• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yyle88 / syntaxgo / 18836268722

27 Oct 2025 07:06AM UTC coverage: 52.137% (-7.3%) from 59.469%
18836268722

push

github

yyle88
Remove deprecated AST merge functions and upgrade dependencies

  - Remove merge_package.go using deprecated ast.MergePackageFiles API
  - Clean up syntaxgo_ast package to use modern Go AST APIs
  - Upgrade Go version from 1.22.8 to 1.24.0

13 of 122 new or added lines in 8 files covered. (10.66%)

20 existing lines in 2 files now uncovered.

622 of 1193 relevant lines covered (52.14%)

7.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/demos/demo3x/main.go
1
// Demo3x shows AST search and code element finding
2
// Search functions and types in parsed AST
3
// Navigate struct fields and extract declarations
4
//
5
// Demo3x 展示 AST 搜索和代码元素查找
6
// 在已解析的 AST 中搜索函数和类型
7
// 遍历结构体字段并提取声明
8
package main
9

10
import (
11
        "fmt"
12
        "go/parser"
13
        "go/token"
14

15
        "github.com/yyle88/must"
16
        "github.com/yyle88/syntaxgo/syntaxgo_search"
17
)
18

NEW
19
func main() {
×
NEW
20
        // Parse Go source code from string
×
NEW
21
        // Create token FileSet to track positions
×
NEW
22
        //
×
NEW
23
        // 从字符串解析 Go 源代码
×
NEW
24
        // 创建 token FileSet 来跟踪位置
×
NEW
25
        fset := token.NewFileSet()
×
NEW
26
        src := `package example
×
NEW
27

×
NEW
28
func HelloWorld() string {
×
NEW
29
        return "Hello, World!"
×
NEW
30
}
×
NEW
31

×
NEW
32
type Person struct {
×
NEW
33
        Name string
×
NEW
34
        Age  int
×
NEW
35
}
×
NEW
36
`
×
NEW
37
        astFile, err := parser.ParseFile(fset, "", src, parser.ParseComments)
×
NEW
38
        if err != nil {
×
NEW
39
                panic(err)
×
40
        }
41

42
        // Search function declaration in AST
43
        // Find function node with specified name
44
        //
45
        // 在 AST 中搜索函数声明
46
        // 查找具有指定名称的函数节点
NEW
47
        astFunc := syntaxgo_search.FindFunctionByName(astFile, "HelloWorld")
×
NEW
48
        if astFunc != nil {
×
NEW
49
                fmt.Println("Found function:", astFunc.Name.Name)
×
NEW
50
        }
×
51

52
        // Search struct type definition in AST
53
        // Locate struct node and extract its fields
54
        //
55
        // 在 AST 中搜索结构体类型定义
56
        // 定位结构体节点并提取其字段
NEW
57
        structType, ok := syntaxgo_search.FindStructTypeByName(astFile, "Person")
×
NEW
58
        must.OK(ok)
×
NEW
59

×
NEW
60
        // Traverse struct fields and print field names
×
NEW
61
        // Each field can have multiple names in one line
×
NEW
62
        //
×
NEW
63
        // 遍历结构体字段并打印字段名
×
NEW
64
        // 每个字段可以在一行中有多个名称
×
NEW
65
        for _, field := range structType.Fields.List {
×
NEW
66
                for _, fieldName := range field.Names {
×
NEW
67
                        fmt.Println("Person Field:", fieldName.Name)
×
NEW
68
                }
×
69
        }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc