]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/jsonpath_scan.l
Fix initialization of fake LSN for unlogged relations
[postgresql] / src / backend / utils / adt / jsonpath_scan.l
index 12ef81b308326d9449bb363a646826a1cb3d3616..9650226f507cee86d49e3f843684a185a1c66845 100644 (file)
@@ -59,25 +59,24 @@ fprintf_to_ereport(const char *fmt, const char *msg)
 %option noyyfree
 
 /*
- * We use exclusive states for quoted, signle-quoted and non-quoted strings,
- * quoted variable names and C-tyle comments.
+ * We use exclusive states for quoted and non-quoted strings,
+ * quoted variable names and C-style comments.
  * Exclusive states:
  *  <xq> - quoted strings
  *  <xnq> - non-quoted strings
  *  <xvq> - quoted variable names
- *  <xsq> - single-quoted strings
  *  <xc> - C-style comment
  */
 
 %x xq
 %x xnq
 %x xvq
-%x xsq
 %x xc
 
-special                 [\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/]
-any                    [^\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/\\\"\' \t\n\r\f]
+special                [\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/]
 blank          [ \t\n\r\f]
+/* "other" means anything that's not special, blank, or '\' or '"' */
+other          [^\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/\\\" \t\n\r\f]
 
 digit          [0-9]
 integer                (0|[1-9]{digit}*)
@@ -95,7 +94,7 @@ hex_fail      \\x{hex_dig}{0,1}
 
 %%
 
-<xnq>{any}+                                            {
+<xnq>{other}+                                  {
                                                                        addstring(false, yytext, yyleng);
                                                                }
 
@@ -105,13 +104,12 @@ hex_fail  \\x{hex_dig}{0,1}
                                                                        return checkKeyword();
                                                                }
 
-
 <xnq>\/\*                                              {
                                                                        yylval->str = scanstring;
                                                                        BEGIN xc;
                                                                }
 
-<xnq>({special}|\"|\')                 {
+<xnq>({special}|\")                            {
                                                                        yylval->str = scanstring;
                                                                        yyless(0);
                                                                        BEGIN INITIAL;
@@ -124,39 +122,37 @@ hex_fail  \\x{hex_dig}{0,1}
                                                                        return checkKeyword();
                                                                }
 
-<xnq,xq,xvq,xsq>\\[\"\'\\]             { addchar(false, yytext[1]); }
-
-<xnq,xq,xvq,xsq>\\b                            { addchar(false, '\b'); }
+<xnq,xq,xvq>\\b                                { addchar(false, '\b'); }
 
-<xnq,xq,xvq,xsq>\\f                            { addchar(false, '\f'); }
+<xnq,xq,xvq>\\f                                { addchar(false, '\f'); }
 
-<xnq,xq,xvq,xsq>\\n                            { addchar(false, '\n'); }
+<xnq,xq,xvq>\\n                                { addchar(false, '\n'); }
 
-<xnq,xq,xvq,xsq>\\r                            { addchar(false, '\r'); }
+<xnq,xq,xvq>\\r                                { addchar(false, '\r'); }
 
-<xnq,xq,xvq,xsq>\\t                            { addchar(false, '\t'); }
+<xnq,xq,xvq>\\t                                { addchar(false, '\t'); }
 
-<xnq,xq,xvq,xsq>\\v                            { addchar(false, '\v'); }
+<xnq,xq,xvq>\\v                                { addchar(false, '\v'); }
 
-<xnq,xq,xvq,xsq>{unicode}+             { parseUnicode(yytext, yyleng); }
+<xnq,xq,xvq>{unicode}+         { parseUnicode(yytext, yyleng); }
 
-<xnq,xq,xvq,xsq>{hex_char}             { parseHexChar(yytext); }
+<xnq,xq,xvq>{hex_char}         { parseHexChar(yytext); }
 
-<xnq,xq,xvq,xsq>{unicode}*{unicodefail}        { yyerror(NULL, "Unicode sequence is invalid"); }
+<xnq,xq,xvq>{unicode}*{unicodefail}    { yyerror(NULL, "invalid unicode sequence"); }
 
-<xnq,xq,xvq,xsq>{hex_fail}             { yyerror(NULL, "Hex character sequence is invalid"); }
+<xnq,xq,xvq>{hex_fail}         { yyerror(NULL, "invalid hex character sequence"); }
 
-<xnq,xq,xvq,xsq>{unicode}+\\   {
-                                                                       /* throw back the \\, and treat as unicode */
-                                                                       yyless(yyleng - 1);
-                                                                       parseUnicode(yytext, yyleng);
-                                                               }
+<xnq,xq,xvq>{unicode}+\\       {
+                                                               /* throw back the \\, and treat as unicode */
+                                                               yyless(yyleng - 1);
+                                                               parseUnicode(yytext, yyleng);
+                                                       }
 
-<xnq,xq,xvq,xsq>\\.                            { yyerror(NULL, "Escape sequence is invalid"); }
+<xnq,xq,xvq>\\.                                { addchar(false, yytext[1]); }
 
-<xnq,xq,xvq,xsq>\\                             { yyerror(NULL, "Unexpected end after backslash"); }
+<xnq,xq,xvq>\\                         { yyerror(NULL, "unexpected end after backslash"); }
 
-<xq,xvq,xsq><<EOF>>                            { yyerror(NULL, "Unexpected end of quoted string"); }
+<xq,xvq><<EOF>>                                { yyerror(NULL, "unexpected end of quoted string"); }
 
 <xq>\"                                                 {
                                                                        yylval->str = scanstring;
@@ -170,23 +166,15 @@ hex_fail  \\x{hex_dig}{0,1}
                                                                        return VARIABLE_P;
                                                                }
 
-<xsq>\'                                                        {
-                                                                       yylval->str = scanstring;
-                                                                       BEGIN INITIAL;
-                                                                       return STRING_P;
-                                                               }
-
 <xq,xvq>[^\\\"]+                               { addstring(false, yytext, yyleng); }
 
-<xsq>[^\\\']+                                  { addstring(false, yytext, yyleng); }
-
 <xc>\*\/                                               { BEGIN INITIAL; }
 
 <xc>[^\*]+                                             { }
 
 <xc>\*                                                 { }
 
-<xc><<EOF>>                                            { yyerror(NULL, "Unexpected end of comment"); }
+<xc><<EOF>>                                            { yyerror(NULL, "unexpected end of comment"); }
 
 \&\&                                                   { return AND_P; }
 
@@ -210,7 +198,7 @@ hex_fail    \\x{hex_dig}{0,1}
 
 \>                                                             { return GREATER_P; }
 
-\${any}+                                               {
+\${other}+                                             {
                                                                        addstring(true, yytext + 1, yyleng - 1);
                                                                        addchar(false, '\0');
                                                                        yylval->str = scanstring;
@@ -261,29 +249,24 @@ hex_fail  \\x{hex_dig}{0,1}
                                                                        return INT_P;
                                                                }
 
-({realfail1}|{realfail2})              { yyerror(NULL, "Floating point number is invalid"); }
-
-{any}+                                                 {
-                                                                       addstring(true, yytext, yyleng);
-                                                                       BEGIN xnq;
-                                                               }
+({realfail1}|{realfail2})              { yyerror(NULL, "invalid floating point number"); }
 
 \"                                                             {
                                                                        addchar(true, '\0');
                                                                        BEGIN xq;
                                                                }
 
-\'                                                             {
-                                                                       addchar(true, '\0');
-                                                                       BEGIN xsq;
-                                                               }
-
 \\                                                             {
                                                                        yyless(0);
                                                                        addchar(true, '\0');
                                                                        BEGIN xnq;
                                                                }
 
+{other}+                                               {
+                                                                       addstring(true, yytext, yyleng);
+                                                                       BEGIN xnq;
+                                                               }
+
 <<EOF>>                                                        { yyterminate(); }
 
 %%
@@ -295,17 +278,16 @@ jsonpath_yyerror(JsonPathParseResult **result, const char *message)
        {
                ereport(ERROR,
                                (errcode(ERRCODE_SYNTAX_ERROR),
-                                errmsg("bad jsonpath representation"),
                                 /* translator: %s is typically "syntax error" */
-                                errdetail("%s at end of input", message)));
+                                errmsg("%s at end of jsonpath input", _(message))));
        }
        else
        {
                ereport(ERROR,
                                (errcode(ERRCODE_SYNTAX_ERROR),
-                                errmsg("bad jsonpath representation"),
                                 /* translator: first %s is typically "syntax error" */
-                                errdetail("%s at or near \"%s\"", message, yytext)));
+                                errmsg("%s at or near \"%s\" of jsonpath input",
+                                               _(message), yytext)));
        }
 }
 
