Support single-quoted strings in dbStatic JSON5 values
Teach lexer to recognize them. Strip leading & trailing quotes from string values. Add some tests.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
newline "\n"
|
||||
backslash "\\"
|
||||
singlequote "'"
|
||||
doublequote "\""
|
||||
comment "#"
|
||||
whitespace [ \t\r\n]
|
||||
@@ -18,14 +19,17 @@ stringchar [^"\n\\]
|
||||
bareword [a-zA-Z0-9_\-+:.\[\]<>;]
|
||||
|
||||
punctuation [:,\[\]{}]
|
||||
normalchar [^"\\\0-\x1f]
|
||||
normalchar [^"'\\\0-\x1f]
|
||||
barechar [a-zA-Z0-9_\-+.]
|
||||
escapedchar ({backslash}[^ux1-9])
|
||||
hexdigit [0-9a-fA-F]
|
||||
latinchar ({backslash}"x"{hexdigit}{2})
|
||||
unicodechar ({backslash}"u"{hexdigit}{4})
|
||||
jsonchar ({normalchar}|{escapedchar}|{latinchar}|{unicodechar})
|
||||
jsondqstr ({doublequote}{jsonchar}*{doublequote})
|
||||
jsondqchar ({normalchar}|{singlequote}|{escapedchar}|{latinchar}|{unicodechar})
|
||||
jsondqstr ({doublequote}{jsondqchar}*{doublequote})
|
||||
jsonsqchar ({normalchar}|{doublequote}|{escapedchar}|{latinchar}|{unicodechar})
|
||||
jsonsqstr ({singlequote}{jsonsqchar}*{singlequote})
|
||||
jsonstr ({jsondqstr}|{jsonsqstr})
|
||||
|
||||
sign ([+-]?)
|
||||
int ({sign}([0-9]|[1-9][0-9]+))
|
||||
@@ -107,7 +111,7 @@ static int yyreset(void)
|
||||
|
||||
<JSON>{punctuation} return yytext[0];
|
||||
|
||||
<JSON>{jsondqstr} {
|
||||
<JSON>{jsonstr} {
|
||||
yylval.Str = dbmfStrdup((char *) yytext);
|
||||
return jsonSTRING;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1173,7 @@ static void dbRecordField(char *name,char *value)
|
||||
return;
|
||||
}
|
||||
|
||||
if (*value == '"') {
|
||||
if (*value == '"' || *value == '\'') {
|
||||
/* jsonSTRING values still have their quotes */
|
||||
value++;
|
||||
value[strlen(value) - 1] = 0;
|
||||
@@ -1206,7 +1206,7 @@ static void dbRecordInfo(char *name, char *value)
|
||||
ptempListNode = (tempListNode *)ellFirst(&tempList);
|
||||
pdbentry = ptempListNode->item;
|
||||
|
||||
if (*value == '"') {
|
||||
if (*value == '"' || *value == '\'') {
|
||||
/* jsonSTRING values still have their quotes */
|
||||
value++;
|
||||
value[strlen(value) - 1] = 0;
|
||||
|
||||
@@ -67,6 +67,7 @@ static const struct testParseDataT {
|
||||
{" #B111 C112 N113 @cparam", {CAMAC_IO, "cparam", 0, "BCN", {111, 112, 113}}},
|
||||
{" @hello world ", {INST_IO, "hello world", 0, "", /*{}*/}},
|
||||
{" {\"x\":true} ", {JSON_LINK, "{\"x\":true}", 0, "", /*{}*/}},
|
||||
{" {'x':true} ", {JSON_LINK, "{'x':true}", 0, "", /*{}*/}},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@@ -587,7 +588,9 @@ void testJLink(void)
|
||||
|
||||
testdbGetFieldEqual("j1.INP", DBF_STRING, "{z:{good:1}}");
|
||||
testdbGetFieldEqual("j1.VAL", DBF_LONG, 1);
|
||||
testdbGetFieldEqual("j2.INP", DBF_STRING, "{\"z\":{'good':2}}");
|
||||
testdbGetFieldEqual("j2.VAL", DBF_LONG, 2);
|
||||
testdbGetFieldEqual("j2.TSEL", DBF_STRING, "j1.TIME NPP NMS");
|
||||
testdbGetFieldEqual("j3.VAL", DBF_LONG, 3);
|
||||
|
||||
testNumZ(6);
|
||||
@@ -596,7 +599,7 @@ void testJLink(void)
|
||||
testdbPutFieldOk("j1.PROC", DBF_LONG, 1);
|
||||
testdbGetFieldEqual("j1.VAL", DBF_LONG, 4);
|
||||
|
||||
testdbPutFieldOk("j2.TSEL", DBF_STRING, "{\"z\":{\"good\":0}}");
|
||||
testdbPutFieldOk("j2.TSEL", DBF_STRING, "{'z':{good:0}}");
|
||||
testdbPutFieldOk("j2.PROC", DBF_LONG, 1);
|
||||
|
||||
testNumZ(7);
|
||||
@@ -611,8 +614,8 @@ void testJLink(void)
|
||||
testNumZ(7);
|
||||
|
||||
/* Check SDIS using a JSON link prevents processing */
|
||||
testdbPutFieldOk("j1.SDIS", DBF_STRING, "{\"z\":{\"good\":1}}");
|
||||
testdbPutFieldOk("j1.INP", DBF_STRING, "{\"z\":{\"good\":1}}");
|
||||
testdbPutFieldOk("j1.SDIS", DBF_STRING, "{z:{good:1}}");
|
||||
testdbPutFieldOk("j1.INP", DBF_STRING, "{z:{good:1}}");
|
||||
testdbPutFieldOk("j1.PROC", DBF_LONG, 1);
|
||||
testdbGetFieldEqual("j1.VAL", DBF_LONG, 4);
|
||||
|
||||
@@ -697,7 +700,7 @@ void testTSEL(void)
|
||||
|
||||
MAIN(dbPutLinkTest)
|
||||
{
|
||||
testPlan(337);
|
||||
testPlan(342);
|
||||
testLinkParse();
|
||||
testLinkFailParse();
|
||||
testCADBSet();
|
||||
|
||||
@@ -7,8 +7,8 @@ record(x, "j1") {
|
||||
}
|
||||
|
||||
record(x, "j2") {
|
||||
field(INP, {z:{good:2}})
|
||||
field(TSEL, "j1.TIME")
|
||||
field(INP, {"z":{'good':2}})
|
||||
field(TSEL, 'j1.TIME')
|
||||
}
|
||||
|
||||
record(x, "j3") {
|
||||
|
||||
Reference in New Issue
Block a user