25#include "jsonpath_gram.h"
46#define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
int errmsg_internal(const char *fmt,...)
#define ereport(elevel,...)
static bool parseHexChar(char *s, struct Node *escontext, yyscan_t yyscanner)
static bool parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)
static void addchar(bool init, char c, yyscan_t yyscanner)
static void fprintf_to_ereport(const char *fmt, const char *msg)
static enum yytokentype checkKeyword(yyscan_t yyscanner)
static void addstring(bool init, char *s, int l, yyscan_t yyscanner)
static void const char * fmt
59%option never-interactive
65%option prefix="jsonpath_yy"
66%option extra-type="struct jsonpath_yy_extra_type *"
88special [\?\%\$\.\[\]\{\}\(\)\|\&\!\=<>\@\#\,\*:\-\+\/]
91other [^\?\%\$\.\[\]\{\}\(\)\|\&\!\=<>\@\#\,\*:\-\+\/\\\" \t\n\r\f]
99decinteger (0|[1-9](_?{decdigit})*)
101decdigits {decdigit}(_?{decdigit})*
103hexinteger 0[xX]{hexdigit}(_?{hexdigit})*
104octinteger 0[oO]{octdigit}(_?{octdigit})*
105bininteger 0[bB]{bindigit}(_?{bindigit})*
107decimal ({decinteger}\.{decdigits}?|\.{decdigits})
108real ({decinteger}|{decimal})[Ee][-+]?{decdigits}
109realfail ({decinteger}|{decimal})[Ee][-+]
111decinteger_junk {decinteger}{other}
112decimal_junk {decimal}{other}
113real_junk {real}{other}
115unicode \\u({hexdigit}{4}|\{{hexdigit}{1,6}\})
116unicodefail \\u({hexdigit}{0,3}|\{{hexdigit}{0,6})
117hex_char \\x{hexdigit}{2}
118hex_fail \\x{hexdigit}{0,1}
127 yylval->str =
yyextra->scanstring;
133 yylval->str =
yyextra->scanstring;
138 yylval->str =
yyextra->scanstring;
145 yylval->str =
yyextra->scanstring;
150<xnq,xq,xvq>\\b {
addchar(
false,
'\b', yyscanner); }
152<xnq,xq,xvq>\\f {
addchar(
false,
'\f', yyscanner); }
154<xnq,xq,xvq>\\n {
addchar(
false,
'\n', yyscanner); }
156<xnq,xq,xvq>\\r {
addchar(
false,
'\r', yyscanner); }
158<xnq,xq,xvq>\\t {
addchar(
false,
'\t', yyscanner); }
160<xnq,xq,xvq>\\v {
addchar(
false,
'\v', yyscanner); }
162<xnq,xq,xvq>{unicode}+ {
167<xnq,xq,xvq>{hex_char} {
172<xnq,xq,xvq>{unicode}*{unicodefail} {
174 "invalid Unicode escape sequence");
void jsonpath_yyerror(JsonPathParseResult **result, struct Node *escontext, yyscan_t yyscanner, const char *message)
178<xnq,xq,xvq>{hex_fail} {
180 "invalid hexadecimal character sequence");
184<xnq,xq,xvq>{unicode}+\\ {
191<xnq,xq,xvq>\\. {
addchar(
false, yytext[1], yyscanner); }
195 "unexpected end after backslash");
201 "unterminated quoted string");
206 yylval->str =
yyextra->scanstring;
212 yylval->str =
yyextra->scanstring;
219<xc>\*\/ { BEGIN INITIAL; }
227 "unexpected end of comment");
230\&\& {
return AND_P; }
236\*\* {
return ANY_P; }
240<\= {
return LESSEQUAL_P; }
242\=\= {
return EQUAL_P; }
244<> {
return NOTEQUAL_P; }
246\!\= {
return NOTEQUAL_P; }
248>\= {
return GREATEREQUAL_P; }
250> {
return GREATER_P; }
254 addchar(
false,
'\0', yyscanner);
255 yylval->str =
yyextra->scanstring;
260 addchar(
true,
'\0', yyscanner);
264{special} {
return *yytext; }
269 addchar(
true,
'\0', yyscanner);
275 addchar(
false,
'\0', yyscanner);
276 yylval->str =
yyextra->scanstring;
282 addchar(
false,
'\0', yyscanner);
283 yylval->str =
yyextra->scanstring;
289 addchar(
false,
'\0', yyscanner);
290 yylval->str =
yyextra->scanstring;
296 addchar(
false,
'\0', yyscanner);
297 yylval->str =
yyextra->scanstring;
303 addchar(
false,
'\0', yyscanner);
304 yylval->str =
yyextra->scanstring;
310 addchar(
false,
'\0', yyscanner);
311 yylval->str =
yyextra->scanstring;
317 "invalid numeric literal");
322 "trailing junk after numeric literal");
327 "trailing junk after numeric literal");
332 "trailing junk after numeric literal");
336 addchar(
true,
'\0', yyscanner);
342 addchar(
true,
'\0', yyscanner);
351<<EOF>> { yyterminate(); }
359#define yyextra (((struct yyguts_t *) yyscanner)->yyextra_r)
373 if (*yytext == YY_END_OF_BUFFER_CHAR)
376 (
errcode(ERRCODE_SYNTAX_ERROR),
378 errmsg(
"%s at end of jsonpath input",
_(message))));
383 (
errcode(ERRCODE_SYNTAX_ERROR),
385 errmsg(
"%s at or near \"%s\" of jsonpath input",
386 _(message), yytext)));
403 {2,
false, IS_P,
"is"},
404 {2,
false, TO_P,
"to"},
405 {3,
false, ABS_P,
"abs"},
406 {3,
false, LAX_P,
"lax"},
407 {4,
false, DATE_P,
"date"},
408 {4,
false, FLAG_P,
"flag"},
409 {4,
false, LAST_P,
"last"},
410 {4,
true, NULL_P,
"null"},
411 {4,
false, SIZE_P,
"size"},
412 {4,
false, TIME_P,
"time"},
413 {4,
true, TRUE_P,
"true"},
414 {4,
false, TYPE_P,
"type"},
415 {4,
false, WITH_P,
"with"},
416 {5,
true, FALSE_P,
"false"},
417 {5,
false, FLOOR_P,
"floor"},
418 {6,
false, BIGINT_P,
"bigint"},
419 {6,
false, DOUBLE_P,
"double"},
420 {6,
false, EXISTS_P,
"exists"},
421 {6,
false, NUMBER_P,
"number"},
422 {6,
false, STARTS_P,
"starts"},
423 {6,
false, STRICT_P,
"strict"},
424 {6,
false, STRINGFUNC_P,
"string"},
425 {7,
false, BOOLEAN_P,
"boolean"},
426 {7,
false, CEILING_P,
"ceiling"},
427 {7,
false, DECIMAL_P,
"decimal"},
428 {7,
false, INTEGER_P,
"integer"},
429 {7,
false, TIME_TZ_P,
"time_tz"},
430 {7,
false, UNKNOWN_P,
"unknown"},
431 {8,
false, DATETIME_P,
"datetime"},
432 {8,
false, KEYVALUE_P,
"keyvalue"},
433 {9,
false, TIMESTAMP_P,
"timestamp"},
434 {10,
false, LIKE_REGEX_P,
"like_regex"},
435 {12,
false, TIMESTAMP_TZ_P,
"timestamp_tz"},
441static enum yytokentype
453 while (StopLow < StopHigh)
455 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
457 if (StopMiddle->len ==
yyextra->scanstring.len)
461 diff = StopMiddle->len -
yyextra->scanstring.len;
464 StopLow = StopMiddle + 1;
466 StopHigh = StopMiddle;
469 if (StopMiddle->lowercase)
470 diff = strncmp(StopMiddle->keyword,
yyextra->scanstring.val,
474 res = StopMiddle->val;
492 yyextra->scanstring.total =
Max(32, appendLen);
498 if (
yyextra->scanstring.len + appendLen >=
yyextra->scanstring.total)
500 while (
yyextra->scanstring.len + appendLen >=
yyextra->scanstring.total)
501 yyextra->scanstring.total *= 2;
534 if (jsonpath_yylex_init(&scanner) != 0)
537 yyset_extra(&yyext, scanner);
542 jsonpath_yy_scan_bytes(
str,
len, scanner);
547 jsonpath_yylex_destroy(scanner);
556 if (
c >=
'0' &&
c <=
'9')
561 if (
c >=
'a' &&
c <=
'f')
563 *result =
c -
'a' + 0xA;
566 if (
c >=
'A' &&
c <=
'F')
568 *result =
c -
'A' + 0xA;
583 (
errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
584 errmsg(
"unsupported Unicode escape sequence"),
585 errdetail(
"\\u0000 cannot be converted to text.")));
601 (
errcode(ERRCODE_SYNTAX_ERROR),
602 errmsg(
"could not convert Unicode to server encoding")));
603 addstring(
false, cbuf, strlen(cbuf), yyscanner);
614 if (*hi_surrogate != -1)
616 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
617 errmsg(
"invalid input syntax for type %s",
"jsonpath"),
618 errdetail(
"Unicode high surrogate must not follow "
619 "a high surrogate.")));
625 if (*hi_surrogate == -1)
627 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
628 errmsg(
"invalid input syntax for type %s",
"jsonpath"),
629 errdetail(
"Unicode low surrogate must follow a high "
634 else if (*hi_surrogate != -1)
637 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
638 errmsg(
"invalid input syntax for type %s",
"jsonpath"),
639 errdetail(
"Unicode low surrogate must follow a high "
654 int hi_surrogate = -1;
656 for (
i = 2;
i < l;
i += 2)
664 while (s[++
i] !=
'}' &&
i < l)
666 if (!
hexval(s[
i], &si, escontext, yyscanner))
674 for (
j = 0;
j < 4 &&
i < l;
j++)
676 if (!
hexval(s[
i++], &si, escontext, yyscanner))
682 if (!
addUnicode(ch, &hi_surrogate, escontext, yyscanner))
686 if (hi_surrogate != -1)
689 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
690 errmsg(
"invalid input syntax for type %s",
"jsonpath"),
691 errdetail(
"Unicode low surrogate must follow a high "
706 if (!
hexval(s[2], &
s2, escontext, yyscanner))
708 if (!
hexval(s[3], &
s3, escontext, yyscanner))
static void PGresult * res
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
int jsonpath_yyparse(JsonPathParseResult **result, struct Node *escontext, yyscan_t yyscanner)
static void resizeString(bool init, int appendLen, yyscan_t yyscanner)
struct JsonPathKeyword JsonPathKeyword
void jsonpath_yyfree(void *ptr, yyscan_t yyscanner)
void * jsonpath_yyrealloc(void *ptr, yy_size_t bytes, yyscan_t yyscanner)
JsonPathParseResult * parsejsonpath(const char *str, int len, struct Node *escontext)
static bool addUnicode(int ch, int *hi_surrogate, struct Node *escontext, yyscan_t yyscanner)
static const JsonPathKeyword keywords[]
void * jsonpath_yyalloc(yy_size_t bytes, yyscan_t yyscanner)
static bool hexval(char c, int *result, struct Node *escontext, yyscan_t yyscanner)
static bool addUnicodeChar(int ch, struct Node *escontext, yyscan_t yyscanner)
bool pg_unicode_to_server_noerror(pg_wchar c, unsigned char *s)
void pg_unicode_to_server(pg_wchar c, unsigned char *s)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
#define SOFT_ERROR_OCCURRED(escontext)
#define IsA(nodeptr, _type_)
#define MAX_UNICODE_EQUIVALENT_STRING
static pg_wchar surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second)
static bool is_utf16_surrogate_first(pg_wchar c)
static bool is_utf16_surrogate_second(pg_wchar c)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)