1
0
mirror of synced 2025-12-23 16:01:40 +08:00
Files
jsonlint-mod/src/jsonlint.y
2012-05-27 14:26:14 -07:00

79 lines
1.1 KiB
Plaintext

%start JSONText
/*
ECMA-262 5th Edition, 15.12.1 The JSON Grammar.
*/
%%
JSONString
: STRING
{$$ = yytext.replace(/\\\\/g, "\\");}
;
JSONNumber
: NUMBER
{$$ = Number(yytext);}
;
JSONNullLiteral
: NULL
{$$ = null;}
;
JSONBooleanLiteral
: TRUE
{$$ = true;}
| FALSE
{$$ = false;}
;
JSONText
: JSONValue EOF
{return $$ = $1;}
;
JSONValue
: JSONNullLiteral
| JSONBooleanLiteral
| JSONString
| JSONNumber
| JSONObject
| JSONArray
;
JSONObject
: '{' '}'
{{$$ = {};}}
| '{' JSONMemberList '}'
{$$ = $2;}
;
JSONMember
: JSONString ':' JSONValue
{$$ = [$1, $3];}
;
JSONMemberList
: JSONMember
{{$$ = {}; $$[$1[0]] = $1[1];}}
| JSONMemberList ',' JSONMember
{$$ = $1; $1[$3[0]] = $3[1];}
;
JSONArray
: '[' ']'
{$$ = [];}
| '[' JSONElementList ']'
{$$ = $2;}
;
JSONElementList
: JSONValue
{$$ = [$1];}
| JSONElementList ',' JSONValue
{$$ = $1; $1.push($3);}
;