39
39
)
40
40
41
41
var (
42
- infile = flag .String ("infile" , "" , "input filename" )
43
- outfile = flag .String ("outfile" , "" , "output filename (if it is not specified, the result is printed to stdout.)" )
42
+ astfile = flag .String ("astfile" , "ast/ast.go" , "path to ast/ast.go" )
43
+ constfile = flag .String ("constfile" , "ast/ast_const.go" , "path to ast/ast_const.go" )
44
+ outfile = flag .String ("outfile" , "" , "output filename (if it is not specified, the result is printed to stdout.)" )
44
45
)
45
46
46
47
func main () {
@@ -51,41 +52,41 @@ func main() {
51
52
52
53
flag .Parse ()
53
54
54
- catalog , err := astcatalog .Load (* infile )
55
+ catalog , err := astcatalog .Load (* astfile , * constfile )
55
56
if err != nil {
56
57
log .Fatal (err )
57
58
}
58
59
59
- nodes := make ([]* astcatalog.NodeDef , 0 , len (catalog ))
60
- for _ , node := range catalog {
61
- nodes = append (nodes , node )
60
+ structs := make ([]* astcatalog.NodeStructDef , 0 , len (catalog . Structs ))
61
+ for _ , structDef := range catalog . Structs {
62
+ structs = append (structs , structDef )
62
63
}
63
- sort .Slice (nodes , func (i , j int ) bool {
64
- return nodes [i ].SourcePos < nodes [j ].SourcePos
64
+ sort .Slice (structs , func (i , j int ) bool {
65
+ return structs [i ].SourcePos < structs [j ].SourcePos
65
66
})
66
67
67
68
var buffer bytes.Buffer
68
69
buffer .WriteString (prologue )
69
70
70
- for _ , node := range nodes {
71
- x := string (unicode .ToLower (rune (node .Name [0 ])))
71
+ for _ , structDef := range structs {
72
+ x := string (unicode .ToLower (rune (structDef .Name [0 ])))
72
73
73
- posExpr , err := poslang .Parse (node .Pos )
74
+ posExpr , err := poslang .Parse (structDef .Pos )
74
75
if err != nil {
75
76
log .Fatalf ("error on parsing pos: %v" , err )
76
77
}
77
78
78
- endExpr , err := poslang .Parse (node .End )
79
+ endExpr , err := poslang .Parse (structDef .End )
79
80
if err != nil {
80
81
log .Fatalf ("error on parsing pos: %v" , err )
81
82
}
82
83
83
84
fmt .Fprintln (& buffer )
84
- fmt .Fprintf (& buffer , "func (%s *%s) Pos() token.Pos {\n " , x , node .Name )
85
+ fmt .Fprintf (& buffer , "func (%s *%s) Pos() token.Pos {\n " , x , structDef .Name )
85
86
fmt .Fprintf (& buffer , "\t return %s\n " , posExpr .PosExprToGo (x ))
86
87
fmt .Fprintf (& buffer , "}\n " )
87
88
fmt .Fprintln (& buffer )
88
- fmt .Fprintf (& buffer , "func (%s *%s) End() token.Pos {\n " , x , node .Name )
89
+ fmt .Fprintf (& buffer , "func (%s *%s) End() token.Pos {\n " , x , structDef .Name )
89
90
fmt .Fprintf (& buffer , "\t return %s\n " , endExpr .PosExprToGo (x ))
90
91
fmt .Fprintf (& buffer , "}\n " )
91
92
}
0 commit comments