@@ -5,121 +5,83 @@ package actionlint
5
5
type ExprNode interface {
6
6
// Token returns the first token of the node. This method is useful to get position of this node.
7
7
Token () * Token
8
- // Parent returns the parent node of this node.
9
- Parent () ExprNode
10
8
}
11
9
12
10
// Variable
13
11
14
12
// VariableNode is node for variable access.
15
13
type VariableNode struct {
16
14
// Name is name of the variable
17
- Name string
18
- tok * Token
19
- parent ExprNode
15
+ Name string
16
+ tok * Token
20
17
}
21
18
22
19
// Token returns the first token of the node. This method is useful to get position of this node.
23
20
func (n * VariableNode ) Token () * Token {
24
21
return n .tok
25
22
}
26
23
27
- // Parent returns the parent node of this node.
28
- func (n * VariableNode ) Parent () ExprNode {
29
- return n .parent
30
- }
31
-
32
24
// Literals
33
25
34
26
// NullNode is node for null literal.
35
27
type NullNode struct {
36
- tok * Token
37
- parent ExprNode
28
+ tok * Token
38
29
}
39
30
40
31
// Token returns the first token of the node. This method is useful to get position of this node.
41
32
func (n * NullNode ) Token () * Token {
42
33
return n .tok
43
34
}
44
35
45
- // Parent returns the parent node of this node.
46
- func (n * NullNode ) Parent () ExprNode {
47
- return n .parent
48
- }
49
-
50
36
// BoolNode is node for boolean literal, true or false.
51
37
type BoolNode struct {
52
38
// Value is value of the boolean literal.
53
- Value bool
54
- tok * Token
55
- parent ExprNode
39
+ Value bool
40
+ tok * Token
56
41
}
57
42
58
43
// Token returns the first token of the node. This method is useful to get position of this node.
59
44
func (n * BoolNode ) Token () * Token {
60
45
return n .tok
61
46
}
62
47
63
- // Parent returns the parent node of this node.
64
- func (n * BoolNode ) Parent () ExprNode {
65
- return n .parent
66
- }
67
-
68
48
// IntNode is node for integer literal.
69
49
type IntNode struct {
70
50
// Value is value of the integer literal.
71
- Value int
72
- tok * Token
73
- parent ExprNode
51
+ Value int
52
+ tok * Token
74
53
}
75
54
76
55
// Token returns the first token of the node. This method is useful to get position of this node.
77
56
func (n * IntNode ) Token () * Token {
78
57
return n .tok
79
58
}
80
59
81
- // Parent returns the parent node of this node.
82
- func (n * IntNode ) Parent () ExprNode {
83
- return n .parent
84
- }
85
-
86
60
// FloatNode is node for float literal.
87
61
type FloatNode struct {
88
62
// Value is value of the float literal.
89
- Value float64
90
- tok * Token
91
- parent ExprNode
63
+ Value float64
64
+ tok * Token
92
65
}
93
66
94
67
// Token returns the first token of the node. This method is useful to get position of this node.
95
68
func (n * FloatNode ) Token () * Token {
96
69
return n .tok
97
70
}
98
71
99
- // Parent returns the parent node of this node.
100
- func (n * FloatNode ) Parent () ExprNode {
101
- return n .parent
102
- }
103
-
104
72
// StringNode is node for string literal.
105
73
type StringNode struct {
106
74
// Value is value of the string literal. Escapes are resolved and quotes at both edges are
107
75
// removed.
108
- Value string
109
- tok * Token
110
- parent ExprNode
76
+ Value string
77
+ tok * Token
111
78
}
112
79
113
80
// Token returns the first token of the node. This method is useful to get position of this node.
114
81
func (n * StringNode ) Token () * Token {
115
82
return n .tok
116
83
}
117
84
118
- // Parent returns the parent node of this node.
119
- func (n * StringNode ) Parent () ExprNode {
120
- return n .parent
121
- }
122
-
123
85
// Operators
124
86
125
87
// ObjectDerefNode represents property dereference of object like 'foo.bar'.
@@ -128,76 +90,52 @@ type ObjectDerefNode struct {
128
90
Receiver ExprNode
129
91
// Property is a name of property to access.
130
92
Property string
131
- parent ExprNode
132
93
}
133
94
134
95
// Token returns the first token of the node. This method is useful to get position of this node.
135
- func (n * ObjectDerefNode ) Token () * Token {
96
+ func (n ObjectDerefNode ) Token () * Token {
136
97
return n .Receiver .Token ()
137
98
}
138
99
139
- // Parent returns the parent node of this node.
140
- func (n * ObjectDerefNode ) Parent () ExprNode {
141
- return n .parent
142
- }
143
-
144
100
// ArrayDerefNode represents elements dereference of arrays like '*' in 'foo.bar.*.piyo'.
145
101
type ArrayDerefNode struct {
146
102
// Receiver is an expression at receiver of array element dereference.
147
103
Receiver ExprNode
148
- parent ExprNode
149
104
}
150
105
151
106
// Token returns the first token of the node. This method is useful to get position of this node.
152
- func (n * ArrayDerefNode ) Token () * Token {
107
+ func (n ArrayDerefNode ) Token () * Token {
153
108
return n .Receiver .Token ()
154
109
}
155
110
156
- // Parent returns the parent node of this node.
157
- func (n * ArrayDerefNode ) Parent () ExprNode {
158
- return n .parent
159
- }
160
-
161
111
// IndexAccessNode is node for index access, which represents dynamic object property access or
162
112
// array index access.
163
113
type IndexAccessNode struct {
164
114
// Operand is an expression at operand of index access, which should be array or object.
165
115
Operand ExprNode
166
116
// Index is an expression at index, which should be integer or string.
167
- Index ExprNode
168
- parent ExprNode
117
+ Index ExprNode
169
118
}
170
119
171
120
// Token returns the first token of the node. This method is useful to get position of this node.
172
121
func (n * IndexAccessNode ) Token () * Token {
173
122
return n .Operand .Token ()
174
123
}
175
124
176
- // Parent returns the parent node of this node.
177
- func (n * IndexAccessNode ) Parent () ExprNode {
178
- return n .parent
179
- }
180
-
181
125
// Note: Currently only ! is a logical unary operator
182
126
183
127
// NotOpNode is node for unary ! operator.
184
128
type NotOpNode struct {
185
129
// Operand is an expression at operand of ! operator.
186
130
Operand ExprNode
187
131
tok * Token
188
- parent ExprNode
189
132
}
190
133
191
134
// Token returns the first token of the node. This method is useful to get position of this node.
192
135
func (n * NotOpNode ) Token () * Token {
193
136
return n .tok
194
137
}
195
138
196
- // Parent returns the parent node of this node.
197
- func (n * NotOpNode ) Parent () ExprNode {
198
- return n .parent
199
- }
200
-
201
139
// CompareOpNodeKind is a kind of compare operators; ==, !=, <, <=, >, >=.
202
140
type CompareOpNodeKind int
203
141
@@ -249,20 +187,14 @@ type CompareOpNode struct {
249
187
// Left is an expression for left hand side of the binary operator.
250
188
Left ExprNode
251
189
// Right is an expression for right hand side of the binary operator.
252
- Right ExprNode
253
- parent ExprNode
190
+ Right ExprNode
254
191
}
255
192
256
193
// Token returns the first token of the node. This method is useful to get position of this node.
257
194
func (n * CompareOpNode ) Token () * Token {
258
195
return n .Left .Token ()
259
196
}
260
197
261
- // Parent returns the parent node of this node.
262
- func (n * CompareOpNode ) Parent () ExprNode {
263
- return n .parent
264
- }
265
-
266
198
// LogicalOpNodeKind is a kind of logical operators; && and ||.
267
199
type LogicalOpNodeKind int
268
200
@@ -293,42 +225,30 @@ type LogicalOpNode struct {
293
225
// Left is an expression for left hand side of the binary operator.
294
226
Left ExprNode
295
227
// Right is an expression for right hand side of the binary operator.
296
- Right ExprNode
297
- parent ExprNode
228
+ Right ExprNode
298
229
}
299
230
300
231
// Token returns the first token of the node. This method is useful to get position of this node.
301
232
func (n * LogicalOpNode ) Token () * Token {
302
233
return n .Left .Token ()
303
234
}
304
235
305
- // Parent returns the parent node of this node.
306
- func (n * LogicalOpNode ) Parent () ExprNode {
307
- return n .parent
308
- }
309
-
310
236
// FuncCallNode represents function call in expression.
311
237
// Note that currently only calling builtin functions is supported.
312
238
type FuncCallNode struct {
313
239
// Callee is a name of called function. This is string value because currently only built-in
314
240
// functions can be called.
315
241
Callee string
316
242
// Args is arguments of the function call.
317
- Args []ExprNode
318
- tok * Token
319
- parent ExprNode
243
+ Args []ExprNode
244
+ tok * Token
320
245
}
321
246
322
247
// Token returns the first token of the node. This method is useful to get position of this node.
323
248
func (n * FuncCallNode ) Token () * Token {
324
249
return n .tok
325
250
}
326
251
327
- // Parent returns the parent node of this node.
328
- func (n * FuncCallNode ) Parent () ExprNode {
329
- return n .parent
330
- }
331
-
332
252
// VisitExprNodeFunc is a visitor function for VisitExprNode(). The entering argument is set to
333
253
// true when it is called before visiting children. It is set to false when it is called after
334
254
// visiting children. It means that this function is called twice for the same node. The parent
@@ -355,8 +275,8 @@ func visitExprNode(n, p ExprNode, f VisitExprNodeFunc) {
355
275
visitExprNode (n .Left , n , f )
356
276
visitExprNode (n .Right , n , f )
357
277
case * FuncCallNode :
358
- for i := range n .Args {
359
- visitExprNode (n . Args [ i ] , n , f )
278
+ for _ , a := range n .Args {
279
+ visitExprNode (a , n , f )
360
280
}
361
281
}
362
282
f (n , p , false )
@@ -366,18 +286,3 @@ func visitExprNode(n, p ExprNode, f VisitExprNodeFunc) {
366
286
func VisitExprNode (n ExprNode , f VisitExprNodeFunc ) {
367
287
visitExprNode (n , nil , f )
368
288
}
369
-
370
- // FindParent applies predicate to each parent of this node until predicate returns true.
371
- // Then it returns result of predicate. If no parent found, returns nil, false.
372
- func FindParent [T ExprNode ](n ExprNode , predicate func (n ExprNode ) (T , bool )) (T , bool ) {
373
- parent := n .Parent ()
374
- for parent != nil {
375
- t , ok := predicate (parent )
376
- if ok {
377
- return t , true
378
- }
379
- parent = parent .Parent ()
380
- }
381
- var zero T
382
- return zero , false
383
- }
0 commit comments