Skip to content

Commit 3fd68fd

Browse files
committed
Clean up JSON parser
Don't use <value> type for JSON tokens that don't have a value and remove the errlex productions -- we're going to get an unexpected token error anyway, there's no need to handle these explicitly. This also removes the awkward workarounds for the unused value warnings.
1 parent 5bee9c9 commit 3fd68fd

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

ext/json/json_parser.y

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ int json_yydebug = 1;
3232
#define YYFREE free
3333
#endif
3434

35-
#define PHP_JSON_USE(uv) ((void) (uv))
36-
#define PHP_JSON_USE_1(uvr, uv1) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1)
37-
#define PHP_JSON_USE_2(uvr, uv1, uv2) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1); PHP_JSON_USE(uv2)
38-
3935
#define PHP_JSON_DEPTH_DEC --parser->depth
4036
#define PHP_JSON_DEPTH_INC \
4137
if (parser->max_depth && parser->depth >= parser->max_depth) { \
@@ -67,10 +63,10 @@ int json_yydebug = 1;
6763
%token <value> PHP_JSON_T_DOUBLE
6864
%token <value> PHP_JSON_T_STRING
6965
%token <value> PHP_JSON_T_ESTRING
70-
%token <value> PHP_JSON_T_EOI
71-
%token <value> PHP_JSON_T_ERROR
66+
%token PHP_JSON_T_EOI
67+
%token PHP_JSON_T_ERROR
7268

73-
%type <value> start object key value array errlex
69+
%type <value> start object key value array
7470
%type <value> members member elements element
7571
%type <pair> pair
7672

@@ -90,11 +86,7 @@ start:
9086
{
9187
ZVAL_COPY_VALUE(&$$, &$1);
9288
ZVAL_COPY_VALUE(parser->return_value, &$1);
93-
PHP_JSON_USE($2); YYACCEPT;
94-
}
95-
| value errlex
96-
{
97-
PHP_JSON_USE_2($$, $1, $2);
89+
YYACCEPT;
9890
}
9991
;
10092

@@ -148,10 +140,6 @@ member:
148140
}
149141
ZVAL_COPY_VALUE(&$$, &$1);
150142
}
151-
| member errlex
152-
{
153-
PHP_JSON_USE_2($$, $1, $2);
154-
}
155143
;
156144

157145
pair:
@@ -160,10 +148,6 @@ pair:
160148
$$.key = Z_STR($1);
161149
ZVAL_COPY_VALUE(&$$.val, &$3);
162150
}
163-
| key errlex
164-
{
165-
PHP_JSON_USE_2($$, $1, $2);
166-
}
167151
;
168152

169153
array:
@@ -212,10 +196,6 @@ element:
212196
parser->methods.array_append(parser, &$1, &$3);
213197
ZVAL_COPY_VALUE(&$$, &$1);
214198
}
215-
| element errlex
216-
{
217-
PHP_JSON_USE_2($$, $1, $2);
218-
}
219199
;
220200

221201
key:
@@ -233,15 +213,6 @@ value:
233213
| PHP_JSON_T_NUL
234214
| PHP_JSON_T_TRUE
235215
| PHP_JSON_T_FALSE
236-
| errlex
237-
;
238-
239-
errlex:
240-
PHP_JSON_T_ERROR
241-
{
242-
PHP_JSON_USE_1($$, $1);
243-
YYERROR;
244-
}
245216
;
246217

247218
%% /* Functions */

0 commit comments

Comments
 (0)