1 parent
0f7759f831
commit
ffa2832e33
9 files changed
+1179
-1294
No files matched your search
@@ -1253,16 +1253,16 @@ static const char* const jq_builtins[] = {
|
||||
"def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
|
||||
"def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);",
|
||||
"def any(generator; condition):"
|
||||
" [label | foreach generator as $i"
|
||||
" [label $out | foreach generator as $i"
|
||||
" (false;"
|
||||
" if . then break elif $i | condition then true else . end;"
|
||||
" if . then break $out elif $i | condition then true else . end;"
|
||||
" if . then . else empty end)] | length == 1;",
|
||||
"def any(condition): any(.[]; condition);",
|
||||
"def any: any(.);",
|
||||
"def all(generator; condition): "
|
||||
" [label | foreach generator as $i"
|
||||
" [label $out | foreach generator as $i"
|
||||
" (true;"
|
||||
" if .|not then break elif $i | condition then . else false end;"
|
||||
" if .|not then break $out elif $i | condition then . else false end;"
|
||||
" if .|not then . else empty end)] | length == 0;",
|
||||
"def all(condition): all(.[]; condition);",
|
||||
"def all: all(.);",
|
||||
@@ -1373,8 +1373,8 @@ static const char* const jq_builtins[] = {
|
||||
" def _until: "
|
||||
" if cond then . else (next|_until) end;"
|
||||
" _until;",
|
||||
"def limit($n; exp): if $n < 0 then exp else label | foreach exp as $item ([$n, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1]) end;",
|
||||
"def first(g): label | foreach g as $item ([false, null]; if .[0]==true then break else [true, $item] end; .[1]);",
|
||||
"def limit($n; exp): if $n < 0 then exp else label $out | foreach exp as $item ([$n, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1]) end;",
|
||||
"def first(g): label $out | foreach g as $item ([false, null]; if .[0]==true then break $out else [true, $item] end; .[1]);",
|
||||
"def last(g): reduce g as $item (null; $item);",
|
||||
"def nth($n; g): if $n < 0 then error(\"nth doesn't support negative indices\") else last(limit($n + 1; g)) end;",
|
||||
"def first: .[0];",
|
||||
|
||||
@@ -1820,41 +1820,26 @@ sections:
|
||||
# But if the error caught is not "break" then re-raise it.
|
||||
try repeat(exp) catch .=="break" then empty else error;
|
||||
|
||||
jq has a syntax for lexical labels to "break" or "go (back) to":
|
||||
jq has a syntax for named lexical labels to "break" or "go (back) to":
|
||||
|
||||
label | ... break ...
|
||||
label $out | ... break $out ...
|
||||
|
||||
The `break` builtin will cause the program to return to act as
|
||||
though the nearest `label` (to the left) produced `empty`.
|
||||
The `break $label_name` expression will cause the program to
|
||||
to act as though the nearest (to the left) `label $label_name`
|
||||
produced `empty`.
|
||||
|
||||
The `break2` builtin will return the program to the second
|
||||
nearest `label`, then `empty`.
|
||||
|
||||
The `break3` builtin will return the program to the third
|
||||
nearest `label`, then `empty`.
|
||||
|
||||
A variation on this is named labels:
|
||||
|
||||
label $name | ... break $name
|
||||
|
||||
The `break $name` form returns to the named label and produces
|
||||
`empty`.
|
||||
|
||||
In all cases the relationship between the `break` and
|
||||
corresponding `label` is lexical: the label has to be
|
||||
"visible" from the break.
|
||||
The relationship between the `break` and corresponding `label`
|
||||
is lexical: the label has to be "visible" from the break.
|
||||
|
||||
To break out of a `reduce`, for example:
|
||||
|
||||
label | reduce .[] as $item (null; if .==false then break else ... end)
|
||||
label $out | reduce .[] as $item (null; if .==false then break $out else ... end)
|
||||
|
||||
The following jq program produces a syntax error:
|
||||
|
||||
break
|
||||
break $out
|
||||
|
||||
because:
|
||||
|
||||
jq: error: break used outside labeled control structure
|
||||
because no label `$out` is visible.
|
||||
|
||||
- title: "`?` operator"
|
||||
body: |
|
||||
|
||||
@@ -358,8 +358,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
|
||||
*yy_cp = '\0'; \
|
||||
yyg->yy_c_buf_p = yy_cp;
|
||||
|
||||
#define YY_NUM_RULES 49
|
||||
#define YY_END_OF_BUFFER 50
|
||||
#define YY_NUM_RULES 47
|
||||
#define YY_END_OF_BUFFER 48
|
||||
/* This struct is not used in this scanner,
|
||||
but its presence is necessary. */
|
||||
struct yy_trans_info
|
||||
@@ -367,24 +367,23 @@ struct yy_trans_info
|
||||
flex_int32_t yy_verify;
|
||||
flex_int32_t yy_nxt;
|
||||
};
|
||||
static yyconst flex_int16_t yy_accept[143] =
|
||||
static yyconst flex_int16_t yy_accept[141] =
|
||||
{ 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 50, 48, 47, 47, 48, 39, 1, 34,
|
||||
34, 35, 36, 34, 34, 34, 34, 34, 38, 34,
|
||||
34, 34, 48, 45, 45, 45, 45, 45, 45, 45,
|
||||
45, 45, 45, 45, 45, 45, 34, 43, 43, 41,
|
||||
44, 47, 2, 1, 29, 27, 25, 26, 33, 38,
|
||||
46, 46, 17, 28, 0, 31, 3, 32, 37, 45,
|
||||
0, 45, 4, 45, 45, 45, 45, 45, 45, 8,
|
||||
45, 45, 45, 13, 45, 45, 45, 24, 43, 42,
|
||||
40, 42, 46, 0, 38, 30, 38, 0, 12, 45,
|
||||
0, 0, 48, 46, 45, 45, 46, 37, 1, 32,
|
||||
32, 33, 34, 32, 32, 32, 32, 32, 36, 32,
|
||||
32, 32, 46, 43, 43, 43, 43, 43, 43, 43,
|
||||
43, 43, 43, 43, 43, 43, 32, 41, 41, 39,
|
||||
42, 45, 2, 1, 27, 25, 23, 24, 31, 36,
|
||||
44, 44, 17, 26, 0, 29, 3, 30, 35, 43,
|
||||
0, 43, 4, 43, 43, 43, 43, 43, 43, 8,
|
||||
43, 43, 43, 13, 43, 43, 43, 22, 41, 40,
|
||||
38, 40, 44, 0, 36, 28, 36, 0, 12, 43,
|
||||
|
||||
45, 7, 45, 45, 14, 45, 45, 45, 45, 45,
|
||||
45, 18, 0, 42, 45, 45, 45, 11, 10, 45,
|
||||
45, 45, 45, 45, 9, 42, 21, 19, 45, 45,
|
||||
20, 45, 45, 42, 22, 23, 45, 5, 6, 15,
|
||||
16, 0
|
||||
43, 7, 43, 43, 14, 43, 43, 43, 43, 43,
|
||||
43, 18, 0, 40, 43, 43, 43, 11, 10, 43,
|
||||
43, 43, 43, 43, 9, 40, 21, 19, 43, 43,
|
||||
20, 43, 43, 40, 43, 5, 6, 15, 16, 0
|
||||
} ;
|
||||
|
||||
static yyconst flex_int32_t yy_ec[256] =
|
||||
@@ -393,16 +392,16 @@ static yyconst flex_int32_t yy_ec[256] =
|
||||
1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 5, 6, 7, 8, 9, 1, 1, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 18, 19,
|
||||
20, 18, 18, 18, 18, 18, 18, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 28, 28, 28, 29, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
30, 31, 32, 1, 33, 1, 34, 35, 36, 37,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 19, 20, 21,
|
||||
22, 23, 24, 25, 26, 26, 26, 26, 27, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
28, 29, 30, 1, 31, 1, 32, 33, 34, 35,
|
||||
|
||||
38, 39, 28, 40, 41, 28, 42, 43, 44, 45,
|
||||
46, 47, 28, 48, 49, 50, 51, 28, 28, 28,
|
||||
52, 28, 53, 54, 55, 1, 1, 1, 1, 1,
|
||||
36, 37, 26, 38, 39, 26, 40, 41, 42, 43,
|
||||
44, 45, 26, 46, 47, 48, 49, 26, 26, 26,
|
||||
50, 26, 51, 52, 53, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
@@ -419,146 +418,140 @@ static yyconst flex_int32_t yy_ec[256] =
|
||||
1, 1, 1, 1, 1
|
||||
} ;
|
||||
|
||||
static yyconst flex_int32_t yy_meta[56] =
|
||||
static yyconst flex_int32_t yy_meta[54] =
|
||||
{ 0,
|
||||
1, 1, 2, 2, 1, 3, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 4, 1, 5, 5, 5,
|
||||
6, 1, 1, 1, 1, 1, 1, 7, 7, 1,
|
||||
8, 1, 9, 7, 7, 7, 7, 7, 7, 7,
|
||||
1, 1, 1, 1, 1, 4, 1, 5, 6, 1,
|
||||
1, 1, 1, 1, 1, 7, 7, 1, 8, 1,
|
||||
9, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 1, 1, 1
|
||||
1, 1, 1
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_base[156] =
|
||||
static yyconst flex_int16_t yy_base[154] =
|
||||
{ 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
53, 54, 317, 318, 59, 61, 292, 318, 0, 318,
|
||||
291, 318, 318, 290, 289, 288, 49, 49, 61, 287,
|
||||
286, 285, 0, 287, 37, 49, 54, 51, 50, 55,
|
||||
70, 62, 71, 73, 77, 79, 283, 0, 0, 318,
|
||||
92, 101, 318, 0, 318, 318, 318, 318, 104, 110,
|
||||
0, 92, 282, 318, 131, 318, 318, 318, 0, 284,
|
||||
283, 95, 280, 87, 85, 92, 113, 115, 97, 276,
|
||||
116, 120, 119, 272, 132, 126, 136, 318, 0, 259,
|
||||
318, 255, 0, 140, 147, 318, 152, 0, 262, 140,
|
||||
51, 52, 293, 294, 57, 59, 270, 294, 0, 294,
|
||||
269, 294, 294, 268, 267, 266, 47, 47, 50, 265,
|
||||
264, 263, 0, 265, 48, 51, 52, 37, 53, 56,
|
||||
66, 57, 60, 59, 63, 68, 261, 0, 0, 294,
|
||||
78, 90, 294, 0, 294, 294, 294, 294, 93, 94,
|
||||
0, 100, 260, 294, 104, 294, 294, 294, 0, 262,
|
||||
259, 88, 255, 97, 83, 105, 106, 109, 113, 251,
|
||||
107, 115, 116, 248, 119, 120, 117, 294, 0, 234,
|
||||
294, 231, 0, 240, 228, 294, 223, 0, 218, 118,
|
||||
|
||||
147, 260, 152, 154, 248, 155, 156, 157, 158, 159,
|
||||
160, 243, 172, 229, 234, 164, 163, 232, 229, 165,
|
||||
166, 168, 169, 177, 227, 207, 196, 205, 183, 175,
|
||||
201, 180, 186, 190, 199, 179, 187, 176, 173, 117,
|
||||
53, 318, 227, 236, 242, 247, 252, 261, 270, 275,
|
||||
280, 282, 287, 291, 295
|
||||
121, 213, 124, 122, 211, 127, 128, 130, 138, 141,
|
||||
143, 208, 154, 196, 196, 149, 146, 183, 182, 150,
|
||||
151, 152, 154, 157, 181, 165, 169, 166, 158, 156,
|
||||
164, 160, 162, 149, 161, 155, 82, 79, 71, 294,
|
||||
204, 213, 219, 224, 229, 238, 247, 252, 257, 259,
|
||||
264, 268, 272
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_def[156] =
|
||||
static yyconst flex_int16_t yy_def[154] =
|
||||
{ 0,
|
||||
142, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
143, 143, 142, 142, 142, 142, 142, 142, 144, 142,
|
||||
142, 142, 142, 142, 142, 142, 145, 142, 142, 142,
|
||||
142, 142, 146, 147, 147, 147, 147, 147, 147, 147,
|
||||
147, 147, 147, 147, 147, 147, 142, 148, 148, 142,
|
||||
149, 142, 142, 144, 142, 142, 142, 142, 142, 142,
|
||||
150, 150, 142, 142, 142, 142, 142, 142, 146, 147,
|
||||
142, 147, 147, 147, 147, 147, 147, 147, 147, 147,
|
||||
147, 147, 147, 147, 147, 147, 147, 142, 148, 142,
|
||||
142, 151, 150, 142, 150, 142, 142, 152, 147, 147,
|
||||
140, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
141, 141, 140, 140, 140, 140, 140, 140, 142, 140,
|
||||
140, 140, 140, 140, 140, 140, 143, 140, 140, 140,
|
||||
140, 140, 144, 145, 145, 145, 145, 145, 145, 145,
|
||||
145, 145, 145, 145, 145, 145, 140, 146, 146, 140,
|
||||
147, 140, 140, 142, 140, 140, 140, 140, 140, 140,
|
||||
148, 148, 140, 140, 140, 140, 140, 140, 144, 145,
|
||||
140, 145, 145, 145, 145, 145, 145, 145, 145, 145,
|
||||
145, 145, 145, 145, 145, 145, 145, 140, 146, 140,
|
||||
140, 149, 148, 140, 148, 140, 140, 150, 145, 145,
|
||||
|
||||
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
|
||||
147, 147, 149, 153, 147, 147, 147, 147, 147, 147,
|
||||
147, 147, 147, 147, 147, 154, 147, 147, 147, 147,
|
||||
147, 147, 147, 155, 147, 147, 147, 147, 147, 147,
|
||||
147, 0, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142
|
||||
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
|
||||
145, 145, 147, 151, 145, 145, 145, 145, 145, 145,
|
||||
145, 145, 145, 145, 145, 152, 145, 145, 145, 145,
|
||||
145, 145, 145, 153, 145, 145, 145, 145, 145, 0,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_nxt[374] =
|
||||
static yyconst flex_int16_t yy_nxt[348] =
|
||||
{ 0,
|
||||
14, 15, 16, 14, 17, 18, 19, 20, 21, 22,
|
||||
23, 24, 25, 20, 26, 27, 28, 29, 29, 29,
|
||||
20, 20, 30, 31, 32, 20, 33, 34, 34, 22,
|
||||
14, 23, 34, 35, 36, 37, 38, 39, 40, 34,
|
||||
41, 34, 42, 43, 34, 44, 34, 45, 34, 46,
|
||||
34, 34, 22, 47, 23, 49, 49, 71, 50, 50,
|
||||
52, 52, 52, 52, 59, 63, 60, 60, 60, 71,
|
||||
71, 71, 64, 71, 71, 71, 60, 62, 60, 60,
|
||||
60, 72, 71, 51, 51, 73, 62, 75, 76, 65,
|
||||
71, 71, 77, 71, 78, 82, 74, 71, 65, 71,
|
||||
23, 24, 25, 20, 26, 27, 28, 29, 20, 20,
|
||||
30, 31, 32, 20, 33, 34, 34, 22, 14, 23,
|
||||
34, 35, 36, 37, 38, 39, 40, 34, 41, 34,
|
||||
42, 43, 34, 44, 34, 45, 34, 46, 34, 34,
|
||||
22, 47, 23, 49, 49, 71, 50, 50, 52, 52,
|
||||
52, 52, 59, 63, 60, 60, 71, 60, 64, 71,
|
||||
71, 71, 76, 62, 71, 71, 65, 71, 71, 51,
|
||||
51, 71, 62, 75, 71, 65, 71, 91, 82, 71,
|
||||
72, 52, 52, 77, 73, 78, 74, 71, 85, 79,
|
||||
|
||||
79, 91, 52, 52, 94, 71, 94, 71, 80, 95,
|
||||
95, 95, 71, 81, 85, 71, 83, 71, 86, 60,
|
||||
84, 60, 60, 60, 100, 60, 87, 60, 60, 60,
|
||||
102, 99, 65, 71, 101, 71, 71, 71, 65, 71,
|
||||
71, 65, 92, 94, 106, 94, 71, 65, 97, 97,
|
||||
97, 105, 71, 103, 108, 109, 71, 97, 97, 97,
|
||||
71, 104, 107, 111, 95, 95, 95, 71, 110, 97,
|
||||
97, 97, 71, 116, 71, 71, 71, 71, 71, 71,
|
||||
71, 142, 117, 71, 71, 71, 71, 112, 71, 71,
|
||||
118, 119, 120, 71, 122, 71, 71, 71, 129, 71,
|
||||
71, 71, 80, 83, 84, 86, 71, 81, 60, 60,
|
||||
60, 60, 94, 87, 94, 71, 94, 95, 94, 65,
|
||||
65, 97, 99, 71, 71, 71, 92, 71, 65, 65,
|
||||
101, 71, 100, 71, 71, 71, 71, 71, 71, 71,
|
||||
71, 102, 71, 105, 103, 71, 71, 108, 71, 116,
|
||||
109, 107, 104, 110, 117, 111, 71, 119, 106, 71,
|
||||
118, 71, 120, 140, 71, 122, 112, 71, 71, 71,
|
||||
71, 121, 71, 71, 71, 71, 71, 113, 71, 71,
|
||||
71, 129, 71, 128, 71, 125, 123, 71, 127, 124,
|
||||
133, 135, 131, 113, 132, 137, 130, 138, 139, 71,
|
||||
|
||||
71, 121, 128, 71, 125, 127, 71, 71, 123, 124,
|
||||
131, 132, 133, 130, 135, 136, 71, 139, 137, 71,
|
||||
113, 71, 92, 140, 138, 71, 141, 48, 48, 48,
|
||||
48, 48, 48, 48, 48, 48, 54, 113, 54, 54,
|
||||
54, 54, 54, 54, 54, 61, 61, 71, 61, 71,
|
||||
61, 69, 71, 69, 71, 69, 70, 70, 70, 113,
|
||||
70, 89, 89, 71, 89, 89, 89, 89, 71, 89,
|
||||
90, 90, 90, 90, 90, 90, 90, 90, 90, 93,
|
||||
71, 93, 71, 93, 114, 113, 114, 114, 115, 113,
|
||||
115, 126, 71, 126, 126, 134, 71, 134, 134, 90,
|
||||
71, 71, 92, 136, 48, 48, 48, 48, 48, 48,
|
||||
48, 48, 48, 54, 71, 54, 54, 54, 54, 54,
|
||||
54, 54, 61, 61, 113, 61, 71, 61, 69, 71,
|
||||
69, 71, 69, 70, 70, 70, 71, 70, 89, 89,
|
||||
97, 89, 89, 89, 89, 95, 89, 90, 90, 90,
|
||||
90, 90, 90, 90, 90, 90, 93, 97, 93, 113,
|
||||
93, 114, 113, 114, 114, 115, 71, 115, 126, 71,
|
||||
126, 126, 134, 71, 134, 134, 90, 98, 90, 90,
|
||||
71, 96, 88, 71, 68, 67, 66, 58, 57, 56,
|
||||
55, 53, 140, 13, 140, 140, 140, 140, 140, 140,
|
||||
|
||||
71, 90, 90, 98, 71, 96, 88, 71, 68, 67,
|
||||
66, 58, 57, 56, 55, 53, 142, 13, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_chk[374] =
|
||||
static yyconst flex_int16_t yy_chk[348] =
|
||||
{ 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 11, 12, 35, 11, 12,
|
||||
15, 15, 16, 16, 27, 28, 27, 27, 27, 36,
|
||||
39, 38, 28, 141, 37, 40, 29, 27, 29, 29,
|
||||
29, 35, 42, 11, 12, 35, 27, 37, 38, 29,
|
||||
41, 43, 39, 44, 39, 42, 36, 45, 29, 46,
|
||||
1, 1, 1, 11, 12, 38, 11, 12, 15, 15,
|
||||
16, 16, 27, 28, 27, 29, 35, 29, 28, 36,
|
||||
37, 39, 38, 27, 40, 42, 29, 44, 43, 11,
|
||||
12, 45, 27, 37, 41, 29, 46, 51, 42, 139,
|
||||
35, 52, 52, 39, 35, 39, 36, 138, 45, 40,
|
||||
|
||||
40, 51, 52, 52, 62, 75, 62, 74, 41, 62,
|
||||
62, 62, 76, 41, 45, 72, 43, 79, 46, 59,
|
||||
44, 59, 59, 59, 74, 60, 46, 60, 60, 60,
|
||||
76, 72, 59, 77, 75, 78, 81, 140, 60, 83,
|
||||
82, 59, 51, 65, 79, 65, 86, 60, 65, 65,
|
||||
65, 78, 85, 77, 82, 83, 87, 94, 94, 94,
|
||||
100, 77, 81, 86, 95, 95, 95, 101, 85, 97,
|
||||
97, 97, 103, 100, 104, 106, 107, 108, 109, 110,
|
||||
111, 113, 101, 117, 116, 120, 121, 87, 122, 123,
|
||||
103, 104, 106, 139, 108, 130, 138, 124, 120, 136,
|
||||
137, 75, 41, 43, 44, 46, 72, 41, 59, 60,
|
||||
59, 60, 62, 46, 62, 74, 65, 62, 65, 59,
|
||||
60, 65, 72, 76, 77, 81, 51, 78, 59, 60,
|
||||
75, 79, 74, 82, 83, 87, 100, 85, 86, 101,
|
||||
104, 76, 103, 78, 77, 106, 107, 82, 108, 100,
|
||||
83, 81, 77, 85, 101, 86, 109, 104, 79, 110,
|
||||
103, 111, 106, 113, 117, 108, 87, 116, 120, 121,
|
||||
122, 107, 123, 136, 130, 124, 129, 134, 132, 135,
|
||||
133, 120, 131, 117, 128, 111, 109, 127, 116, 110,
|
||||
124, 129, 122, 126, 123, 132, 121, 133, 135, 125,
|
||||
|
||||
132, 107, 117, 129, 111, 116, 133, 137, 109, 110,
|
||||
122, 123, 124, 121, 127, 127, 127, 132, 129, 135,
|
||||
134, 131, 113, 133, 130, 128, 137, 143, 143, 143,
|
||||
143, 143, 143, 143, 143, 143, 144, 126, 144, 144,
|
||||
144, 144, 144, 144, 144, 145, 145, 125, 145, 119,
|
||||
145, 146, 118, 146, 115, 146, 147, 147, 147, 114,
|
||||
147, 148, 148, 112, 148, 148, 148, 148, 105, 148,
|
||||
149, 149, 149, 149, 149, 149, 149, 149, 149, 150,
|
||||
102, 150, 99, 150, 151, 92, 151, 151, 152, 90,
|
||||
152, 153, 84, 153, 153, 154, 80, 154, 154, 155,
|
||||
119, 118, 113, 130, 141, 141, 141, 141, 141, 141,
|
||||
141, 141, 141, 142, 115, 142, 142, 142, 142, 142,
|
||||
142, 142, 143, 143, 114, 143, 112, 143, 144, 105,
|
||||
144, 102, 144, 145, 145, 145, 99, 145, 146, 146,
|
||||
97, 146, 146, 146, 146, 95, 146, 147, 147, 147,
|
||||
147, 147, 147, 147, 147, 147, 148, 94, 148, 92,
|
||||
148, 149, 90, 149, 149, 150, 84, 150, 151, 80,
|
||||
151, 151, 152, 73, 152, 152, 153, 71, 153, 153,
|
||||
70, 63, 47, 34, 32, 31, 30, 26, 25, 24,
|
||||
21, 17, 13, 140, 140, 140, 140, 140, 140, 140,
|
||||
|
||||
73, 155, 155, 71, 70, 63, 47, 34, 32, 31,
|
||||
30, 26, 25, 24, 21, 17, 13, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
|
||||
142, 142, 142
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
|
||||
140, 140, 140, 140, 140, 140, 140
|
||||
} ;
|
||||
|
||||
/* The intent behind this definition is that it'll catch
|
||||
@@ -594,7 +587,7 @@ struct lexer_param;
|
||||
static int enter(int opening, int state, yyscan_t yyscanner);
|
||||
static int try_exit(int closing, int state, yyscan_t yyscanner);
|
||||
#define YY_NO_INPUT 1
|
||||
#line 598 "lexer.c"
|
||||
#line 591 "lexer.c"
|
||||
|
||||
#define INITIAL 0
|
||||
#define IN_PAREN 1
|
||||
@@ -850,7 +843,7 @@ YY_DECL
|
||||
#line 38 "lexer.l"
|
||||
|
||||
|
||||
#line 854 "lexer.c"
|
||||
#line 847 "lexer.c"
|
||||
|
||||
yylval = yylval_param;
|
||||
|
||||
@@ -907,13 +900,13 @@ yy_match:
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 143 )
|
||||
if ( yy_current_state >= 141 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
++yy_cp;
|
||||
}
|
||||
while ( yy_base[yy_current_state] != 318 );
|
||||
while ( yy_base[yy_current_state] != 294 );
|
||||
|
||||
yy_find_action:
|
||||
yy_act = yy_accept[yy_current_state];
|
||||
@@ -1045,124 +1038,114 @@ YY_RULE_SETUP
|
||||
case 22:
|
||||
YY_RULE_SETUP
|
||||
#line 62 "lexer.l"
|
||||
{ return BREAK2; }
|
||||
{ return SETPIPE; }
|
||||
YY_BREAK
|
||||
case 23:
|
||||
YY_RULE_SETUP
|
||||
#line 63 "lexer.l"
|
||||
{ return BREAK3; }
|
||||
{ return SETPLUS; }
|
||||
YY_BREAK
|
||||
case 24:
|
||||
YY_RULE_SETUP
|
||||
#line 64 "lexer.l"
|
||||
{ return SETPIPE; }
|
||||
{ return SETMINUS; }
|
||||
YY_BREAK
|
||||
case 25:
|
||||
YY_RULE_SETUP
|
||||
#line 65 "lexer.l"
|
||||
{ return SETPLUS; }
|
||||
{ return SETMULT; }
|
||||
YY_BREAK
|
||||
case 26:
|
||||
YY_RULE_SETUP
|
||||
#line 66 "lexer.l"
|
||||
{ return SETMINUS; }
|
||||
{ return SETDIV; }
|
||||
YY_BREAK
|
||||
case 27:
|
||||
YY_RULE_SETUP
|
||||
#line 67 "lexer.l"
|
||||
{ return SETMULT; }
|
||||
{ return SETMOD; }
|
||||
YY_BREAK
|
||||
case 28:
|
||||
YY_RULE_SETUP
|
||||
#line 68 "lexer.l"
|
||||
{ return SETDIV; }
|
||||
{ return SETDEFINEDOR; }
|
||||
YY_BREAK
|
||||
case 29:
|
||||
YY_RULE_SETUP
|
||||
#line 69 "lexer.l"
|
||||
{ return SETMOD; }
|
||||
{ return LESSEQ; }
|
||||
YY_BREAK
|
||||
case 30:
|
||||
YY_RULE_SETUP
|
||||
#line 70 "lexer.l"
|
||||
{ return SETDEFINEDOR; }
|
||||
{ return GREATEREQ; }
|
||||
YY_BREAK
|
||||
case 31:
|
||||
YY_RULE_SETUP
|
||||
#line 71 "lexer.l"
|
||||
{ return LESSEQ; }
|
||||
{ return REC; }
|
||||
YY_BREAK
|
||||
case 32:
|
||||
YY_RULE_SETUP
|
||||
#line 72 "lexer.l"
|
||||
{ return GREATEREQ; }
|
||||
{ return yytext[0];}
|
||||
YY_BREAK
|
||||
case 33:
|
||||
YY_RULE_SETUP
|
||||
#line 73 "lexer.l"
|
||||
{ return REC; }
|
||||
YY_BREAK
|
||||
case 34:
|
||||
YY_RULE_SETUP
|
||||
#line 74 "lexer.l"
|
||||
{ return yytext[0];}
|
||||
YY_BREAK
|
||||
case 35:
|
||||
YY_RULE_SETUP
|
||||
#line 76 "lexer.l"
|
||||
{
|
||||
return enter(yytext[0], YY_START, yyscanner);
|
||||
}
|
||||
YY_BREAK
|
||||
case 36:
|
||||
case 34:
|
||||
YY_RULE_SETUP
|
||||
#line 80 "lexer.l"
|
||||
#line 78 "lexer.l"
|
||||
{
|
||||
return try_exit(yytext[0], YY_START, yyscanner);
|
||||
}
|
||||
YY_BREAK
|
||||
case 37:
|
||||
case 35:
|
||||
YY_RULE_SETUP
|
||||
#line 84 "lexer.l"
|
||||
#line 82 "lexer.l"
|
||||
{
|
||||
yylval->literal = jv_string_sized(yytext + 1, yyleng - 1); return FORMAT;
|
||||
}
|
||||
YY_BREAK
|
||||
case 38:
|
||||
case 36:
|
||||
YY_RULE_SETUP
|
||||
#line 88 "lexer.l"
|
||||
#line 86 "lexer.l"
|
||||
{
|
||||
yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;
|
||||
}
|
||||
YY_BREAK
|
||||
case 39:
|
||||
case 37:
|
||||
YY_RULE_SETUP
|
||||
#line 92 "lexer.l"
|
||||
#line 90 "lexer.l"
|
||||
{
|
||||
yy_push_state(IN_QQSTRING, yyscanner);
|
||||
return QQSTRING_START;
|
||||
}
|
||||
YY_BREAK
|
||||
|
||||
case 40:
|
||||
case 38:
|
||||
YY_RULE_SETUP
|
||||
#line 98 "lexer.l"
|
||||
#line 96 "lexer.l"
|
||||
{
|
||||
return enter(QQSTRING_INTERP_START, YY_START, yyscanner);
|
||||
}
|
||||
YY_BREAK
|
||||
case 41:
|
||||
case 39:
|
||||
YY_RULE_SETUP
|
||||
#line 101 "lexer.l"
|
||||
#line 99 "lexer.l"
|
||||
{
|
||||
yy_pop_state(yyscanner);
|
||||
return QQSTRING_END;
|
||||
}
|
||||
YY_BREAK
|
||||
case 42:
|
||||
/* rule 42 can match eol */
|
||||
case 40:
|
||||
/* rule 40 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 105 "lexer.l"
|
||||
#line 103 "lexer.l"
|
||||
{
|
||||
/* pass escapes to the json parser */
|
||||
jv escapes = jv_string_fmt("\"%.*s\"", (int)yyleng, yytext);
|
||||
@@ -1171,50 +1154,50 @@ YY_RULE_SETUP
|
||||
return QQSTRING_TEXT;
|
||||
}
|
||||
YY_BREAK
|
||||
case 43:
|
||||
/* rule 43 can match eol */
|
||||
case 41:
|
||||
/* rule 41 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 112 "lexer.l"
|
||||
#line 110 "lexer.l"
|
||||
{
|
||||
yylval->literal = jv_string_sized(yytext, yyleng);
|
||||
return QQSTRING_TEXT;
|
||||
}
|
||||
YY_BREAK
|
||||
case 44:
|
||||
case 42:
|
||||
YY_RULE_SETUP
|
||||
#line 116 "lexer.l"
|
||||
#line 114 "lexer.l"
|
||||
{
|
||||
return INVALID_CHARACTER;
|
||||
}
|
||||
YY_BREAK
|
||||
|
||||
case 45:
|
||||
case 43:
|
||||
YY_RULE_SETUP
|
||||
#line 122 "lexer.l"
|
||||
#line 120 "lexer.l"
|
||||
{ yylval->literal = jv_string(yytext); return IDENT;}
|
||||
YY_BREAK
|
||||
case 44:
|
||||
YY_RULE_SETUP
|
||||
#line 121 "lexer.l"
|
||||
{ yylval->literal = jv_string(yytext+1); return FIELD;}
|
||||
YY_BREAK
|
||||
case 45:
|
||||
/* rule 45 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 123 "lexer.l"
|
||||
{}
|
||||
YY_BREAK
|
||||
case 46:
|
||||
YY_RULE_SETUP
|
||||
#line 123 "lexer.l"
|
||||
{ yylval->literal = jv_string(yytext+1); return FIELD;}
|
||||
YY_BREAK
|
||||
case 47:
|
||||
/* rule 47 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 125 "lexer.l"
|
||||
{}
|
||||
YY_BREAK
|
||||
case 48:
|
||||
YY_RULE_SETUP
|
||||
#line 127 "lexer.l"
|
||||
{ return INVALID_CHARACTER; }
|
||||
YY_BREAK
|
||||
case 49:
|
||||
case 47:
|
||||
YY_RULE_SETUP
|
||||
#line 129 "lexer.l"
|
||||
#line 127 "lexer.l"
|
||||
YY_FATAL_ERROR( "flex scanner jammed" );
|
||||
YY_BREAK
|
||||
#line 1218 "lexer.c"
|
||||
#line 1201 "lexer.c"
|
||||
case YY_STATE_EOF(INITIAL):
|
||||
case YY_STATE_EOF(IN_PAREN):
|
||||
case YY_STATE_EOF(IN_BRACKET):
|
||||
@@ -1513,7 +1496,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 143 )
|
||||
if ( yy_current_state >= 141 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
@@ -1542,11 +1525,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 143 )
|
||||
if ( yy_current_state >= 141 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
yy_is_jam = (yy_current_state == 142);
|
||||
yy_is_jam = (yy_current_state == 140);
|
||||
|
||||
return yy_is_jam ? 0 : yy_current_state;
|
||||
}
|
||||
@@ -2378,7 +2361,7 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
|
||||
|
||||
#define YYTABLES_NAME "yytables"
|
||||
|
||||
#line 129 "lexer.l"
|
||||
#line 127 "lexer.l"
|
||||
|
||||
|
||||
/* perhaps these should be calls... */
|
||||
|
||||
@@ -354,7 +354,7 @@ extern int jq_yylex \
|
||||
#undef YY_DECL
|
||||
#endif
|
||||
|
||||
#line 129 "lexer.l"
|
||||
#line 127 "lexer.l"
|
||||
|
||||
|
||||
#line 361 "lexer.h"
|
||||
|
||||
@@ -59,8 +59,6 @@ struct lexer_param;
|
||||
"catch" { return CATCH; }
|
||||
"label" { return LABEL; }
|
||||
"break" { return BREAK; }
|
||||
"break2" { return BREAK2; }
|
||||
"break3" { return BREAK3; }
|
||||
"|=" { return SETPIPE; }
|
||||
"+=" { return SETPLUS; }
|
||||
"-=" { return SETMINUS; }
|
||||
|
||||
@@ -92,21 +92,19 @@ struct lexer_param;
|
||||
CATCH = 282,
|
||||
LABEL = 283,
|
||||
BREAK = 284,
|
||||
BREAK2 = 285,
|
||||
BREAK3 = 286,
|
||||
SETPIPE = 287,
|
||||
SETPLUS = 288,
|
||||
SETMINUS = 289,
|
||||
SETMULT = 290,
|
||||
SETDIV = 291,
|
||||
SETDEFINEDOR = 292,
|
||||
LESSEQ = 293,
|
||||
GREATEREQ = 294,
|
||||
QQSTRING_START = 295,
|
||||
QQSTRING_TEXT = 296,
|
||||
QQSTRING_INTERP_START = 297,
|
||||
QQSTRING_INTERP_END = 298,
|
||||
QQSTRING_END = 299
|
||||
SETPIPE = 285,
|
||||
SETPLUS = 286,
|
||||
SETMINUS = 287,
|
||||
SETMULT = 288,
|
||||
SETDIV = 289,
|
||||
SETDEFINEDOR = 290,
|
||||
LESSEQ = 291,
|
||||
GREATEREQ = 292,
|
||||
QQSTRING_START = 293,
|
||||
QQSTRING_TEXT = 294,
|
||||
QQSTRING_INTERP_START = 295,
|
||||
QQSTRING_INTERP_END = 296,
|
||||
QQSTRING_END = 297
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
@@ -137,21 +135,19 @@ struct lexer_param;
|
||||
#define CATCH 282
|
||||
#define LABEL 283
|
||||
#define BREAK 284
|
||||
#define BREAK2 285
|
||||
#define BREAK3 286
|
||||
#define SETPIPE 287
|
||||
#define SETPLUS 288
|
||||
#define SETMINUS 289
|
||||
#define SETMULT 290
|
||||
#define SETDIV 291
|
||||
#define SETDEFINEDOR 292
|
||||
#define LESSEQ 293
|
||||
#define GREATEREQ 294
|
||||
#define QQSTRING_START 295
|
||||
#define QQSTRING_TEXT 296
|
||||
#define QQSTRING_INTERP_START 297
|
||||
#define QQSTRING_INTERP_END 298
|
||||
#define QQSTRING_END 299
|
||||
#define SETPIPE 285
|
||||
#define SETPLUS 286
|
||||
#define SETMINUS 287
|
||||
#define SETMULT 288
|
||||
#define SETDIV 289
|
||||
#define SETDEFINEDOR 290
|
||||
#define LESSEQ 291
|
||||
#define GREATEREQ 292
|
||||
#define QQSTRING_START 293
|
||||
#define QQSTRING_TEXT 294
|
||||
#define QQSTRING_INTERP_START 295
|
||||
#define QQSTRING_INTERP_END 296
|
||||
#define QQSTRING_END 297
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
@@ -163,7 +159,7 @@ union YYSTYPE
|
||||
jv literal;
|
||||
block blk;
|
||||
|
||||
#line 167 "parser.h" /* yacc.c:1909 */
|
||||
#line 163 "parser.h" /* yacc.c:1909 */
|
||||
};
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
|
||||
@@ -72,8 +72,6 @@ struct lexer_param;
|
||||
%token CATCH "catch"
|
||||
%token LABEL "label"
|
||||
%token BREAK "break"
|
||||
%token BREAK2 "break2"
|
||||
%token BREAK3 "break3"
|
||||
%token SETPIPE "|="
|
||||
%token SETPLUS "+="
|
||||
%token SETMINUS "-="
|
||||
@@ -153,8 +151,6 @@ int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, block* answer, int* errors,
|
||||
return tok;
|
||||
}
|
||||
|
||||
static unsigned int next_label = 0;
|
||||
|
||||
static block gen_dictpair(block k, block v) {
|
||||
return BLOCK(gen_subexp(k), gen_subexp(v), gen_op_simple(INSERT));
|
||||
}
|
||||
@@ -351,12 +347,6 @@ Term "as" '$' IDENT '|' Exp {
|
||||
$$ = $2;
|
||||
} |
|
||||
|
||||
"label" '|' Exp {
|
||||
jv v = jv_string_fmt("*anonlabel%u", next_label++);
|
||||
$$ = gen_location(@$, locations, gen_label(jv_string_value(v), $3));
|
||||
jv_free(v);
|
||||
} |
|
||||
|
||||
"label" '$' IDENT '|' Exp {
|
||||
jv v = jv_string_fmt("*label-%s", jv_string_value($3));
|
||||
$$ = gen_location(@$, locations, gen_label(jv_string_value(v), $5));
|
||||
@@ -600,21 +590,6 @@ Term:
|
||||
REC {
|
||||
$$ = gen_call("recurse", gen_noop());
|
||||
} |
|
||||
BREAK {
|
||||
$$ = gen_location(@$, locations,
|
||||
BLOCK(gen_op_unbound(LOADV, "*1"), // impossible symbol
|
||||
gen_call("error", gen_noop())));
|
||||
} |
|
||||
BREAK2 {
|
||||
$$ = gen_location(@$, locations,
|
||||
BLOCK(gen_op_unbound(LOADV, "*2"), // impossible symbol
|
||||
gen_call("error", gen_noop())));
|
||||
} |
|
||||
BREAK3 {
|
||||
$$ = gen_location(@$, locations,
|
||||
BLOCK(gen_op_unbound(LOADV, "*3"), // impossible symbol
|
||||
gen_call("error", gen_noop())));
|
||||
} |
|
||||
BREAK '$' IDENT {
|
||||
jv v = jv_string_fmt("*label-%s", jv_string_value($3)); // impossible symbol
|
||||
$$ = gen_location(@$, locations,
|
||||
@@ -623,6 +598,10 @@ BREAK '$' IDENT {
|
||||
jv_free(v);
|
||||
jv_free($3);
|
||||
} |
|
||||
BREAK error {
|
||||
FAIL(@$, "break requires a label to break to");
|
||||
$$ = gen_noop();
|
||||
} |
|
||||
Term FIELD '?' {
|
||||
$$ = gen_index_opt($1, gen_const($2));
|
||||
} |
|
||||
|
||||
+1
-13
@@ -247,10 +247,6 @@ null
|
||||
1
|
||||
[1,2,4,8,16,32,64]
|
||||
|
||||
[label | while(.<100; .*2|if . > 10 then break else . end)]
|
||||
1
|
||||
[1,2,4,8]
|
||||
|
||||
[(label $here | .[] | if .>1 then break $here else . end), "hi!"]
|
||||
[0,1,2]
|
||||
[0,1,"hi!"]
|
||||
@@ -259,14 +255,6 @@ null
|
||||
[0,2,1]
|
||||
[0,"hi!"]
|
||||
|
||||
(label | (label | 2 | break2)), 1
|
||||
null
|
||||
1
|
||||
|
||||
%%FAIL
|
||||
break
|
||||
jq: error: break used outside labeled control structure
|
||||
|
||||
%%FAIL
|
||||
. as $foo | break $foo
|
||||
jq: error: *label-foo/0 is not defined
|
||||
@@ -275,7 +263,7 @@ jq: error: *label-foo/0 is not defined
|
||||
[1,2,3,4,5]
|
||||
[1,2,6,24,120]
|
||||
|
||||
[label | foreach .[] as $item ([3, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1])]
|
||||
[label $out | foreach .[] as $item ([3, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1])]
|
||||
[11,22,33,44,55,66,77,88,99]
|
||||
[11,22,33]
|
||||
|
||||
|
||||
Reference in new issue
Block a user