@@ -341,6 +323,7 @@ static const JsonPathKeyword keywords[] = {
        { 6, false,     STRICT_P,       "strict"},
        { 7, false,     CEILING_P,      "ceiling"},
        { 7, false,     UNKNOWN_P,      "unknown"},
+       { 8, false,     DATETIME_P,     "datetime"},
        { 8, false,     KEYVALUE_P,     "keyvalue"},
        { 10,false, LIKE_REGEX_P, "like_regex"},
 };
@@ -478,7 +461,7 @@ parsejsonpath(const char *str, int len)
        jsonpath_scanner_init(str, len);
 
        if (jsonpath_yyparse((void *) &parseresult) != 0)
-               jsonpath_yyerror(NULL, "bugus input");
+               jsonpath_yyerror(NULL, "bogus input"); /* shouldn't happen */
 
        jsonpath_scanner_finish();
 
@@ -495,7 +478,7 @@ hexval(char c)
                return c - 'a' + 0xA;
        if (c >= 'A' && c <= 'F')
                return c - 'A' + 0xA;
-       elog(ERROR, "invalid hexadecimal digit");
+       jsonpath_yyerror(NULL, "invalid hexadecimal digit");
        return 0; /* not reached */
 }
 
@@ -540,7 +523,7 @@ addUnicodeChar(int ch)
        {
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                errmsg("invalid input syntax for type jsonpath"),
+                                errmsg("invalid input syntax for type %s", "jsonpath"),
                                 errdetail("Unicode escape values cannot be used for code "
                                                   "point values above 007F when the server encoding "
                                                   "is not UTF8.")));
