35
35
% token CLOSE_BRACE
36
36
% token EOF
37
37
38
- /* % left OPEN_BRACKET */
39
38
/* according to https:// github.com/ stedolan/ jq/ issues/ 1326 */
40
39
% right PIPE /* lowest precedence */
41
40
% nonassoc COMMA
@@ -55,28 +54,29 @@ program:
55
54
| EOF ;
56
55
{ Identity }
57
56
58
- str_or_id :
57
+ string_or_identifier :
59
58
| key = IDENTIFIER { Literal (String key) }
60
59
| key = STRING { Literal (String key) }
61
60
62
- key_val (E ):
63
- | key = str_or_id
61
+ key_value (E ):
62
+ | key = string_or_identifier
64
63
{ key, None }
65
64
| OPEN_PARENT ; e1 = E CLOSE_PARENT ; COLON ; e2 = E
66
65
{ e1, Some e2 }
67
- | key = str_or_id ; COLON ; e = E
66
+ | key = string_or_identifier ; COLON ; e = E
68
67
{ key, Some e }
69
68
70
69
elif_term:
71
70
| ELIF cond = item_expr THEN e = term
72
71
{ cond, e }
73
72
74
73
// sequence_expr handles the lowest precedence operators: comma and pipe
74
+ // while item_expr handles the higher precedence operators
75
75
sequence_expr :
76
76
| left = sequence_expr; COMMA ; right = sequence_expr;
77
77
{ Comma (left, right) }
78
78
79
- | left = sequence_expr; PIPE ; right = item_expr; // Pipe binds tighter than comma, but less than others
79
+ | left = sequence_expr; PIPE ; right = item_expr;
80
80
{ Pipe (left, right) }
81
81
82
82
| e = item_expr
@@ -96,10 +96,10 @@ sequence_expr:
96
96
| AND {And }
97
97
| OR {Or }
98
98
99
- // item_expr handles operators with higher precedence than COMMA and PIPE
100
99
item_expr:
101
100
| left = item_expr; op = operator; right = item_expr;
102
101
{ Operation (left, op, right) }
102
+
103
103
| e = term
104
104
{ e }
105
105
@@ -124,8 +124,7 @@ term:
124
124
{ Literal (Null ) }
125
125
| RANGE ; OPEN_PARENT ; nl = separated_nonempty_list(SEMICOLON , number); CLOSE_PARENT ;
126
126
{
127
- let nl = List. map int_of_float nl in
128
- match nl with
127
+ match (List. map Int. of_float nl) with
129
128
| [] -> assert false (* nonempty_list *)
130
129
| x :: [] -> Range (x, None , None )
131
130
| x :: y :: [] -> Range (x, Some y, None )
@@ -211,12 +210,13 @@ term:
211
210
| OPEN_BRACE ; CLOSE_BRACE ;
212
211
{ Object [] }
213
212
214
- | e = delimited(OPEN_BRACE , separated_nonempty_list(COMMA , key_val (term)), CLOSE_BRACE );
213
+ | e = delimited(OPEN_BRACE , separated_nonempty_list(COMMA , key_value (term)), CLOSE_BRACE );
215
214
{ Object e }
216
215
217
216
// Parentheses allow a full sequence_expr inside, reducing to an item_expr
218
217
| OPEN_PARENT ; e = sequence_expr; CLOSE_PARENT ;
219
218
{ e }
219
+
220
220
| e = term; OPEN_BRACKET ; i = number; CLOSE_BRACKET
221
221
{ Pipe (e, Index (int_of_float i)) }
222
222
0 commit comments