Skip to content

Commit

Permalink
Fix number lexer to avoid conflict with object indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jul 13, 2021
1 parent d18b2d0 commit 596b591
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 128 deletions.
254 changes: 127 additions & 127 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,25 +582,25 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static const flex_int16_t yy_accept[157] =
static const flex_int16_t yy_accept[158] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 51, 49, 48, 48, 49, 40, 1, 35,
35, 36, 37, 35, 35, 35, 35, 35, 39, 35,
35, 35, 35, 49, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 35, 44,
44, 42, 45, 48, 2, 1, 29, 27, 25, 26,
33, 39, 47, 47, 18, 28, 0, 31, 3, 32,
0, 38, 46, 0, 46, 46, 4, 46, 46, 46,
46, 46, 46, 9, 46, 46, 46, 46, 14, 46,
46, 46, 24, 44, 43, 41, 43, 47, 0, 39,

30, 39, 34, 0, 46, 13, 46, 46, 8, 46,
46, 15, 46, 46, 46, 46, 46, 46, 46, 19,
0, 43, 46, 46, 46, 46, 12, 11, 46, 46,
46, 46, 46, 46, 10, 43, 46, 22, 20, 46,
46, 46, 21, 46, 46, 43, 46, 46, 5, 46,
7, 16, 23, 17, 6, 0
33, 39, 47, 18, 28, 39, 39, 0, 31, 3,
32, 0, 38, 46, 0, 46, 46, 4, 46, 46,
46, 46, 46, 46, 9, 46, 46, 46, 46, 14,
46, 46, 46, 24, 44, 43, 41, 43, 47, 30,

39, 0, 39, 34, 0, 46, 13, 46, 46, 8,
46, 46, 15, 46, 46, 46, 46, 46, 46, 46,
19, 0, 43, 46, 46, 46, 46, 12, 11, 46,
46, 46, 46, 46, 46, 10, 43, 46, 22, 20,
46, 46, 46, 21, 46, 46, 43, 46, 46, 5,
46, 7, 16, 23, 17, 6, 0
} ;

static const YY_CHAR yy_ec[256] =
Expand Down Expand Up @@ -645,138 +645,138 @@ static const YY_CHAR yy_meta[54] =
1, 1, 1
} ;

static const flex_int16_t yy_base[170] =
static const flex_int16_t yy_base[171] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51, 52, 320, 321, 57, 59, 297, 321, 0, 321,
296, 321, 321, 295, 294, 293, 47, 47, 50, 292,
291, 290, 294, 0, 291, 48, 51, 53, 52, 37,
59, 57, 66, 56, 63, 68, 70, 72, 287, 0,
0, 321, 80, 90, 321, 0, 321, 321, 321, 321,
95, 99, 0, 106, 286, 321, 110, 321, 321, 321,
290, 0, 285, 281, 86, 77, 277, 97, 101, 111,
113, 115, 117, 274, 119, 120, 118, 121, 270, 122,
123, 124, 321, 0, 257, 321, 255, 0, 254, 249,

321, 245, 321, 0, 125, 239, 126, 127, 237, 128,
134, 234, 136, 143, 147, 148, 149, 152, 154, 232,
165, 212, 210, 157, 159, 158, 209, 208, 160, 161,
162, 163, 164, 166, 207, 196, 171, 205, 204, 174,
167, 175, 201, 170, 176, 190, 190, 184, 199, 194,
198, 197, 85, 78, 76, 321, 230, 239, 245, 250,
255, 264, 273, 278, 283, 285, 290, 294, 298
51, 52, 319, 320, 57, 59, 296, 320, 0, 320,
295, 320, 320, 294, 293, 292, 47, 47, 50, 291,
290, 289, 293, 0, 290, 48, 51, 37, 52, 53,
54, 55, 59, 56, 63, 57, 68, 71, 286, 0,
0, 320, 75, 89, 320, 0, 320, 320, 320, 320,
320, 87, 0, 285, 320, 92, 95, 103, 320, 320,
320, 289, 0, 286, 285, 74, 101, 284, 89, 81,
93, 87, 108, 113, 283, 116, 114, 118, 119, 282,
120, 121, 122, 320, 0, 271, 320, 270, 0, 320,

