File tree Expand file tree Collapse file tree 4 files changed +88
-60
lines changed Expand file tree Collapse file tree 4 files changed +88
-60
lines changed Original file line number Diff line number Diff line change @@ -15,152 +15,148 @@ type Node interface {
1515 SetType (reflect.Type )
1616}
1717
18- type Base struct {
18+ type base struct {
1919 loc file.Location
2020 nodeType reflect.Type
2121}
2222
23- func (n * Base ) Location () file.Location {
23+ func (n * base ) Location () file.Location {
2424 return n .loc
2525}
2626
27- func (n * Base ) SetLocation (loc file.Location ) {
27+ func (n * base ) SetLocation (loc file.Location ) {
2828 n .loc = loc
2929}
3030
31- func (n * Base ) Type () reflect.Type {
31+ func (n * base ) Type () reflect.Type {
3232 return n .nodeType
3333}
3434
35- func (n * Base ) SetType (t reflect.Type ) {
35+ func (n * base ) SetType (t reflect.Type ) {
3636 n .nodeType = t
3737}
3838
39- func Loc (l file.Location ) Base {
40- return Base {loc : l }
41- }
42-
4339type NilNode struct {
44- Base
40+ base
4541}
4642
4743type IdentifierNode struct {
48- Base
44+ base
4945 Value string
5046}
5147
5248type IntegerNode struct {
53- Base
49+ base
5450 Value int
5551}
5652
5753type FloatNode struct {
58- Base
54+ base
5955 Value float64
6056}
6157
6258type BoolNode struct {
63- Base
59+ base
6460 Value bool
6561}
6662
6763type StringNode struct {
68- Base
64+ base
6965 Value string
7066}
7167
7268type ConstantNode struct {
73- Base
69+ base
7470 Value interface {}
7571}
7672
7773type UnaryNode struct {
78- Base
74+ base
7975 Operator string
8076 Node Node
8177}
8278
8379type BinaryNode struct {
84- Base
80+ base
8581 Operator string
8682 Left Node
8783 Right Node
8884}
8985
9086type MatchesNode struct {
91- Base
87+ base
9288 Regexp * regexp.Regexp
9389 Left Node
9490 Right Node
9591}
9692
9793type PropertyNode struct {
98- Base
94+ base
9995 Node Node
10096 Property string
10197}
10298
10399type IndexNode struct {
104- Base
100+ base
105101 Node Node
106102 Index Node
107103}
108104
109105type SliceNode struct {
110- Base
106+ base
111107 Node Node
112108 From Node
113109 To Node
114110}
115111
116112type MethodNode struct {
117- Base
113+ base
118114 Node Node
119115 Method string
120116 Arguments []Node
121117}
122118
123119type FunctionNode struct {
124- Base
120+ base
125121 Name string
126122 Arguments []Node
127123 Fast bool
128124}
129125
130126type BuiltinNode struct {
131- Base
127+ base
132128 Name string
133129 Arguments []Node
134130}
135131
136132type ClosureNode struct {
137- Base
133+ base
138134 Node Node
139135}
140136
141137type PointerNode struct {
142- Base
138+ base
143139}
144140
145141type ConditionalNode struct {
146- Base
142+ base
147143 Cond Node
148144 Exp1 Node
149145 Exp2 Node
150146}
151147
152148type ArrayNode struct {
153- Base
149+ base
154150 Nodes []Node
155151}
156152
157153type MapNode struct {
158- Base
154+ base
159155 Pairs []Node
160156}
161157
162158type PairNode struct {
163- Base
159+ base
164160 Key Node
165161 Value Node
166162}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package ast
33import (
44 "fmt"
55 "reflect"
6+ "regexp"
67)
78
89func Dump (node Node ) string {
@@ -19,7 +20,7 @@ func dump(v reflect.Value, ident string) string {
1920 out := t .Name () + "{\n "
2021 for i := 0 ; i < t .NumField (); i ++ {
2122 f := t .Field (i )
22- if f .Name == "Base" {
23+ if isPrivate ( f .Name ) {
2324 continue
2425 }
2526 s := v .Field (i )
@@ -50,3 +51,9 @@ func dump(v reflect.Value, ident string) string {
5051 return fmt .Sprintf ("%v" , v )
5152 }
5253}
54+
55+ var isCapital = regexp .MustCompile ("^[A-Z]" )
56+
57+ func isPrivate (s string ) bool {
58+ return ! isCapital .Match ([]byte (s ))
59+ }
Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ import (
44 "bufio"
55 "flag"
66 "fmt"
7+ "github.com/antonmedv/expr/ast"
78 "io/ioutil"
89 "os"
910
1011 "github.com/antonmedv/expr"
11- "github.com/antonmedv/expr/ast"
1212 "github.com/antonmedv/expr/checker"
1313 "github.com/antonmedv/expr/compiler"
1414 "github.com/antonmedv/expr/optimizer"
You can’t perform that action at this time.
0 commit comments