forked from jdevillard/JmesPath.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJmesPathParser.y
407 lines (362 loc) · 7.87 KB
/
JmesPathParser.y
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
%namespace DevLab.JmesPath
%partial
%parsertype JmesPathParser
%visibility internal
%tokentype TokenType
%union {
public Token Token;
}
%token
T_AND,
T_OR,
T_NOT,
T_PLUS,
T_MINUS,
T_MULTIPLY,
T_DIVIDE,
T_MODULO,
T_DIV,
T_COLON,
T_COMMA,
T_DOT,
T_PIPE,
T_EQ,
T_GT,
T_GE,
T_LT,
T_LE,
T_NE,
T_FILTER,
T_FLATTEN,
T_STAR,
T_CURRENT,
T_ETYPE,
T_NUMBER,
T_LSTRING,
T_QSTRING,
T_RSTRING,
T_USTRING,
T_LBRACE,
T_RBRACE,
T_LBRACKET,
T_RBRACKET,
T_LPAREN,
T_RPAREN
%left T_PIPE
%left T_OR
%left T_AND
%left T_NOT
%left T_EQ
%left T_GT
%left T_GE
%left T_LT
%left T_LE
%left T_NE
%left T_NOT
%left T_PLUS
%left T_MINUS
%left T_MULTIPLY
%left T_DIVIDE
%left T_MODULO
%left T_DIV
%left T_DOT
%left T_LBRACKET
%left T_STAR
%left T_FILTER
%left T_FLATTEN
%left T_LISTWILDCARD
%left T_RBRACKET
%start expression
%%
expression : expression_impl
{
OnExpression();
ResolveParsingState();
}
;
expression_impl : sub_expression
| index_expression
| comparator_expression
| or_expression
| identifier
| and_expression
| not_expression
| paren_expression
| hash_wildcard
| multi_select_list
| multi_select_hash
| literal
| pipe_expression
| function_expression
| raw_string
| current_node
| arithmetic_expression
;
sub_expression : sub_expression_impl
{
OnSubExpression();
}
;
sub_expression_impl : expression T_DOT identifier
| expression T_DOT multi_select_hash
| expression T_DOT multi_select_list
| expression T_DOT function_expression
| expression T_DOT hash_wildcard
;
arithmetic_expression : expression T_PLUS expression
{
OnArithmeticAddition();
}
| expression T_MINUS expression
{
OnArithmeticSubtraction();
}
| expression T_MULTIPLY expression
{
OnArithmeticMultiplication();
}
| expression T_STAR expression
{
OnArithmeticMultiplication();
}
| expression T_DIVIDE expression
{
OnArithmeticDivision();
}
| expression T_MODULO expression
{
OnArithmeticModulo();
}
| expression T_DIV expression
{
OnArithmeticIntegerDivision();
}
;
index_expression : expression bracket_specifier
{
System.Diagnostics.Debug.WriteLine("index expression (expression, bracket_specifier): {0}.", $1.Token);
OnIndexExpression();
}
| bracket_specifier
;
function_expression : unquoted_string arguments
{
PopFunction($1.Token);
}
;
arguments : T_LPAREN T_RPAREN
{
PushFunction();
}
| T_LPAREN function_arguments T_RPAREN
;
function_arguments : expression
{
PushFunction();
AddFunctionArg();
}
| expression_type
{
PushFunction();
AddFunctionArg();
}
| function_arguments T_COMMA expression
{
AddFunctionArg();
}
| function_arguments T_COMMA expression_type
{
AddFunctionArg();
}
;
current_node : T_CURRENT
{
OnCurrentNode();
}
;
expression_type : T_ETYPE expression
{
OnExpressionType();
}
;
bracket_specifier : T_LBRACKET T_NUMBER T_RBRACKET
{
System.Diagnostics.Debug.WriteLine("bracket_specifier (index): {0}.", $2.Token);
OnIndex($2.Token);
}
| T_LBRACKET T_STAR T_RBRACKET
{
System.Diagnostics.Debug.WriteLine("bracket_specifier (list wildcard projection).");
OnListWildcardProjection();
}
| T_LBRACKET slice_expression T_RBRACKET
| T_FILTER expression T_RBRACKET
{
OnFilterProjection();
}
| T_FLATTEN
{
System.Diagnostics.Debug.WriteLine("bracket_specifier (flattening projection).");
OnFlattenProjection();
}
;
comparator_expression
: expression T_EQ expression
{
OnComparisonExpression($2.Token);
}
| expression T_GE expression
{
OnComparisonExpression($2.Token);
}
| expression T_GT expression
{
OnComparisonExpression($2.Token);
}
| expression T_LE expression
{
OnComparisonExpression($2.Token);
}
| expression T_LT expression
{
OnComparisonExpression($2.Token);
}
| expression T_NE expression
{
OnComparisonExpression($2.Token);
}
;
or_expression : expression T_OR expression
{
OnOrExpression();
}
;
identifier : identifier_impl
{
System.Diagnostics.Debug.WriteLine("identifier ({0}): {1}.", $1.Token.Type, $1.Token);
OnIdentifier($1.Token);
}
;
identifier_impl : quoted_string
| unquoted_string
;
and_expression : expression T_AND expression
{
OnAndExpression();
}
;
not_expression : T_NOT expression
{
OnNotExpression();
}
;
paren_expression : T_LPAREN expression T_RPAREN
;
hash_wildcard : T_STAR
{
System.Diagnostics.Debug.WriteLine("wildcard (hash wildcard projection): {0}", $1.Token);
OnHashWildcardProjection();
}
;
multi_select_hash : T_LBRACE keyval_expressions T_RBRACE
{
PopMultiSelectHash();
};
keyval_expressions : keyval_expression
{
PushMultiSelectHash();
AddMultiSelectHashExpression();
}
| keyval_expressions T_COMMA keyval_expression
{
AddMultiSelectHashExpression();
}
;
keyval_expression : identifier T_COLON expression
;
multi_select_list : T_LBRACKET expressions T_RBRACKET
{
PopMultiSelectList();
}
;
expressions : expression
{
PushMultiSelectList();
AddMultiSelectListExpression();
}
| expressions T_COMMA expression
{
AddMultiSelectListExpression();
}
;
pipe_expression : expression T_PIPE expression
{
OnPipeExpression();
}
;
slice_expression : T_COLON
{
OnSliceExpression(null, null, null);
}
| T_NUMBER T_COLON
{
OnSliceExpression($1.Token, null, null);
}
| T_NUMBER T_COLON T_COLON
{
OnSliceExpression($1.Token, null, null);
}
| T_NUMBER T_COLON T_NUMBER
{
OnSliceExpression($1.Token, $3.Token, null);
}
| T_NUMBER T_COLON T_NUMBER T_COLON
{
OnSliceExpression($1.Token, $3.Token, null);
}
| T_NUMBER T_COLON T_NUMBER T_COLON T_NUMBER
{
OnSliceExpression($1.Token, $3.Token, $5.Token);
}
| T_NUMBER T_COLON T_COLON T_NUMBER
{
OnSliceExpression($1.Token, null, $4.Token);
}
| T_COLON T_NUMBER
{
OnSliceExpression(null, $2.Token, null);
}
| T_COLON T_NUMBER T_COLON
{
OnSliceExpression(null, $2.Token, null);
}
| T_COLON T_NUMBER T_COLON T_NUMBER
{
OnSliceExpression(null, $2.Token, $4.Token);
}
| T_COLON T_COLON T_NUMBER
{
OnSliceExpression(null, null, $3.Token);
}
| T_COLON T_COLON
{
OnSliceExpression(null, null, null);
}
;
quoted_string : T_QSTRING
;
unquoted_string : T_USTRING
;
literal : T_LSTRING
{
System.Diagnostics.Debug.WriteLine("literal string : {0}", $1.Token);
OnLiteralString($1.Token);
}
;
raw_string : T_RSTRING
{
System.Diagnostics.Debug.WriteLine("raw string : {0}", $1.Token);
OnRawString($1.Token);
}
;
%%