|
25 | 25 |
|
26 | 26 | #include "src/core/json/lexer_impl.h"
|
27 | 27 | #include "src/core/json/driver.h"
|
| 28 | +#include <absl/strings/numbers.h> |
| 29 | +#include "base/logging.h" |
28 | 30 |
|
29 | 31 | #define yylex driver->lexer()->Lex
|
30 | 32 |
|
31 | 33 | using namespace std;
|
| 34 | + |
| 35 | +static int unsafe_stoi(std::string_view s) { |
| 36 | + int value; |
| 37 | + bool success = absl::SimpleAtoi(s, &value); |
| 38 | + DCHECK(success); |
| 39 | + return value; |
| 40 | +} |
32 | 41 | }
|
33 | 42 |
|
34 | 43 | %parse-param { Driver *driver }
|
@@ -56,7 +65,7 @@ using namespace std;
|
56 | 65 | // Needed 0 at the end to satisfy bison 3.5.1
|
57 | 66 | %token YYEOF 0
|
58 | 67 | %token <std::string> UNQ_STR "unquoted string"
|
59 |
| -%token <int> INT "integer" |
| 68 | +%token <std::string> INT "integer" |
60 | 69 |
|
61 | 70 | %nterm <std::string> identifier
|
62 | 71 | %nterm <PathSegment> bracket_index
|
@@ -84,23 +93,28 @@ relative_path: identifier { driver->AddIdentifier($1); } opt_relative_location
|
84 | 93 | | bracket_expr
|
85 | 94 |
|
86 | 95 | identifier: UNQ_STR
|
| 96 | + | INT |
87 | 97 |
|
88 | 98 | bracket_expr: LBRACKET bracket_index RBRACKET { driver->AddSegment($2); } opt_relative_location
|
89 | 99 |
|
90 | 100 | bracket_index: single_quoted_string { $$ = PathSegment(SegmentType::IDENTIFIER, $1); }
|
91 | 101 | | double_quoted_string { $$ = PathSegment(SegmentType::IDENTIFIER, $1); }
|
92 | 102 | | WILDCARD { $$ = PathSegment{SegmentType::INDEX, IndexExpr::All()}; }
|
93 |
| - | INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr($1, $1)); } |
94 |
| - | INT COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen($1, $3)); } |
95 |
| - | INT COLON { $$ = PathSegment(SegmentType::INDEX, IndexExpr($1, INT_MAX)); } |
96 |
| - | COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen(0, $2)); } |
| 103 | + | INT { int tmp_idx = unsafe_stoi($1); |
| 104 | + $$ = PathSegment(SegmentType::INDEX, IndexExpr(tmp_idx, tmp_idx)); } |
| 105 | + | INT COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen( |
| 106 | + unsafe_stoi($1), unsafe_stoi($3))); } |
| 107 | + | INT COLON { $$ = PathSegment(SegmentType::INDEX, IndexExpr(unsafe_stoi($1), INT_MAX)); } |
| 108 | + | COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen(0, unsafe_stoi($2))); } |
97 | 109 |
|
98 | 110 | single_quoted_string: SINGLE_QUOTE quoted_content SINGLE_QUOTE { $$ = $2; }
|
99 | 111 |
|
100 | 112 | double_quoted_string: DOUBLE_QUOTE quoted_content DOUBLE_QUOTE { $$ = $2; }
|
101 | 113 |
|
102 | 114 | quoted_content: UNQ_STR { $$ = $1; }
|
| 115 | + | INT { $$ = $1; } |
103 | 116 | | quoted_content DOT UNQ_STR { $$ = $1 + "." + $3; }
|
| 117 | + | quoted_content DOT INT { $$ = $1 + "." + $3; } |
104 | 118 |
|
105 | 119 | function_expr: UNQ_STR { driver->AddFunction($1); } LPARENT ROOT relative_location RPARENT
|
106 | 120 | %%
|
|
0 commit comments