Accept bareword JSON strings, quote them

This commit is contained in:
Andrew Johnson
2016-05-20 00:02:45 -05:00
parent 6e6ae4354b
commit 7ea544673a
2 changed files with 18 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ bareword [a-zA-Z0-9_\-+:.\[\]<>;]
punctuation [:,\[\]{}]
normalchar [^"\\\0-\x1f]
barechar [a-zA-Z0-9_\-+.]
escapedchar ({backslash}["\\/bfnrt])
hexdigit [0-9a-fA-F]
unicodechar ({backslash}"u"{hexdigit}{4})
@@ -102,6 +103,11 @@ static int yyreset(void)
return jsonSTRING;
}
<JSON>{barechar}+ {
yylval.Str = dbmfStrdup((char *) yytext);
return jsonBARE;
}
<JSON>{number} {
yylval.Str = dbmfStrdup((char *) yytext);
return jsonNUMBER;

View File

@@ -30,9 +30,9 @@ static int yyAbort = 0;
%token <Str> tokenSTRING tokenCDEFS
%token jsonNULL jsonTRUE jsonFALSE
%token <Str> jsonNUMBER jsonSTRING
%token <Str> jsonNUMBER jsonSTRING jsonBARE
%type <Str> json_value json_object json_array
%type <Str> json_members json_pair json_elements
%type <Str> json_members json_pair json_elements json_string
%%
@@ -296,13 +296,21 @@ json_members: json_pair
if (dbStaticDebug>2) printf("json %s\n", $$);
};
json_pair: jsonSTRING ':' json_value
json_pair: json_string ':' json_value
{
$$ = dbmfStrcat3($1, ":", $3);
dbmfFree($1); dbmfFree($3);
if (dbStaticDebug>2) printf("json %s\n", $$);
};
json_string: jsonSTRING
| jsonBARE
{
$$ = dbmfStrcat3("\"", $1, "\"");
dbmfFree($1);
if (dbStaticDebug>2) printf("json %s\n", $$);
};
json_array: '[' ']'
{
$$ = dbmfStrdup("[]");
@@ -327,7 +335,7 @@ json_value: jsonNULL { $$ = dbmfStrdup("null"); }
| jsonTRUE { $$ = dbmfStrdup("true"); }
| jsonFALSE { $$ = dbmfStrdup("false"); }
| jsonNUMBER
| jsonSTRING
| json_string
| json_array
| json_object ;