-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes.go
More file actions
243 lines (193 loc) · 7.26 KB
/
Copy pathnodes.go
File metadata and controls
243 lines (193 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package ast
type NodeType string
const (
TypeProgram NodeType = "Program"
TypeExpressionStatement NodeType = "ExpressionStatement"
TypeCallExpression NodeType = "CallExpression"
TypeVariableDeclaration NodeType = "VariableDeclaration"
TypeVariableDeclarator NodeType = "VariableDeclarator"
TypeMemberExpression NodeType = "MemberExpression"
TypeIdentifier NodeType = "Identifier"
TypeLiteral NodeType = "Literal"
TypeObjectExpression NodeType = "ObjectExpression"
TypeProperty NodeType = "Property"
TypeBinaryExpression NodeType = "BinaryExpression"
TypeIfStatement NodeType = "IfStatement"
TypeForStatement NodeType = "ForStatement"
TypeForInStatement NodeType = "ForInStatement"
TypeWhileStatement NodeType = "WhileStatement"
TypeConditionalExpression NodeType = "ConditionalExpression"
TypeLogicalExpression NodeType = "LogicalExpression"
TypeUnaryExpression NodeType = "UnaryExpression"
TypeArrayPattern NodeType = "ArrayPattern"
TypeArrowFunctionExpression NodeType = "ArrowFunctionExpression"
TypeBreakStatement NodeType = "BreakStatement"
TypeContinueStatement NodeType = "ContinueStatement"
)
type Node interface {
Type() NodeType
}
type Program struct {
NodeType NodeType `json:"type"`
Body []Node `json:"body"`
PineVersion int `json:"pineVersion,omitempty"`
}
func (p *Program) Type() NodeType { return TypeProgram }
type ExpressionStatement struct {
NodeType NodeType `json:"type"`
Expression Expression `json:"expression"`
}
func (e *ExpressionStatement) Type() NodeType { return TypeExpressionStatement }
type Expression interface {
Node
expressionNode()
}
type CallExpression struct {
NodeType NodeType `json:"type"`
Callee Expression `json:"callee"`
Arguments []Expression `json:"arguments"`
}
func (c *CallExpression) Type() NodeType { return TypeCallExpression }
func (c *CallExpression) expressionNode() {}
type VariableDeclaration struct {
NodeType NodeType `json:"type"`
Declarations []VariableDeclarator `json:"declarations"`
Kind string `json:"kind"`
Persistence string `json:"persistence,omitempty"` // "", "var", "varip"
}
func (v *VariableDeclaration) Type() NodeType { return TypeVariableDeclaration }
type VariableDeclarator struct {
NodeType NodeType `json:"type"`
ID Pattern `json:"id"`
Init Expression `json:"init,omitempty"`
}
func (v *VariableDeclarator) Type() NodeType { return TypeVariableDeclarator }
type Pattern interface {
Node
patternNode()
}
type ArrayPattern struct {
NodeType NodeType `json:"type"`
Elements []Identifier `json:"elements"`
}
func (a *ArrayPattern) Type() NodeType { return TypeArrayPattern }
func (a *ArrayPattern) patternNode() {}
func (i *Identifier) patternNode() {}
type MemberExpression struct {
NodeType NodeType `json:"type"`
Object Expression `json:"object"`
Property Expression `json:"property"`
Computed bool `json:"computed"`
}
func (m *MemberExpression) Type() NodeType { return TypeMemberExpression }
func (m *MemberExpression) expressionNode() {}
type Identifier struct {
NodeType NodeType `json:"type"`
Name string `json:"name"`
}
func (i *Identifier) Type() NodeType { return TypeIdentifier }
func (i *Identifier) expressionNode() {}
type Literal struct {
NodeType NodeType `json:"type"`
Value interface{} `json:"value"`
Raw string `json:"raw"`
}
func (l *Literal) Type() NodeType { return TypeLiteral }
func (l *Literal) expressionNode() {}
type ObjectExpression struct {
NodeType NodeType `json:"type"`
Properties []Property `json:"properties"`
}
func (o *ObjectExpression) Type() NodeType { return TypeObjectExpression }
func (o *ObjectExpression) expressionNode() {}
type Property struct {
NodeType NodeType `json:"type"`
Key Expression `json:"key"`
Value Expression `json:"value"`
Kind string `json:"kind"`
Method bool `json:"method"`
Shorthand bool `json:"shorthand"`
Computed bool `json:"computed"`
}
func (p *Property) Type() NodeType { return TypeProperty }
type BinaryExpression struct {
NodeType NodeType `json:"type"`
Operator string `json:"operator"`
Left Expression `json:"left"`
Right Expression `json:"right"`
}
func (b *BinaryExpression) Type() NodeType { return TypeBinaryExpression }
func (b *BinaryExpression) expressionNode() {}
type IfStatement struct {
NodeType NodeType `json:"type"`
Test Expression `json:"test"`
Consequent []Node `json:"consequent"`
Alternate []Node `json:"alternate,omitempty"`
}
func (i *IfStatement) Type() NodeType { return TypeIfStatement }
func (i *IfStatement) expressionNode() {}
type ForStatement struct {
NodeType NodeType `json:"type"`
Counter string `json:"counter"`
From Expression `json:"from"`
To Expression `json:"to"`
Step Expression `json:"step,omitempty"`
Body []Node `json:"body"`
}
func (f *ForStatement) Type() NodeType { return TypeForStatement }
func (f *ForStatement) expressionNode() {}
type ForInStatement struct {
NodeType NodeType `json:"type"`
IndexVar string `json:"indexVar,omitempty"`
ElementVar string `json:"elementVar"`
Collection Expression `json:"collection"`
Body []Node `json:"body"`
}
func (f *ForInStatement) Type() NodeType { return TypeForInStatement }
func (f *ForInStatement) expressionNode() {}
type WhileStatement struct {
NodeType NodeType `json:"type"`
Condition Expression `json:"condition"`
Body []Node `json:"body"`
}
func (w *WhileStatement) Type() NodeType { return TypeWhileStatement }
func (w *WhileStatement) expressionNode() {}
type ConditionalExpression struct {
NodeType NodeType `json:"type"`
Test Expression `json:"test"`
Consequent Expression `json:"consequent"`
Alternate Expression `json:"alternate"`
}
func (c *ConditionalExpression) Type() NodeType { return TypeConditionalExpression }
func (c *ConditionalExpression) expressionNode() {}
type LogicalExpression struct {
NodeType NodeType `json:"type"`
Operator string `json:"operator"`
Left Expression `json:"left"`
Right Expression `json:"right"`
}
func (l *LogicalExpression) Type() NodeType { return TypeLogicalExpression }
func (l *LogicalExpression) expressionNode() {}
type UnaryExpression struct {
NodeType NodeType `json:"type"`
Operator string `json:"operator"`
Argument Expression `json:"argument"`
Prefix bool `json:"prefix"`
}
func (u *UnaryExpression) Type() NodeType { return TypeUnaryExpression }
func (u *UnaryExpression) expressionNode() {}
type ArrowFunctionExpression struct {
NodeType NodeType `json:"type"`
Params []Identifier `json:"params"`
Body []Node `json:"body"`
}
func (a *ArrowFunctionExpression) Type() NodeType { return TypeArrowFunctionExpression }
func (a *ArrowFunctionExpression) expressionNode() {}
type BreakStatement struct {
NodeType NodeType `json:"type"`
}
func (b *BreakStatement) Type() NodeType { return TypeBreakStatement }
type ContinueStatement struct {
NodeType NodeType `json:"type"`
}
func (c *ContinueStatement) Type() NodeType { return TypeContinueStatement }