126, 280, 279, 320, 0, 123, 277, 126, 130, 274,
128, 127, 270, 133, 131, 137, 141, 147, 149, 151,
266, 161, 253, 259, 154, 155, 161, 256, 254, 157,
160, 162, 163, 164, 166, 242, 227, 171, 233, 228,
167, 165, 168, 226, 172, 173, 213, 188, 174, 221,
178, 211, 199, 198, 197, 196, 320, 219, 228, 234,
239, 244, 253, 262, 267, 272, 274, 279, 283, 287
} ;

static const flex_int16_t yy_def[170] =
static const flex_int16_t yy_def[171] =
{ 0,
156, 1, 1, 1, 1, 1, 1, 1, 1, 1,
157, 157, 156, 156, 156, 156, 156, 156, 158, 156,
156, 156, 156, 156, 156, 156, 159, 156, 156, 156,
156, 156, 156, 160, 161, 161, 161, 161, 161, 161,
161, 161, 161, 161, 161, 161, 161, 161, 156, 162,
162, 156, 163, 156, 156, 158, 156, 156, 156, 156,
156, 156, 164, 164, 156, 156, 156, 156, 156, 156,
156, 160, 161, 156, 161, 161, 161, 161, 161, 161,
161, 161, 161, 161, 161, 161, 161, 161, 161, 161,
161, 161, 156, 162, 156, 156, 165, 164, 156, 164,

156, 156, 156, 166, 161, 161, 161, 161, 161, 161,
161, 161, 161, 161, 161, 161, 161, 161, 161, 161,
163, 167, 161, 161, 161, 161, 161, 161, 161, 161,
161, 161, 161, 161, 161, 168, 161, 161, 161, 161,
161, 161, 161, 161, 161, 169, 161, 161, 161, 161,
161, 161, 161, 161, 161, 0, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156
157, 1, 1, 1, 1, 1, 1, 1, 1, 1,
158, 158, 157, 157, 157, 157, 157, 157, 159, 157,
157, 157, 157, 157, 157, 157, 160, 157, 157, 157,
157, 157, 157, 161, 162, 162, 162, 162, 162, 162,
162, 162, 162, 162, 162, 162, 162, 162, 157, 163,
163, 157, 164, 157, 157, 159, 157, 157, 157, 157,
157, 157, 165, 157, 157, 157, 157, 157, 157, 157,
157, 157, 161, 162, 157, 162, 162, 162, 162, 162,
162, 162, 162, 162, 162, 162, 162, 162, 162, 162,
162, 162, 162, 157, 163, 157, 157, 166, 165, 157,

157, 157, 157, 157, 167, 162, 162, 162, 162, 162,
162, 162, 162, 162, 162, 162, 162, 162, 162, 162,
162, 164, 168, 162, 162, 162, 162, 162, 162, 162,
162, 162, 162, 162, 162, 162, 169, 162, 162, 162,
162, 162, 162, 162, 162, 162, 170, 162, 162, 162,
162, 162, 162, 162, 162, 162, 0, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157
} ;

