summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f78d30d)
raw | patch | inline | side by side (parent: f78d30d)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 23 Aug 2014 04:39:22 +0000 (21:39 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 23 Aug 2014 04:39:22 +0000 (21:39 -0700) |
Just like in SQL, single quotes may be included in a string by specifying two
adjacent single quotes.
adjacent single quotes.
src/frontend/scanner.l | patch | blob | history | |
t/unit/frontend/parser_test.c | patch | blob | history |
diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index 5af85e047ec2913747f010638d884f9256cb1943..9d8e73d7d73cf01e8e80f552e8e90742cd345991 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
*/
identifier ([A-Za-z_][A-Za-z_0-9$]*)
/* TODO: fully support SQL strings */
-string ('[^']*')
+string ('([^']|'')*')
/*
* Numeric constants.
return IDENTIFIER;
}
{string} {
+ char *quot;
+ size_t len;
+
+ /* remove the leading and trailing quote */
yytext[yyleng - 1] = '\0';
yylval->str = strdup(yytext + 1);
+
+ quot = yylval->str;
+ len = yyleng - 2;
+ while ((quot = strstr(quot, "''")) != NULL) {
+ memmove(quot, quot + 1, len - (quot - yylval->str) - 1);
+ yylval->str[len - 1] = '\0';
+ --len;
+ ++quot;
+ }
return STRING;
}
{integer} {
index 9005811d500b68b6ce594fb7fcc861af2d85c449..bcd46af274c6bddd8a1d2bc6bbf8db27fcf9b2a0 100644 (file)
{ "TIMESERIES "
"'host'.'metric'", -1, 1, CONNECTION_TIMESERIES },
+ /* string constants */
+ { "LOOKUP hosts MATCHING "
+ "host = ''''", -1, 1, CONNECTION_LOOKUP },
+ { "LOOKUP hosts MATCHING "
+ "host = '''foo'", -1, 1, CONNECTION_LOOKUP },
+ { "LOOKUP hosts MATCHING "
+ "host = 'f''oo'", -1, 1, CONNECTION_LOOKUP },
+ { "LOOKUP hosts MATCHING "
+ "host = 'foo'''", -1, 1, CONNECTION_LOOKUP },
+ { "LOOKUP hosts MATCHING "
+ "host = '''", -1, -1, 0 },
+
/* numeric constants */
{ "LOOKUP hosts MATCHING "
"attribute.foo = "