Code

frontend: Added support for single quotes in string constants.
[sysdb.git] / src / frontend / scanner.l
index 5af85e047ec2913747f010638d884f9256cb1943..9d8e73d7d73cf01e8e80f552e8e90742cd345991 100644 (file)
@@ -102,7 +102,7 @@ csc_end             \*\/
  */
 identifier     ([A-Za-z_][A-Za-z_0-9$]*)
 /* TODO: fully support SQL strings */
-string         ('[^']*')
+string         ('([^']|'')*')
 
 /*
  * Numeric constants.
@@ -146,8 +146,21 @@ time               ([0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,9})?)?)
                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} {