@@ -556,7 +539,7 @@ addUnicode(int ch, int *hi_surrogate)
                if (*hi_surrogate != -1)
                        ereport(ERROR,
                                        (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                        errmsg("invalid input syntax for type jsonpath"),
+                                        errmsg("invalid input syntax for type %s", "jsonpath"),
                                         errdetail("Unicode high surrogate must not follow "
                                                           "a high surrogate.")));
                *hi_surrogate = (ch & 0x3ff) << 10;
@@ -567,7 +550,7 @@ addUnicode(int ch, int *hi_surrogate)
                if (*hi_surrogate == -1)
                        ereport(ERROR,
                                        (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                        errmsg("invalid input syntax for type jsonpath"),
+                                        errmsg("invalid input syntax for type %s", "jsonpath"),
                                         errdetail("Unicode low surrogate must follow a high "
                                                           "surrogate.")));
                ch = 0x10000 + *hi_surrogate + (ch & 0x3ff);
@@ -577,7 +560,7 @@ addUnicode(int ch, int *hi_surrogate)
        {
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                errmsg("invalid input syntax for type jsonpath"),
+                                errmsg("invalid input syntax for type %s", "jsonpath"),
                                 errdetail("Unicode low surrogate must follow a high "
                                                   "surrogate.")));
        }
@@ -604,7 +587,7 @@ parseUnicode(char *s, int l)
                {
                        while (s[++i] != '}' && i < l)
                                ch = (ch << 4) | hexval(s[i]);
-                       i++;    /* ski p '}' */
+                       i++;    /* skip '}' */
                }
                else            /* parse '\uXXXX' */
                {
@@ -619,7 +602,7 @@ parseUnicode(char *s, int l)
        {
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                errmsg("invalid input syntax for type jsonpath"),
+                                errmsg("invalid input syntax for type %s", "jsonpath"),
                                 errdetail("Unicode low surrogate must follow a high "
                                                   "surrogate.")));
        }