@@ -216,21 +216,18 @@ makeItemList(List *list) {
216
216
%token <str> STRING_P NUMERIC_P
217
217
218
218
%type <value> result scalar_value
219
- %type <str> key
220
219
221
220
%type <elems> path value_list
222
221
223
- %type <value> path_elem path_elem_any right_expr expr array
222
+ %type <value> key key_any right_expr expr array
224
223
225
224
%token <hint> HINT_P
226
225
227
- %type <hint> opt_hint
228
-
229
226
%left OR_P
230
227
%left AND_P
231
228
%right NOT_P
232
229
%nonassoc IN_P IS_P
233
- %nonassoc XXX
230
+ %nonassoc ' ( ' ' ) '
234
231
235
232
/* Grammar follows */
236
233
%%
@@ -262,11 +259,6 @@ scalar_value:
262
259
| NUMERIC_P { $$ = makeItemNumeric(&$1 ); }
263
260
;
264
261
265
- opt_hint :
266
- HINT_P { $$ = $1 ; }
267
- | /* EMPTY */ %prec XXX { $$ = jsqIndexDefault; }
268
- ;
269
-
270
262
value_list :
271
263
scalar_value { $$ = lappend(NIL, $1 ); }
272
264
| value_list ' ,' scalar_value { $$ = lappend($1 , $3 ); }
@@ -292,11 +284,17 @@ right_expr:
292
284
;
293
285
294
286
expr :
295
- path opt_hint right_expr { $3 ->hint = $2 ; $$ = makeItemList(lappend($1 , $3 )); }
287
+ path right_expr { $$ = makeItemList(lappend($1 , $2 )); }
288
+ | path HINT_P right_expr { $3 ->hint = $2 ; $$ = makeItemList(lappend($1 , $3 )); }
289
+ | NOT_P expr { $$ = makeItemUnary(jqiNot, $2 ); }
290
+ /*
291
+ * In next two lines NOT_P is a patch actually, not a an
292
+ * logical expression.
293
+ */
294
+ | NOT_P HINT_P right_expr { $3 ->hint = $2 ; $$ = makeItemList(lappend(lappend(NIL, makeItemKey(&$1 )), $3 )); }
295
+ | NOT_P right_expr { $$ = makeItemList(lappend(lappend(NIL, makeItemKey(&$1 )), $2 )); }
296
296
| path ' (' expr ' )' { $$ = makeItemList(lappend($1 , $3 )); }
297
297
| ' (' expr ' )' { $$ = $2 ; }
298
- | NOT_P expr { $$ = makeItemUnary(jqiNot, $2 ); }
299
- | NOT_P opt_hint right_expr { $3 ->hint = $2 ; $$ = makeItemList(lappend(lappend(NIL, makeItemKey(&$1 )), $3 )); }
300
298
| expr AND_P expr { $$ = makeItemBinary(jqiAnd, $1 , $3 ); }
301
299
| expr OR_P expr { $$ = makeItemBinary(jqiOr, $1 , $3 ); }
302
300
;
@@ -305,39 +303,38 @@ expr:
305
303
* key is always a string, not a bool or numeric
306
304
*/
307
305
key :
308
- STRING_P { $$ = $1 ; }
309
- | IN_P { $$ = $1 ; }
310
- | IS_P { $$ = $1 ; }
311
- | OR_P { $$ = $1 ; }
312
- | AND_P { $$ = $1 ; }
313
- | NULL_P { $$ = $1 ; }
314
- | TRUE_P { $$ = $1 ; }
315
- | ARRAY_T { $$ = $1 ; }
316
- | FALSE_P { $$ = $1 ; }
317
- | NUMERIC_T { $$ = $1 ; }
318
- | OBJECT_T { $$ = $1 ; }
319
- | STRING_T { $$ = $1 ; }
320
- | BOOLEAN_T { $$ = $1 ; }
321
- | NUMERIC_P { $$ = $1 ; }
322
- ;
323
-
324
- path_elem :
325
306
' *' { $$ = makeItemType(jqiAny); }
326
307
| ' #' { $$ = makeItemType(jqiAnyArray); }
327
308
| ' %' { $$ = makeItemType(jqiAnyKey); }
328
309
| ' $' { $$ = makeItemType(jqiCurrent); }
329
- | key { $$ = makeItemKey(&$1 ); }
310
+ | STRING_P { $$ = makeItemKey(&$1 ); }
311
+ | IN_P { $$ = makeItemKey(&$1 ); }
312
+ | IS_P { $$ = makeItemKey(&$1 ); }
313
+ | OR_P { $$ = makeItemKey(&$1 ); }
314
+ | AND_P { $$ = makeItemKey(&$1 ); }
315
+ | NULL_P { $$ = makeItemKey(&$1 ); }
316
+ | TRUE_P { $$ = makeItemKey(&$1 ); }
317
+ | ARRAY_T { $$ = makeItemKey(&$1 ); }
318
+ | FALSE_P { $$ = makeItemKey(&$1 ); }
319
+ | NUMERIC_T { $$ = makeItemKey(&$1 ); }
320
+ | OBJECT_T { $$ = makeItemKey(&$1 ); }
321
+ | STRING_T { $$ = makeItemKey(&$1 ); }
322
+ | BOOLEAN_T { $$ = makeItemKey(&$1 ); }
323
+ | NUMERIC_P { $$ = makeItemKey(&$1 ); }
330
324
;
331
325
332
- path_elem_any :
333
- path_elem { $$ = $$ ; }
326
+ /*
327
+ * NOT keyword needs separate processing
328
+ */
329
+ key_any :
330
+ key { $$ = $$ ; }
334
331
| NOT_P { $$ = makeItemKey(&$1 ); }
335
332
;
336
333
337
334
path :
338
- path_elem { $$ = lappend(NIL, $1 ); }
339
- | path ' .' path_elem_any { $$ = lappend($1 , $3 ); }
340
- | NOT_P ' .' path_elem_any { $$ = lappend(lappend(NIL, makeItemKey(&$1 )), $3 ); }
335
+ key { $$ = lappend(NIL, $1 ); }
336
+ | path ' .' key_any { $$ = lappend($1 , $3 ); }
337
+ | NOT_P ' .' key_any { $$ = lappend(lappend(NIL, makeItemKey(&$1 )), $3 ); }
341
338
;
342
339
343
340
%%
0 commit comments