static const flex_int16_t yy_nxt[375] =
static const flex_int16_t yy_nxt[374] =
{ 0,
14, 15, 16, 14, 17, 18, 19, 20, 21, 22,
23, 24, 25, 20, 26, 27, 28, 29, 20, 20,
30, 31, 32, 33, 34, 35, 35, 22, 14, 23,
36, 37, 38, 39, 40, 41, 42, 35, 43, 35,
44, 45, 35, 46, 35, 47, 35, 48, 35, 35,
22, 49, 23, 51, 51, 74, 52, 52, 54, 54,
54, 54, 61, 65, 62, 62, 74, 62, 66, 74,
74, 74, 80, 64, 74, 74, 67, 74, 75, 53,
53, 74, 64, 79, 74, 67, 74, 87, 74, 96,
74, 54, 54, 76, 74, 74, 74, 77, 78, 81,

83, 82, 84, 74, 74, 90, 88, 85, 86, 91,
62, 106, 62, 89, 62, 74, 62, 92, 99, 74,
99, 67, 99, 100, 99, 67, 105, 102, 97, 74,
67, 74, 107, 74, 67, 74, 74, 74, 74, 74,
74, 74, 74, 74, 74, 74, 74, 109, 108, 112,
116, 110, 74, 115, 74, 117, 118, 125, 119, 111,
126, 74, 113, 114, 127, 74, 74, 74, 124, 128,
74, 129, 74, 120, 156, 74, 74, 74, 74, 74,
74, 74, 74, 132, 74, 74, 130, 131, 74, 74,
137, 140, 74, 74, 74, 139, 135, 133, 138, 145,

134, 147, 74, 143, 144, 151, 141, 148, 74, 150,
142, 152, 74, 97, 149, 74, 74, 74, 121, 74,
153, 154, 74, 74, 121, 74, 74, 74, 74, 155,
50, 50, 50, 50, 50, 50, 50, 50, 50, 56,
121, 56, 56, 56, 56, 56, 56, 56, 63, 63,
74, 63, 74, 63, 72, 74, 72, 74, 72, 73,
73, 73, 102, 73, 94, 94, 100, 94, 94, 94,
94, 102, 94, 95, 95, 95, 95, 95, 95, 95,
95, 95, 98, 121, 98, 121, 98, 122, 74, 122,
122, 123, 74, 123, 136, 74, 136, 136, 146, 104,

146, 146, 95, 74, 95, 95, 103, 101, 93, 74,
71, 70, 69, 68, 60, 59, 58, 57, 55, 156,
13, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156
22, 49, 23, 51, 51, 75, 52, 52, 54, 54,
54, 54, 61, 64, 62, 66, 75, 67, 65, 75,
75, 75, 75, 75, 75, 75, 68, 75, 76, 53,
53, 75, 79, 80, 97, 68, 75, 88, 81, 75,
54, 54, 75, 77, 82, 85, 83, 78, 84, 75,

86, 87, 90, 91, 62, 75, 89, 75, 92, 101,
66, 75, 67, 68, 106, 102, 93, 102, 68, 75,
103, 68, 68, 98, 108, 111, 75, 68, 109, 110,
68, 75, 75, 112, 75, 107, 75, 75, 75, 75,
75, 75, 113, 101, 75, 75, 75, 116, 75, 75,
117, 75, 68, 118, 119, 75, 120, 126, 114, 75,
115, 68, 129, 127, 128, 75, 125, 75, 130, 75,
157, 121, 75, 75, 131, 75, 133, 132, 75, 75,
75, 75, 75, 75, 75, 75, 75, 138, 141, 75,
75, 75, 75, 136, 139, 134, 75, 135, 140, 146,

149, 148, 151, 144, 145, 142, 75, 152, 153, 98,
143, 155, 150, 156, 75, 75, 75, 75, 154, 50,
50, 50, 50, 50, 50, 50, 50, 50, 56, 75,
56, 56, 56, 56, 56, 56, 56, 63, 63, 75,
63, 122, 63, 73, 75, 73, 75, 73, 74, 74,
74, 75, 74, 95, 95, 122, 95, 95, 95, 95,
75, 95, 96, 96, 96, 96, 96, 96, 96, 96,
96, 99, 75, 99, 75, 99, 123, 75, 123, 123,
124, 122, 124, 137, 75, 137, 137, 147, 75, 147,
147, 96, 75, 96, 96, 75, 103, 103, 122, 122,

75, 75, 75, 105, 75, 104, 100, 94, 75, 72,
71, 70, 69, 60, 59, 58, 57, 55, 157, 13,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157
} ;

