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 {
15
15
SetType (reflect.Type )
16
16
}
17
17
18
- type Base struct {
18
+ type base struct {
19
19
loc file.Location
20
20
nodeType reflect.Type
21
21
}
22
22
23
- func (n * Base ) Location () file.Location {
23
+ func (n * base ) Location () file.Location {
24
24
return n .loc
25
25
}
26
26
27
- func (n * Base ) SetLocation (loc file.Location ) {
27
+ func (n * base ) SetLocation (loc file.Location ) {
28
28
n .loc = loc
29
29
}
30
30
31
- func (n * Base ) Type () reflect.Type {
31
+ func (n * base ) Type () reflect.Type {
32
32
return n .nodeType
33
33
}
34
34
35
- func (n * Base ) SetType (t reflect.Type ) {
35
+ func (n * base ) SetType (t reflect.Type ) {
36
36
n .nodeType = t
37
37
}
38
38
39
- func Loc (l file.Location ) Base {
40
- return Base {loc : l }
41
- }
42
-
43
39
type NilNode struct {
44
- Base
40
+ base
45
41
}
46
42
47
43
type IdentifierNode struct {
48
- Base
44
+ base
49
45
Value string
50
46
}
51
47
52
48
type IntegerNode struct {
53
- Base
49
+ base
54
50
Value int
55
51
}
56
52
57
53
type FloatNode struct {
58
- Base
54
+ base
59
55
Value float64
60
56
}
61
57
62
58
type BoolNode struct {
63
- Base
59
+ base
64
60
Value bool
65
61
}
66
62
67
63
type StringNode struct {
68
- Base
64
+ base
69
65
Value string
70
66
}
71
67
72
68
type ConstantNode struct {
73
- Base
69
+ base
74
70
Value interface {}
75
71
}
76
72
77
73
type UnaryNode struct {
78
- Base
74
+ base
79
75
Operator string
80
76
Node Node
81
77
}
82
78
83
79
type BinaryNode struct {
84
- Base
80
+ base
85
81
Operator string
86
82
Left Node
87
83
Right Node
88
84
}
89
85
90
86
type MatchesNode struct {
91
- Base
87
+ base
92
88
Regexp * regexp.Regexp
93
89
Left Node
94
90
Right Node
95
91
}
96
92
97
93
type PropertyNode struct {
98
- Base
94
+ base
99
95
Node Node
100
96
Property string
101
97
}
102
98
103
99
type IndexNode struct {
104
- Base
100
+ base
105
101
Node Node
106
102
Index Node
107
103
}
108
104
109
105
type SliceNode struct {
110
- Base
106
+ base
111
107
Node Node
112
108
From Node
113
109
To Node
114
110
}
115
111
116
112
type MethodNode struct {
117
- Base
113
+ base
118
114
Node Node
119
115
Method string
120
116
Arguments []Node
121
117
}
122
118
123
119
type FunctionNode struct {
124
- Base
120
+ base
125
121
Name string
126
122
Arguments []Node
127
123
Fast bool
128
124
}
129
125
130
126
type BuiltinNode struct {
131
- Base
127
+ base
132
128
Name string
133
129
Arguments []Node
134
130
}
135
131
136
132
type ClosureNode struct {
137
- Base
133
+ base
138
134
Node Node
139
135
}
140
136
141
137
type PointerNode struct {
142
- Base
138
+ base
143
139
}
144
140
145
141
type ConditionalNode struct {
146
- Base
142
+ base
147
143
Cond Node
148
144
Exp1 Node
149
145
Exp2 Node
150
146
}
151
147
152
148
type ArrayNode struct {
153
- Base
149
+ base
154
150
Nodes []Node
155
151
}
156
152
157
153
type MapNode struct {
158
- Base
154
+ base
159
155
Pairs []Node
160
156
}
161
157
162
158
type PairNode struct {
163
- Base
159
+ base
164
160
Key Node
165
161
Value Node
166
162
}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package ast
3
3
import (
4
4
"fmt"
5
5
"reflect"
6
+ "regexp"
6
7
)
7
8
8
9
func Dump (node Node ) string {
@@ -19,7 +20,7 @@ func dump(v reflect.Value, ident string) string {
19
20
out := t .Name () + "{\n "
20
21
for i := 0 ; i < t .NumField (); i ++ {
21
22
f := t .Field (i )
22
- if f .Name == "Base" {
23
+ if isPrivate ( f .Name ) {
23
24
continue
24
25
}
25
26
s := v .Field (i )
@@ -50,3 +51,9 @@ func dump(v reflect.Value, ident string) string {
50
51
return fmt .Sprintf ("%v" , v )
51
52
}
52
53
}
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 (
4
4
"bufio"
5
5
"flag"
6
6
"fmt"
7
+ "github.com/antonmedv/expr/ast"
7
8
"io/ioutil"
8
9
"os"
9
10
10
11
"github.com/antonmedv/expr"
11
- "github.com/antonmedv/expr/ast"
12
12
"github.com/antonmedv/expr/checker"
13
13
"github.com/antonmedv/expr/compiler"
14
14
"github.com/antonmedv/expr/optimizer"
You can’t perform that action at this time.
0 commit comments