static const flex_int16_t yy_chk[375] =
static const flex_int16_t yy_chk[374] =
{ 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, 11, 12, 40, 11, 12, 15, 15,
1, 1, 1, 11, 12, 38, 11, 12, 15, 15,
16, 16, 27, 28, 27, 29, 36, 29, 28, 37,
39, 38, 40, 27, 44, 42, 29, 41, 36, 11,
12, 45, 27, 39, 43, 29, 46, 44, 47, 53,
48, 54, 54, 37, 155, 76, 154, 37, 38, 41,

42, 41, 43, 153, 75, 47, 45, 43, 43, 48,
61, 76, 61, 46, 62, 78, 62, 48, 64, 79,
64, 61, 67, 64, 67, 62, 75, 67, 53, 80,
61, 81, 78, 82, 62, 83, 87, 85, 86, 88,
90, 91, 92, 105, 107, 108, 110, 80, 79, 82,
87, 81, 111, 86, 113, 88, 90, 107, 91, 81,
108, 114, 83, 85, 110, 115, 116, 117, 105, 111,
118, 113, 119, 92, 121, 124, 126, 125, 129, 130,
131, 132, 133, 116, 134, 141, 114, 115, 144, 137,
124, 129, 140, 142, 145, 126, 119, 117, 125, 134,

118, 137, 148, 132, 133, 144, 130, 140, 147, 142,
131, 145, 150, 121, 141, 152, 151, 149, 146, 143,
147, 148, 139, 138, 136, 135, 128, 127, 123, 150,
157, 157, 157, 157, 157, 157, 157, 157, 157, 158,
122, 158, 158, 158, 158, 158, 158, 158, 159, 159,
120, 159, 112, 159, 160, 109, 160, 106, 160, 161,
161, 161, 102, 161, 162, 162, 100, 162, 162, 162,
162, 99, 162, 163, 163, 163, 163, 163, 163, 163,
163, 163, 164, 97, 164, 95, 164, 165, 89, 165,
165, 166, 84, 166, 167, 77, 167, 167, 168, 74,

168, 168, 169, 73, 169, 169, 71, 65, 49, 35,
33, 32, 31, 30, 26, 25, 24, 21, 17, 13,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
156, 156, 156, 156
39, 40, 41, 42, 44, 46, 29, 43, 36, 11,
12, 45, 38, 39, 53, 29, 47, 44, 40, 48,
54, 54, 76, 37, 41, 43, 41, 37, 42, 80,

43, 43, 46, 47, 62, 82, 45, 79, 48, 66,
67, 81, 67, 62, 76, 68, 48, 68, 66, 77,
68, 67, 62, 53, 79, 82, 83, 66, 80, 81,
67, 84, 87, 82, 86, 77, 88, 89, 91, 92,
93, 106, 83, 101, 108, 112, 111, 87, 109, 115,
88, 114, 101, 89, 91, 116, 92, 108, 84, 117,
86, 101, 112, 109, 111, 118, 106, 119, 114, 120,
122, 93, 125, 126, 115, 130, 117, 116, 131, 127,
132, 133, 134, 142, 135, 141, 143, 125, 130, 138,
145, 146, 149, 120, 126, 118, 151, 119, 127, 135,

141, 138, 143, 133, 134, 131, 148, 145, 146, 122,
132, 149, 142, 151, 156, 155, 154, 153, 148, 158,
158, 158, 158, 158, 158, 158, 158, 158, 159, 152,
159, 159, 159, 159, 159, 159, 159, 160, 160, 150,
160, 147, 160, 161, 144, 161, 140, 161, 162, 162,
162, 139, 162, 163, 163, 137, 163, 163, 163, 163,
136, 163, 164, 164, 164, 164, 164, 164, 164, 164,
164, 165, 129, 165, 128, 165, 166, 124, 166, 166,
167, 123, 167, 168, 121, 168, 168, 169, 113, 169,
169, 170, 110, 170, 170, 107, 103, 102, 98, 96,

90, 85, 78, 75, 74, 72, 64, 49, 35, 33,
32, 31, 30, 26, 25, 24, 21, 17, 13, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
157, 157, 157
} ;

/* The intent behind this definition is that it'll catch
Expand Down Expand Up @@ -1131,13 +1131,13 @@ YY_DECL
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 >= 157 )
if ( yy_current_state >= 158 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 321 );
while ( yy_base[yy_current_state] != 320 );

yy_find_action:
yy_act = yy_accept[yy_current_state];
Expand Down Expand Up @@ -1747,7 +1747,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 >= 157 )
if ( yy_current_state >= 158 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
Expand Down Expand Up @@ -1776,11 +1776,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 >= 157 )
if ( yy_current_state >= 158 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 156);
yy_is_jam = (yy_current_state == 157);

(void)yyg;
return yy_is_jam ? 0 : yy_current_state;
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct lexer_param;
yylval->literal = jv_string_sized(yytext + 1, yyleng - 1); return FORMAT;
}

[0-9.]+([eE][+-]?[0-9]+)? {
([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)? {
yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ jq: error: Cannot use number (0) as object key at <top-level>, line 1:
{"foo": {"bar": 20}}
20

.e0, .E1, .E-1, .E+1
{"e0": 1, "E1": 2, "E": 3}
1
2
2
4

[.[]|.foo?]
[1,[2],{"foo":3,"bar":4},{},{"foo":5}]
[3,null,5]
Expand Down

0 comments on commit 596b591

Please sign in to comment.