1 /* A Bison parser, made by GNU Bison 3.3.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* All symbols defined below should begin with yy or YY, to avoid
38 infringing on user name space. This should be done even for local
39 variables, as they might otherwise be expanded by user macros.
40 There are some unavoidable exceptions within include files to
41 define necessary library symbols; they are noted "INFRINGES ON
42 USER NAME SPACE" below. */
43
44 /* Undocumented macros, especially those whose name start with YY_,
45 are private implementation details. Do not rely on them. */
46
47 /* Identify Bison output. */
48 #define YYBISON 1
49
50 /* Bison version. */
51 #define YYBISON_VERSION "3.3.2"
52
53 /* Skeleton name. */
54 #define YYSKELETON_NAME "yacc.c"
55
56 /* Pure parsers. */
57 #define YYPURE 1
58
59 /* Push parsers. */
60 #define YYPUSH 0
61
62 /* Pull parsers. */
63 #define YYPULL 1
64
65
66 /* Substitute the variable and function names. */
67 #define yyparse jsonpath_yyparse
68 #define yylex jsonpath_yylex
69 #define yyerror jsonpath_yyerror
70 #define yydebug jsonpath_yydebug
71 #define yynerrs jsonpath_yynerrs
72
73
74 /* First part of user prologue. */
75 #line 1 "jsonpath_gram.y" /* yacc.c:337 */
76
77 /*-------------------------------------------------------------------------
78 *
79 * jsonpath_gram.y
80 * Grammar definitions for jsonpath datatype
81 *
82 * Transforms tokenized jsonpath into tree of JsonPathParseItem structs.
83 *
84 * Copyright (c) 2019-2020, PostgreSQL Global Development Group
85 *
86 * IDENTIFICATION
87 * src/backend/utils/adt/jsonpath_gram.y
88 *
89 *-------------------------------------------------------------------------
90 */
91
92 #include "postgres.h"
93
94 #include "catalog/pg_collation.h"
95 #include "fmgr.h"
96 #include "miscadmin.h"
97 #include "nodes/pg_list.h"
98 #include "regex/regex.h"
99 #include "utils/builtins.h"
100 #include "utils/jsonpath.h"
101
102 /* struct JsonPathString is shared between scan and gram */
103 typedef struct JsonPathString
104 {
105 char *val;
106 int len;
107 int total;
108 } JsonPathString;
109
110 union YYSTYPE;
111
112 /* flex 2.5.4 doesn't bother with a decl for this */
113 int jsonpath_yylex(union YYSTYPE *yylval_param);
114 int jsonpath_yyparse(JsonPathParseResult **result);
115 void jsonpath_yyerror(JsonPathParseResult **result, const char *message);
116
117 static JsonPathParseItem *makeItemType(JsonPathItemType type);
118 static JsonPathParseItem *makeItemString(JsonPathString *s);
119 static JsonPathParseItem *makeItemVariable(JsonPathString *s);
120 static JsonPathParseItem *makeItemKey(JsonPathString *s);
121 static JsonPathParseItem *makeItemNumeric(JsonPathString *s);
122 static JsonPathParseItem *makeItemBool(bool val);
123 static JsonPathParseItem *makeItemBinary(JsonPathItemType type,
124 JsonPathParseItem *la,
125 JsonPathParseItem *ra);
126 static JsonPathParseItem *makeItemUnary(JsonPathItemType type,
127 JsonPathParseItem *a);
128 static JsonPathParseItem *makeItemList(List *list);
129 static JsonPathParseItem *makeIndexArray(List *list);
130 static JsonPathParseItem *makeAny(int first, int last);
131 static JsonPathParseItem *makeItemLikeRegex(JsonPathParseItem *expr,
132 JsonPathString *pattern,
133 JsonPathString *flags);
134
135 /*
136 * Bison doesn't allocate anything that needs to live across parser calls,
137 * so we can easily have it use palloc instead of malloc. This prevents
138 * memory leaks if we error out during parsing. Note this only works with
139 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
140 * if possible, so there's not really much problem anyhow, at least if
141 * you're building with gcc.
142 */
143 #define YYMALLOC palloc
144 #define YYFREE pfree
145
146
147 #line 148 "jsonpath_gram.c" /* yacc.c:337 */
148 # ifndef YY_NULLPTR
149 # if defined __cplusplus
150 # if 201103L <= __cplusplus
151 # define YY_NULLPTR nullptr
152 # else
153 # define YY_NULLPTR 0
154 # endif
155 # else
156 # define YY_NULLPTR ((void*)0)
157 # endif
158 # endif
159
160 /* Enabling verbose error messages. */
161 #ifdef YYERROR_VERBOSE
162 # undef YYERROR_VERBOSE
163 # define YYERROR_VERBOSE 1
164 #else
165 # define YYERROR_VERBOSE 1
166 #endif
167
168
169 /* Debug traces. */
170 #ifndef YYDEBUG
171 # define YYDEBUG 0
172 #endif
173 #if YYDEBUG
174 extern int jsonpath_yydebug;
175 #endif
176
177 /* Token type. */
178 #ifndef YYTOKENTYPE
179 # define YYTOKENTYPE
180 enum yytokentype
181 {
182 TO_P = 258,
183 NULL_P = 259,
184 TRUE_P = 260,
185 FALSE_P = 261,
186 IS_P = 262,
187 UNKNOWN_P = 263,
188 EXISTS_P = 264,
189 IDENT_P = 265,
190 STRING_P = 266,
191 NUMERIC_P = 267,
192 INT_P = 268,
193 VARIABLE_P = 269,
194 OR_P = 270,
195 AND_P = 271,
196 NOT_P = 272,
197 LESS_P = 273,
198 LESSEQUAL_P = 274,
199 EQUAL_P = 275,
200 NOTEQUAL_P = 276,
201 GREATEREQUAL_P = 277,
202 GREATER_P = 278,
203 ANY_P = 279,
204 STRICT_P = 280,
205 LAX_P = 281,
206 LAST_P = 282,
207 STARTS_P = 283,
208 WITH_P = 284,
209 LIKE_REGEX_P = 285,
210 FLAG_P = 286,
211 ABS_P = 287,
212 SIZE_P = 288,
213 TYPE_P = 289,
214 FLOOR_P = 290,
215 DOUBLE_P = 291,
216 CEILING_P = 292,
217 KEYVALUE_P = 293,
218 DATETIME_P = 294,
219 UMINUS = 295
220 };
221 #endif
222
223 /* Value type. */
224 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
225
226 union YYSTYPE
227 {
228 #line 80 "jsonpath_gram.y" /* yacc.c:352 */
229
230 JsonPathString str;
231 List *elems; /* list of JsonPathParseItem */
232 List *indexs; /* list of integers */
233 JsonPathParseItem *value;
234 JsonPathParseResult *result;
235 JsonPathItemType optype;
236 bool boolean;
237 int integer;
238
239 #line 240 "jsonpath_gram.c" /* yacc.c:352 */
240 };
241
242 typedef union YYSTYPE YYSTYPE;
243 # define YYSTYPE_IS_TRIVIAL 1
244 # define YYSTYPE_IS_DECLARED 1
245 #endif
246
247
248
249 int jsonpath_yyparse (JsonPathParseResult **result);
250
251
252
253
254
255 #ifdef short
256 # undef short
257 #endif
258
259 #ifdef YYTYPE_UINT8
260 typedef YYTYPE_UINT8 yytype_uint8;
261 #else
262 typedef unsigned char yytype_uint8;
263 #endif
264
265 #ifdef YYTYPE_INT8
266 typedef YYTYPE_INT8 yytype_int8;
267 #else
268 typedef signed char yytype_int8;
269 #endif
270
271 #ifdef YYTYPE_UINT16
272 typedef YYTYPE_UINT16 yytype_uint16;
273 #else
274 typedef unsigned short yytype_uint16;
275 #endif
276
277 #ifdef YYTYPE_INT16
278 typedef YYTYPE_INT16 yytype_int16;
279 #else
280 typedef short yytype_int16;
281 #endif
282
283 #ifndef YYSIZE_T
284 # ifdef __SIZE_TYPE__
285 # define YYSIZE_T __SIZE_TYPE__
286 # elif defined size_t
287 # define YYSIZE_T size_t
288 # elif ! defined YYSIZE_T
289 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
290 # define YYSIZE_T size_t
291 # else
292 # define YYSIZE_T unsigned
293 # endif
294 #endif
295
296 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
297
298 #ifndef YY_
299 # if defined YYENABLE_NLS && YYENABLE_NLS
300 # if ENABLE_NLS
301 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
302 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
303 # endif
304 # endif
305 # ifndef YY_
306 # define YY_(Msgid) Msgid
307 # endif
308 #endif
309
310 #ifndef YY_ATTRIBUTE
311 # if (defined __GNUC__ \
312 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
313 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
314 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
315 # else
316 # define YY_ATTRIBUTE(Spec) /* empty */
317 # endif
318 #endif
319
320 #ifndef YY_ATTRIBUTE_PURE
321 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
322 #endif
323
324 #ifndef YY_ATTRIBUTE_UNUSED
325 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
326 #endif
327
328 /* Suppress unused-variable warnings by "using" E. */
329 #if ! defined lint || defined __GNUC__
330 # define YYUSE(E) ((void) (E))
331 #else
332 # define YYUSE(E) /* empty */
333 #endif
334
335 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
336 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
337 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
338 _Pragma ("GCC diagnostic push") \
339 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
340 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
341 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
342 _Pragma ("GCC diagnostic pop")
343 #else
344 # define YY_INITIAL_VALUE(Value) Value
345 #endif
346 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
347 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
348 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
349 #endif
350 #ifndef YY_INITIAL_VALUE
351 # define YY_INITIAL_VALUE(Value) /* Nothing. */
352 #endif
353
354
355 #if ! defined yyoverflow || YYERROR_VERBOSE
356
357 /* The parser invokes alloca or malloc; define the necessary symbols. */
358
359 # ifdef YYSTACK_USE_ALLOCA
360 # if YYSTACK_USE_ALLOCA
361 # ifdef __GNUC__
362 # define YYSTACK_ALLOC __builtin_alloca
363 # elif defined __BUILTIN_VA_ARG_INCR
364 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
365 # elif defined _AIX
366 # define YYSTACK_ALLOC __alloca
367 # elif defined _MSC_VER
368 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
369 # define alloca _alloca
370 # else
371 # define YYSTACK_ALLOC alloca
372 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
373 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
374 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
375 # ifndef EXIT_SUCCESS
376 # define EXIT_SUCCESS 0
377 # endif
378 # endif
379 # endif
380 # endif
381 # endif
382
383 # ifdef YYSTACK_ALLOC
384 /* Pacify GCC's 'empty if-body' warning. */
385 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
386 # ifndef YYSTACK_ALLOC_MAXIMUM
387 /* The OS might guarantee only one guard page at the bottom of the stack,
388 and a page size can be as small as 4096 bytes. So we cannot safely
389 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
390 to allow for a few compiler-allocated temporary stack slots. */
391 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
392 # endif
393 # else
394 # define YYSTACK_ALLOC YYMALLOC
395 # define YYSTACK_FREE YYFREE
396 # ifndef YYSTACK_ALLOC_MAXIMUM
397 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
398 # endif
399 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
400 && ! ((defined YYMALLOC || defined malloc) \
401 && (defined YYFREE || defined free)))
402 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
403 # ifndef EXIT_SUCCESS
404 # define EXIT_SUCCESS 0
405 # endif
406 # endif
407 # ifndef YYMALLOC
408 # define YYMALLOC malloc
409 # if ! defined malloc && ! defined EXIT_SUCCESS
410 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
411 # endif
412 # endif
413 # ifndef YYFREE
414 # define YYFREE free
415 # if ! defined free && ! defined EXIT_SUCCESS
416 void free (void *); /* INFRINGES ON USER NAME SPACE */
417 # endif
418 # endif
419 # endif
420 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
421
422
423 #if (! defined yyoverflow \
424 && (! defined __cplusplus \
425 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
426
427 /* A type that is properly aligned for any stack member. */
428 union yyalloc
429 {
430 yytype_int16 yyss_alloc;
431 YYSTYPE yyvs_alloc;
432 };
433
434 /* The size of the maximum gap between one aligned stack and the next. */
435 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
436
437 /* The size of an array large to enough to hold all stacks, each with
438 N elements. */
439 # define YYSTACK_BYTES(N) \
440 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
441 + YYSTACK_GAP_MAXIMUM)
442
443 # define YYCOPY_NEEDED 1
444
445 /* Relocate STACK from its old location to the new one. The
446 local variables YYSIZE and YYSTACKSIZE give the old and new number of
447 elements in the stack, and YYPTR gives the new location of the
448 stack. Advance YYPTR to a properly aligned location for the next
449 stack. */
450 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
451 do \
452 { \
453 YYSIZE_T yynewbytes; \
454 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
455 Stack = &yyptr->Stack_alloc; \
456 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
457 yyptr += yynewbytes / sizeof (*yyptr); \
458 } \
459 while (0)
460
461 #endif
462
463 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
464 /* Copy COUNT objects from SRC to DST. The source and destination do
465 not overlap. */
466 # ifndef YYCOPY
467 # if defined __GNUC__ && 1 < __GNUC__
468 # define YYCOPY(Dst, Src, Count) \
469 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
470 # else
471 # define YYCOPY(Dst, Src, Count) \
472 do \
473 { \
474 YYSIZE_T yyi; \
475 for (yyi = 0; yyi < (Count); yyi++) \
476 (Dst)[yyi] = (Src)[yyi]; \
477 } \
478 while (0)
479 # endif
480 # endif
481 #endif /* !YYCOPY_NEEDED */
482
483 /* YYFINAL -- State number of the termination state. */
484 #define YYFINAL 5
485 /* YYLAST -- Last index in YYTABLE. */
486 #define YYLAST 239
487
488 /* YYNTOKENS -- Number of terminals. */
489 #define YYNTOKENS 57
490 /* YYNNTS -- Number of nonterminals. */
491 #define YYNNTS 23
492 /* YYNRULES -- Number of rules. */
493 #define YYNRULES 104
494 /* YYNSTATES -- Number of states. */
495 #define YYNSTATES 143
496
497 #define YYUNDEFTOK 2
498 #define YYMAXUTOK 295
499
500 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
501 as returned by yylex, with out-of-bounds checking. */
502 #define YYTRANSLATE(YYX) \
503 ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
504
505 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
506 as returned by yylex. */
507 static const yytype_uint8 yytranslate[] =
508 {
509 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
510 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
511 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
512 2, 2, 2, 2, 2, 2, 48, 44, 2, 2,
513 46, 47, 42, 40, 50, 41, 55, 43, 2, 2,
514 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
515 2, 2, 2, 56, 49, 2, 2, 2, 2, 2,
516 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
517 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
518 2, 51, 2, 52, 2, 2, 2, 2, 2, 2,
519 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
520 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
521 2, 2, 2, 53, 2, 54, 2, 2, 2, 2,
522 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
523 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
524 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
525 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
526 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
527 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
528 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
529 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
530 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
531 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
532 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
533 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
534 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
535 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
536 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
537 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
538 35, 36, 37, 38, 39, 45
539 };
540
541 #if YYDEBUG
542 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
543 static const yytype_uint16 yyrline[] =
544 {
545 0, 130, 130, 135, 139, 140, 144, 145, 146, 150,
546 151, 152, 153, 154, 155, 156, 160, 161, 162, 163,
547 164, 165, 169, 170, 174, 175, 176, 177, 178, 179,
548 181, 183, 184, 189, 190, 194, 195, 196, 197, 201,
549 202, 203, 204, 208, 209, 210, 211, 212, 213, 214,
550 215, 216, 220, 221, 225, 226, 230, 231, 235, 236,
551 240, 241, 242, 247, 248, 249, 250, 251, 252, 254,
552 258, 262, 263, 267, 271, 272, 273, 274, 275, 276,
553 277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
554 287, 288, 289, 290, 291, 292, 293, 294, 298, 299,
555 300, 301, 302, 303, 304
556 };
557 #endif
558
559 #if YYDEBUG || YYERROR_VERBOSE || 1
560 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
561 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
562 static const char *const yytname[] =
563 {
564 "$end", "error", "$undefined", "TO_P", "NULL_P", "TRUE_P", "FALSE_P",
565 "IS_P", "UNKNOWN_P", "EXISTS_P", "IDENT_P", "STRING_P", "NUMERIC_P",
566 "INT_P", "VARIABLE_P", "OR_P", "AND_P", "NOT_P", "LESS_P", "LESSEQUAL_P",
567 "EQUAL_P", "NOTEQUAL_P", "GREATEREQUAL_P", "GREATER_P", "ANY_P",
568 "STRICT_P", "LAX_P", "LAST_P", "STARTS_P", "WITH_P", "LIKE_REGEX_P",
569 "FLAG_P", "ABS_P", "SIZE_P", "TYPE_P", "FLOOR_P", "DOUBLE_P",
570 "CEILING_P", "KEYVALUE_P", "DATETIME_P", "'+'", "'-'", "'*'", "'/'",
571 "'%'", "UMINUS", "'('", "')'", "'$'", "'@'", "','", "'['", "']'", "'{'",
572 "'}'", "'.'", "'?'", "$accept", "result", "expr_or_predicate", "mode",
573 "scalar_value", "comp_op", "delimited_predicate", "predicate",
574 "starts_with_initial", "path_primary", "accessor_expr", "expr",
575 "index_elem", "index_list", "array_accessor", "any_level", "any_path",
576 "accessor_op", "datetime_template", "opt_datetime_template", "key",
577 "key_name", "method", YY_NULLPTR
578 };
579 #endif
580
581 # ifdef YYPRINT
582 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
583 (internal) symbol number NUM (which must be that of a token). */
584 static const yytype_uint16 yytoknum[] =
585 {
586 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
587 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
588 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
589 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
590 43, 45, 42, 47, 37, 295, 40, 41, 36, 64,
591 44, 91, 93, 123, 125, 46, 63
592 };
593 # endif
594
595 #define YYPACT_NINF -44
596
597 #define yypact_value_is_default(Yystate) \
598 (!!((Yystate) == (-44)))
599
600 #define YYTABLE_NINF -105
601
602 #define yytable_value_is_error(Yytable_value) \
603 0
604
605 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
606 STATE-NUM. */
607 static const yytype_int16 yypact[] =
608 {
609 7, -44, -44, 18, 51, -44, -44, -44, -44, -43,
610 -44, -44, -44, -44, -3, -44, 114, 114, 51, -44,
611 -44, -44, -44, -44, 10, -44, -35, 195, 114, 51,
612 -44, 51, -44, -44, 14, 165, 51, 51, 68, 140,
613 -9, -44, -44, -44, -44, -44, -44, -44, -44, 37,
614 60, 114, 114, 114, 114, 114, 114, 46, 20, 195,
615 30, 3, -35, 59, -44, 24, -2, -44, -41, -44,
616 -44, -44, -44, -44, -44, -44, -44, -44, 31, -44,
617 -44, -44, -44, -44, -44, -44, 48, 50, 52, 61,
618 67, 69, 78, 83, -44, -44, -44, -44, 84, 51,
619 17, 100, 79, 79, -44, -44, -44, 62, -44, -44,
620 -35, 75, -44, -44, -44, 114, 114, -44, -8, 121,
621 86, 54, -44, -44, -44, 123, -44, 62, -44, -44,
622 -44, -1, -44, -44, 88, -44, -44, -44, -8, -44,
623 -44, 82, -44
624 };
625
626 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
627 Performed when YYTABLE does not specify something else to do. Zero
628 means the default is an error. */
629 static const yytype_uint8 yydefact[] =
630 {
631 8, 6, 7, 0, 0, 1, 10, 11, 12, 0,
632 9, 13, 14, 15, 0, 38, 0, 0, 0, 36,
633 37, 2, 35, 24, 5, 39, 43, 4, 0, 0,
634 28, 0, 45, 46, 0, 0, 0, 0, 0, 0,
635 0, 65, 42, 18, 20, 16, 17, 21, 19, 0,
636 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
637 0, 22, 44, 27, 26, 0, 52, 54, 0, 76,
638 77, 78, 79, 80, 81, 82, 74, 75, 60, 83,
639 84, 93, 94, 95, 96, 97, 85, 86, 87, 88,
640 89, 90, 92, 91, 64, 66, 63, 73, 0, 0,
641 0, 31, 47, 48, 49, 50, 51, 25, 23, 22,
642 0, 0, 41, 40, 56, 0, 0, 57, 0, 72,
643 0, 0, 33, 34, 30, 0, 29, 53, 55, 58,
644 59, 0, 70, 71, 0, 67, 69, 32, 0, 61,
645 68, 0, 62
646 };
647
648 /* YYPGOTO[NTERM-NUM]. */
649 static const yytype_int8 yypgoto[] =
650 {
651 -44, -44, -44, -44, -44, -44, 124, -14, -44, -44,
652 -44, -4, 21, -44, -44, 1, -44, -18, -44, -44,
653 -44, -44, -44
654 };
655
656 /* YYDEFGOTO[NTERM-NUM]. */
657 static const yytype_int16 yydefgoto[] =
658 {
659 -1, 3, 21, 4, 22, 56, 23, 24, 124, 25,
660 26, 59, 67, 68, 41, 131, 95, 112, 133, 134,
661 96, 97, 98
662 };
663
664 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
665 positive, shift that token. If negative, reduce the rule whose
666 number is the opposite. If YYTABLE_NINF, syntax error. */
667 static const yytype_int16 yytable[] =
668 {
669 27, 115, 138, 28, 34, 129, 9, -3, 42, 116,
670 111, 117, 32, 33, 35, 58, 38, 60, 5, 130,
671 39, 40, 63, 64, 57, 36, 37, 35, 122, 36,
672 37, 123, 1, 2, 66, 36, 37, 99, 51, 52,
673 53, 54, 55, 29, 113, 36, 37, 102, 103, 104,
674 105, 106, 107, 139, 38, 6, 7, 8, 39, 40,
675 9, 61, 10, 11, 12, 13, 100, 109, 14, 36,
676 37, 101, 6, 7, 8, 37, 114, 110, 15, 10,
677 11, 12, 13, 126, 118, 121, 51, 52, 53, 54,
678 55, 16, 17, 108, -98, 15, -99, 18, -100, 19,
679 20, 136, 51, 52, 53, 54, 55, -101, 16, 17,
680 65, 127, 66, -102, 31, -103, 19, 20, 6, 7,
681 8, 53, 54, 55, -104, 10, 11, 12, 13, 119,
682 120, 125, 132, 135, 137, 140, 142, 128, 30, 141,
683 0, 15, 0, 69, 70, 71, 72, 73, 74, 75,
684 76, 77, 0, 0, 16, 17, 0, 0, 0, 0,
685 31, 0, 19, 20, 78, 79, 80, 81, 82, 83,
686 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
687 0, 0, 94, 43, 44, 45, 46, 47, 48, 0,
688 0, 0, 0, 49, 0, 50, 0, 0, 0, 0,
689 0, 0, 0, 0, 0, 51, 52, 53, 54, 55,
690 0, 0, 62, 43, 44, 45, 46, 47, 48, 0,
691 0, 0, 0, 49, 0, 50, 0, 0, 0, 0,
692 0, 0, 0, 0, 0, 51, 52, 53, 54, 55
693 };
694
695 static const yytype_int16 yycheck[] =
696 {
697 4, 3, 3, 46, 18, 13, 9, 0, 26, 50,
698 7, 52, 16, 17, 18, 29, 51, 31, 0, 27,
699 55, 56, 36, 37, 28, 15, 16, 31, 11, 15,
700 16, 14, 25, 26, 38, 15, 16, 46, 40, 41,
701 42, 43, 44, 46, 62, 15, 16, 51, 52, 53,
702 54, 55, 56, 54, 51, 4, 5, 6, 55, 56,
703 9, 47, 11, 12, 13, 14, 29, 47, 17, 15,
704 16, 11, 4, 5, 6, 16, 52, 47, 27, 11,
705 12, 13, 14, 8, 53, 99, 40, 41, 42, 43,
706 44, 40, 41, 47, 46, 27, 46, 46, 46, 48,
707 49, 47, 40, 41, 42, 43, 44, 46, 40, 41,
708 42, 115, 116, 46, 46, 46, 48, 49, 4, 5,
709 6, 42, 43, 44, 46, 11, 12, 13, 14, 46,
710 46, 31, 11, 47, 11, 47, 54, 116, 14, 138,
711 -1, 27, -1, 3, 4, 5, 6, 7, 8, 9,
712 10, 11, -1, -1, 40, 41, -1, -1, -1, -1,
713 46, -1, 48, 49, 24, 25, 26, 27, 28, 29,
714 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
715 -1, -1, 42, 18, 19, 20, 21, 22, 23, -1,
716 -1, -1, -1, 28, -1, 30, -1, -1, -1, -1,
717 -1, -1, -1, -1, -1, 40, 41, 42, 43, 44,
718 -1, -1, 47, 18, 19, 20, 21, 22, 23, -1,
719 -1, -1, -1, 28, -1, 30, -1, -1, -1, -1,
720 -1, -1, -1, -1, -1, 40, 41, 42, 43, 44
721 };
722
723 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
724 symbol of state STATE-NUM. */
725 static const yytype_uint8 yystos[] =
726 {
727 0, 25, 26, 58, 60, 0, 4, 5, 6, 9,
728 11, 12, 13, 14, 17, 27, 40, 41, 46, 48,
729 49, 59, 61, 63, 64, 66, 67, 68, 46, 46,
730 63, 46, 68, 68, 64, 68, 15, 16, 51, 55,
731 56, 71, 74, 18, 19, 20, 21, 22, 23, 28,
732 30, 40, 41, 42, 43, 44, 62, 68, 64, 68,
733 64, 47, 47, 64, 64, 42, 68, 69, 70, 3,
734 4, 5, 6, 7, 8, 9, 10, 11, 24, 25,
735 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
736 36, 37, 38, 39, 42, 73, 77, 78, 79, 46,
737 29, 11, 68, 68, 68, 68, 68, 68, 47, 47,
738 47, 7, 74, 74, 52, 3, 50, 52, 53, 46,
739 46, 64, 11, 14, 65, 31, 8, 68, 69, 13,
740 27, 72, 11, 75, 76, 47, 47, 11, 3, 54,
741 47, 72, 54
742 };
743
744 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
745 static const yytype_uint8 yyr1[] =
746 {
747 0, 57, 58, 58, 59, 59, 60, 60, 60, 61,
748 61, 61, 61, 61, 61, 61, 62, 62, 62, 62,
749 62, 62, 63, 63, 64, 64, 64, 64, 64, 64,
750 64, 64, 64, 65, 65, 66, 66, 66, 66, 67,
751 67, 67, 67, 68, 68, 68, 68, 68, 68, 68,
752 68, 68, 69, 69, 70, 70, 71, 71, 72, 72,
753 73, 73, 73, 74, 74, 74, 74, 74, 74, 74,
754 75, 76, 76, 77, 78, 78, 78, 78, 78, 78,
755 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
756 78, 78, 78, 78, 78, 78, 78, 78, 79, 79,
757 79, 79, 79, 79, 79
758 };
759
760 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
761 static const yytype_uint8 yyr2[] =
762 {
763 0, 2, 2, 0, 1, 1, 1, 1, 0, 1,
764 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
765 1, 1, 3, 4, 1, 3, 3, 3, 2, 5,
766 4, 3, 5, 1, 1, 1, 1, 1, 1, 1,
767 4, 4, 2, 1, 3, 2, 2, 3, 3, 3,
768 3, 3, 1, 3, 1, 3, 3, 3, 1, 1,
769 1, 4, 6, 2, 2, 1, 2, 4, 5, 4,
770 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
771 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
772 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
773 1, 1, 1, 1, 1
774 };
775
776
777 #define yyerrok (yyerrstatus = 0)
778 #define yyclearin (yychar = YYEMPTY)
779 #define YYEMPTY (-2)
780 #define YYEOF 0
781
782 #define YYACCEPT goto yyacceptlab
783 #define YYABORT goto yyabortlab
784 #define YYERROR goto yyerrorlab
785
786
787 #define YYRECOVERING() (!!yyerrstatus)
788
789 #define YYBACKUP(Token, Value) \
790 do \
791 if (yychar == YYEMPTY) \
792 { \
793 yychar = (Token); \
794 yylval = (Value); \
795 YYPOPSTACK (yylen); \
796 yystate = *yyssp; \
797 goto yybackup; \
798 } \
799 else \
800 { \
801 yyerror (result, YY_("syntax error: cannot back up")); \
802 YYERROR; \
803 } \
804 while (0)
805
806 /* Error token number */
807 #define YYTERROR 1
808 #define YYERRCODE 256
809
810
811
812 /* Enable debugging if requested. */
813 #if YYDEBUG
814
815 # ifndef YYFPRINTF
816 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
817 # define YYFPRINTF fprintf
818 # endif
819
820 # define YYDPRINTF(Args) \
821 do { \
822 if (yydebug) \
823 YYFPRINTF Args; \
824 } while (0)
825
826 /* This macro is provided for backward compatibility. */
827 #ifndef YY_LOCATION_PRINT
828 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
829 #endif
830
831
832 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
833 do { \
834 if (yydebug) \
835 { \
836 YYFPRINTF (stderr, "%s ", Title); \
837 yy_symbol_print (stderr, \
838 Type, Value, result); \
839 YYFPRINTF (stderr, "\n"); \
840 } \
841 } while (0)
842
843
844 /*-----------------------------------.
845 | Print this symbol's value on YYO. |
846 `-----------------------------------*/
847
848 static void
yy_symbol_value_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep,JsonPathParseResult ** result)849 yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, JsonPathParseResult **result)
850 {
851 FILE *yyoutput = yyo;
852 YYUSE (yyoutput);
853 YYUSE (result);
854 if (!yyvaluep)
855 return;
856 # ifdef YYPRINT
857 if (yytype < YYNTOKENS)
858 YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
859 # endif
860 YYUSE (yytype);
861 }
862
863
864 /*---------------------------.
865 | Print this symbol on YYO. |
866 `---------------------------*/
867
868 static void
yy_symbol_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep,JsonPathParseResult ** result)869 yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, JsonPathParseResult **result)
870 {
871 YYFPRINTF (yyo, "%s %s (",
872 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
873
874 yy_symbol_value_print (yyo, yytype, yyvaluep, result);
875 YYFPRINTF (yyo, ")");
876 }
877
878 /*------------------------------------------------------------------.
879 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
880 | TOP (included). |
881 `------------------------------------------------------------------*/
882
883 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)884 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
885 {
886 YYFPRINTF (stderr, "Stack now");
887 for (; yybottom <= yytop; yybottom++)
888 {
889 int yybot = *yybottom;
890 YYFPRINTF (stderr, " %d", yybot);
891 }
892 YYFPRINTF (stderr, "\n");
893 }
894
895 # define YY_STACK_PRINT(Bottom, Top) \
896 do { \
897 if (yydebug) \
898 yy_stack_print ((Bottom), (Top)); \
899 } while (0)
900
901
902 /*------------------------------------------------.
903 | Report that the YYRULE is going to be reduced. |
904 `------------------------------------------------*/
905
906 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule,JsonPathParseResult ** result)907 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, JsonPathParseResult **result)
908 {
909 unsigned long yylno = yyrline[yyrule];
910 int yynrhs = yyr2[yyrule];
911 int yyi;
912 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
913 yyrule - 1, yylno);
914 /* The symbols being reduced. */
915 for (yyi = 0; yyi < yynrhs; yyi++)
916 {
917 YYFPRINTF (stderr, " $%d = ", yyi + 1);
918 yy_symbol_print (stderr,
919 yystos[yyssp[yyi + 1 - yynrhs]],
920 &yyvsp[(yyi + 1) - (yynrhs)]
921 , result);
922 YYFPRINTF (stderr, "\n");
923 }
924 }
925
926 # define YY_REDUCE_PRINT(Rule) \
927 do { \
928 if (yydebug) \
929 yy_reduce_print (yyssp, yyvsp, Rule, result); \
930 } while (0)
931
932 /* Nonzero means print parse trace. It is left uninitialized so that
933 multiple parsers can coexist. */
934 int yydebug;
935 #else /* !YYDEBUG */
936 # define YYDPRINTF(Args)
937 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
938 # define YY_STACK_PRINT(Bottom, Top)
939 # define YY_REDUCE_PRINT(Rule)
940 #endif /* !YYDEBUG */
941
942
943 /* YYINITDEPTH -- initial size of the parser's stacks. */
944 #ifndef YYINITDEPTH
945 # define YYINITDEPTH 200
946 #endif
947
948 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
949 if the built-in stack extension method is used).
950
951 Do not make this value too large; the results are undefined if
952 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
953 evaluated with infinite-precision integer arithmetic. */
954
955 #ifndef YYMAXDEPTH
956 # define YYMAXDEPTH 10000
957 #endif
958
959
960 #if YYERROR_VERBOSE
961
962 # ifndef yystrlen
963 # if defined __GLIBC__ && defined _STRING_H
964 # define yystrlen strlen
965 # else
966 /* Return the length of YYSTR. */
967 static YYSIZE_T
yystrlen(const char * yystr)968 yystrlen (const char *yystr)
969 {
970 YYSIZE_T yylen;
971 for (yylen = 0; yystr[yylen]; yylen++)
972 continue;
973 return yylen;
974 }
975 # endif
976 # endif
977
978 # ifndef yystpcpy
979 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
980 # define yystpcpy stpcpy
981 # else
982 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
983 YYDEST. */
984 static char *
yystpcpy(char * yydest,const char * yysrc)985 yystpcpy (char *yydest, const char *yysrc)
986 {
987 char *yyd = yydest;
988 const char *yys = yysrc;
989
990 while ((*yyd++ = *yys++) != '\0')
991 continue;
992
993 return yyd - 1;
994 }
995 # endif
996 # endif
997
998 # ifndef yytnamerr
999 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1000 quotes and backslashes, so that it's suitable for yyerror. The
1001 heuristic is that double-quoting is unnecessary unless the string
1002 contains an apostrophe, a comma, or backslash (other than
1003 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1004 null, do not copy; instead, return the length of what the result
1005 would have been. */
1006 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1007 yytnamerr (char *yyres, const char *yystr)
1008 {
1009 if (*yystr == '"')
1010 {
1011 YYSIZE_T yyn = 0;
1012 char const *yyp = yystr;
1013
1014 for (;;)
1015 switch (*++yyp)
1016 {
1017 case '\'':
1018 case ',':
1019 goto do_not_strip_quotes;
1020
1021 case '\\':
1022 if (*++yyp != '\\')
1023 goto do_not_strip_quotes;
1024 else
1025 goto append;
1026
1027 append:
1028 default:
1029 if (yyres)
1030 yyres[yyn] = *yyp;
1031 yyn++;
1032 break;
1033
1034 case '"':
1035 if (yyres)
1036 yyres[yyn] = '\0';
1037 return yyn;
1038 }
1039 do_not_strip_quotes: ;
1040 }
1041
1042 if (! yyres)
1043 return yystrlen (yystr);
1044
1045 return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres);
1046 }
1047 # endif
1048
1049 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1050 about the unexpected token YYTOKEN for the state stack whose top is
1051 YYSSP.
1052
1053 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1054 not large enough to hold the message. In that case, also set
1055 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1056 required number of bytes is too large to store. */
1057 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1058 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1059 yytype_int16 *yyssp, int yytoken)
1060 {
1061 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1062 YYSIZE_T yysize = yysize0;
1063 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1064 /* Internationalized format string. */
1065 const char *yyformat = YY_NULLPTR;
1066 /* Arguments of yyformat. */
1067 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1068 /* Number of reported tokens (one for the "unexpected", one per
1069 "expected"). */
1070 int yycount = 0;
1071
1072 /* There are many possibilities here to consider:
1073 - If this state is a consistent state with a default action, then
1074 the only way this function was invoked is if the default action
1075 is an error action. In that case, don't check for expected
1076 tokens because there are none.
1077 - The only way there can be no lookahead present (in yychar) is if
1078 this state is a consistent state with a default action. Thus,
1079 detecting the absence of a lookahead is sufficient to determine
1080 that there is no unexpected or expected token to report. In that
1081 case, just report a simple "syntax error".
1082 - Don't assume there isn't a lookahead just because this state is a
1083 consistent state with a default action. There might have been a
1084 previous inconsistent state, consistent state with a non-default
1085 action, or user semantic action that manipulated yychar.
1086 - Of course, the expected token list depends on states to have
1087 correct lookahead information, and it depends on the parser not
1088 to perform extra reductions after fetching a lookahead from the
1089 scanner and before detecting a syntax error. Thus, state merging
1090 (from LALR or IELR) and default reductions corrupt the expected
1091 token list. However, the list is correct for canonical LR with
1092 one exception: it will still contain any token that will not be
1093 accepted due to an error action in a later state.
1094 */
1095 if (yytoken != YYEMPTY)
1096 {
1097 int yyn = yypact[*yyssp];
1098 yyarg[yycount++] = yytname[yytoken];
1099 if (!yypact_value_is_default (yyn))
1100 {
1101 /* Start YYX at -YYN if negative to avoid negative indexes in
1102 YYCHECK. In other words, skip the first -YYN actions for
1103 this state because they are default actions. */
1104 int yyxbegin = yyn < 0 ? -yyn : 0;
1105 /* Stay within bounds of both yycheck and yytname. */
1106 int yychecklim = YYLAST - yyn + 1;
1107 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1108 int yyx;
1109
1110 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1111 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1112 && !yytable_value_is_error (yytable[yyx + yyn]))
1113 {
1114 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1115 {
1116 yycount = 1;
1117 yysize = yysize0;
1118 break;
1119 }
1120 yyarg[yycount++] = yytname[yyx];
1121 {
1122 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1123 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1124 yysize = yysize1;
1125 else
1126 return 2;
1127 }
1128 }
1129 }
1130 }
1131
1132 switch (yycount)
1133 {
1134 # define YYCASE_(N, S) \
1135 case N: \
1136 yyformat = S; \
1137 break
1138 default: /* Avoid compiler warnings. */
1139 YYCASE_(0, YY_("syntax error"));
1140 YYCASE_(1, YY_("syntax error, unexpected %s"));
1141 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1142 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1143 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1144 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1145 # undef YYCASE_
1146 }
1147
1148 {
1149 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1150 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1151 yysize = yysize1;
1152 else
1153 return 2;
1154 }
1155
1156 if (*yymsg_alloc < yysize)
1157 {
1158 *yymsg_alloc = 2 * yysize;
1159 if (! (yysize <= *yymsg_alloc
1160 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1161 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1162 return 1;
1163 }
1164
1165 /* Avoid sprintf, as that infringes on the user's name space.
1166 Don't have undefined behavior even if the translation
1167 produced a string with the wrong number of "%s"s. */
1168 {
1169 char *yyp = *yymsg;
1170 int yyi = 0;
1171 while ((*yyp = *yyformat) != '\0')
1172 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1173 {
1174 yyp += yytnamerr (yyp, yyarg[yyi++]);
1175 yyformat += 2;
1176 }
1177 else
1178 {
1179 yyp++;
1180 yyformat++;
1181 }
1182 }
1183 return 0;
1184 }
1185 #endif /* YYERROR_VERBOSE */
1186
1187 /*-----------------------------------------------.
1188 | Release the memory associated to this symbol. |
1189 `-----------------------------------------------*/
1190
1191 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,JsonPathParseResult ** result)1192 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, JsonPathParseResult **result)
1193 {
1194 YYUSE (yyvaluep);
1195 YYUSE (result);
1196 if (!yymsg)
1197 yymsg = "Deleting";
1198 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1199
1200 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1201 YYUSE (yytype);
1202 YY_IGNORE_MAYBE_UNINITIALIZED_END
1203 }
1204
1205
1206
1207
1208 /*----------.
1209 | yyparse. |
1210 `----------*/
1211
1212 int
yyparse(JsonPathParseResult ** result)1213 yyparse (JsonPathParseResult **result)
1214 {
1215 /* The lookahead symbol. */
1216 int yychar;
1217
1218
1219 /* The semantic value of the lookahead symbol. */
1220 /* Default value used for initialization, for pacifying older GCCs
1221 or non-GCC compilers. */
1222 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1223 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1224
1225 /* Number of syntax errors so far. */
1226 int yynerrs;
1227
1228 int yystate;
1229 /* Number of tokens to shift before error messages enabled. */
1230 int yyerrstatus;
1231
1232 /* The stacks and their tools:
1233 'yyss': related to states.
1234 'yyvs': related to semantic values.
1235
1236 Refer to the stacks through separate pointers, to allow yyoverflow
1237 to reallocate them elsewhere. */
1238
1239 /* The state stack. */
1240 yytype_int16 yyssa[YYINITDEPTH];
1241 yytype_int16 *yyss;
1242 yytype_int16 *yyssp;
1243
1244 /* The semantic value stack. */
1245 YYSTYPE yyvsa[YYINITDEPTH];
1246 YYSTYPE *yyvs;
1247 YYSTYPE *yyvsp;
1248
1249 YYSIZE_T yystacksize;
1250
1251 int yyn;
1252 int yyresult;
1253 /* Lookahead token as an internal (translated) token number. */
1254 int yytoken = 0;
1255 /* The variables used to return semantic value and location from the
1256 action routines. */
1257 YYSTYPE yyval;
1258
1259 #if YYERROR_VERBOSE
1260 /* Buffer for error messages, and its allocated size. */
1261 char yymsgbuf[128];
1262 char *yymsg = yymsgbuf;
1263 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1264 #endif
1265
1266 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1267
1268 /* The number of symbols on the RHS of the reduced rule.
1269 Keep to zero when no symbol should be popped. */
1270 int yylen = 0;
1271
1272 yyssp = yyss = yyssa;
1273 yyvsp = yyvs = yyvsa;
1274 yystacksize = YYINITDEPTH;
1275
1276 YYDPRINTF ((stderr, "Starting parse\n"));
1277
1278 yystate = 0;
1279 yyerrstatus = 0;
1280 yynerrs = 0;
1281 yychar = YYEMPTY; /* Cause a token to be read. */
1282 goto yysetstate;
1283
1284
1285 /*------------------------------------------------------------.
1286 | yynewstate -- push a new state, which is found in yystate. |
1287 `------------------------------------------------------------*/
1288 yynewstate:
1289 /* In all cases, when you get here, the value and location stacks
1290 have just been pushed. So pushing a state here evens the stacks. */
1291 yyssp++;
1292
1293
1294 /*--------------------------------------------------------------------.
1295 | yynewstate -- set current state (the top of the stack) to yystate. |
1296 `--------------------------------------------------------------------*/
1297 yysetstate:
1298 *yyssp = (yytype_int16) yystate;
1299
1300 if (yyss + yystacksize - 1 <= yyssp)
1301 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1302 goto yyexhaustedlab;
1303 #else
1304 {
1305 /* Get the current used size of the three stacks, in elements. */
1306 YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1);
1307
1308 # if defined yyoverflow
1309 {
1310 /* Give user a chance to reallocate the stack. Use copies of
1311 these so that the &'s don't force the real ones into
1312 memory. */
1313 YYSTYPE *yyvs1 = yyvs;
1314 yytype_int16 *yyss1 = yyss;
1315
1316 /* Each stack pointer address is followed by the size of the
1317 data in use in that stack, in bytes. This used to be a
1318 conditional around just the two extra args, but that might
1319 be undefined if yyoverflow is a macro. */
1320 yyoverflow (YY_("memory exhausted"),
1321 &yyss1, yysize * sizeof (*yyssp),
1322 &yyvs1, yysize * sizeof (*yyvsp),
1323 &yystacksize);
1324 yyss = yyss1;
1325 yyvs = yyvs1;
1326 }
1327 # else /* defined YYSTACK_RELOCATE */
1328 /* Extend the stack our own way. */
1329 if (YYMAXDEPTH <= yystacksize)
1330 goto yyexhaustedlab;
1331 yystacksize *= 2;
1332 if (YYMAXDEPTH < yystacksize)
1333 yystacksize = YYMAXDEPTH;
1334
1335 {
1336 yytype_int16 *yyss1 = yyss;
1337 union yyalloc *yyptr =
1338 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1339 if (! yyptr)
1340 goto yyexhaustedlab;
1341 YYSTACK_RELOCATE (yyss_alloc, yyss);
1342 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1343 # undef YYSTACK_RELOCATE
1344 if (yyss1 != yyssa)
1345 YYSTACK_FREE (yyss1);
1346 }
1347 # endif
1348
1349 yyssp = yyss + yysize - 1;
1350 yyvsp = yyvs + yysize - 1;
1351
1352 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1353 (unsigned long) yystacksize));
1354
1355 if (yyss + yystacksize - 1 <= yyssp)
1356 YYABORT;
1357 }
1358 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1359
1360 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1361
1362 if (yystate == YYFINAL)
1363 YYACCEPT;
1364
1365 goto yybackup;
1366
1367
1368 /*-----------.
1369 | yybackup. |
1370 `-----------*/
1371 yybackup:
1372 /* Do appropriate processing given the current state. Read a
1373 lookahead token if we need one and don't already have one. */
1374
1375 /* First try to decide what to do without reference to lookahead token. */
1376 yyn = yypact[yystate];
1377 if (yypact_value_is_default (yyn))
1378 goto yydefault;
1379
1380 /* Not known => get a lookahead token if don't already have one. */
1381
1382 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1383 if (yychar == YYEMPTY)
1384 {
1385 YYDPRINTF ((stderr, "Reading a token: "));
1386 yychar = yylex (&yylval);
1387 }
1388
1389 if (yychar <= YYEOF)
1390 {
1391 yychar = yytoken = YYEOF;
1392 YYDPRINTF ((stderr, "Now at end of input.\n"));
1393 }
1394 else
1395 {
1396 yytoken = YYTRANSLATE (yychar);
1397 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1398 }
1399
1400 /* If the proper action on seeing token YYTOKEN is to reduce or to
1401 detect an error, take that action. */
1402 yyn += yytoken;
1403 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1404 goto yydefault;
1405 yyn = yytable[yyn];
1406 if (yyn <= 0)
1407 {
1408 if (yytable_value_is_error (yyn))
1409 goto yyerrlab;
1410 yyn = -yyn;
1411 goto yyreduce;
1412 }
1413
1414 /* Count tokens shifted since error; after three, turn off error
1415 status. */
1416 if (yyerrstatus)
1417 yyerrstatus--;
1418
1419 /* Shift the lookahead token. */
1420 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1421
1422 /* Discard the shifted token. */
1423 yychar = YYEMPTY;
1424
1425 yystate = yyn;
1426 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1427 *++yyvsp = yylval;
1428 YY_IGNORE_MAYBE_UNINITIALIZED_END
1429
1430 goto yynewstate;
1431
1432
1433 /*-----------------------------------------------------------.
1434 | yydefault -- do the default action for the current state. |
1435 `-----------------------------------------------------------*/
1436 yydefault:
1437 yyn = yydefact[yystate];
1438 if (yyn == 0)
1439 goto yyerrlab;
1440 goto yyreduce;
1441
1442
1443 /*-----------------------------.
1444 | yyreduce -- do a reduction. |
1445 `-----------------------------*/
1446 yyreduce:
1447 /* yyn is the number of a rule to reduce with. */
1448 yylen = yyr2[yyn];
1449
1450 /* If YYLEN is nonzero, implement the default value of the action:
1451 '$$ = $1'.
1452
1453 Otherwise, the following line sets YYVAL to garbage.
1454 This behavior is undocumented and Bison
1455 users should not rely upon it. Assigning to YYVAL
1456 unconditionally makes the parser a bit smaller, and it avoids a
1457 GCC warning that YYVAL may be used uninitialized. */
1458 yyval = yyvsp[1-yylen];
1459
1460
1461 YY_REDUCE_PRINT (yyn);
1462 switch (yyn)
1463 {
1464 case 2:
1465 #line 130 "jsonpath_gram.y" /* yacc.c:1652 */
1466 {
1467 *result = palloc(sizeof(JsonPathParseResult));
1468 (*result)->expr = (yyvsp[0].value);
1469 (*result)->lax = (yyvsp[-1].boolean);
1470 }
1471 #line 1472 "jsonpath_gram.c" /* yacc.c:1652 */
1472 break;
1473
1474 case 3:
1475 #line 135 "jsonpath_gram.y" /* yacc.c:1652 */
1476 { *result = NULL; }
1477 #line 1478 "jsonpath_gram.c" /* yacc.c:1652 */
1478 break;
1479
1480 case 4:
1481 #line 139 "jsonpath_gram.y" /* yacc.c:1652 */
1482 { (yyval.value) = (yyvsp[0].value); }
1483 #line 1484 "jsonpath_gram.c" /* yacc.c:1652 */
1484 break;
1485
1486 case 5:
1487 #line 140 "jsonpath_gram.y" /* yacc.c:1652 */
1488 { (yyval.value) = (yyvsp[0].value); }
1489 #line 1490 "jsonpath_gram.c" /* yacc.c:1652 */
1490 break;
1491
1492 case 6:
1493 #line 144 "jsonpath_gram.y" /* yacc.c:1652 */
1494 { (yyval.boolean) = false; }
1495 #line 1496 "jsonpath_gram.c" /* yacc.c:1652 */
1496 break;
1497
1498 case 7:
1499 #line 145 "jsonpath_gram.y" /* yacc.c:1652 */
1500 { (yyval.boolean) = true; }
1501 #line 1502 "jsonpath_gram.c" /* yacc.c:1652 */
1502 break;
1503
1504 case 8:
1505 #line 146 "jsonpath_gram.y" /* yacc.c:1652 */
1506 { (yyval.boolean) = true; }
1507 #line 1508 "jsonpath_gram.c" /* yacc.c:1652 */
1508 break;
1509
1510 case 9:
1511 #line 150 "jsonpath_gram.y" /* yacc.c:1652 */
1512 { (yyval.value) = makeItemString(&(yyvsp[0].str)); }
1513 #line 1514 "jsonpath_gram.c" /* yacc.c:1652 */
1514 break;
1515
1516 case 10:
1517 #line 151 "jsonpath_gram.y" /* yacc.c:1652 */
1518 { (yyval.value) = makeItemString(NULL); }
1519 #line 1520 "jsonpath_gram.c" /* yacc.c:1652 */
1520 break;
1521
1522 case 11:
1523 #line 152 "jsonpath_gram.y" /* yacc.c:1652 */
1524 { (yyval.value) = makeItemBool(true); }
1525 #line 1526 "jsonpath_gram.c" /* yacc.c:1652 */
1526 break;
1527
1528 case 12:
1529 #line 153 "jsonpath_gram.y" /* yacc.c:1652 */
1530 { (yyval.value) = makeItemBool(false); }
1531 #line 1532 "jsonpath_gram.c" /* yacc.c:1652 */
1532 break;
1533
1534 case 13:
1535 #line 154 "jsonpath_gram.y" /* yacc.c:1652 */
1536 { (yyval.value) = makeItemNumeric(&(yyvsp[0].str)); }
1537 #line 1538 "jsonpath_gram.c" /* yacc.c:1652 */
1538 break;
1539
1540 case 14:
1541 #line 155 "jsonpath_gram.y" /* yacc.c:1652 */
1542 { (yyval.value) = makeItemNumeric(&(yyvsp[0].str)); }
1543 #line 1544 "jsonpath_gram.c" /* yacc.c:1652 */
1544 break;
1545
1546 case 15:
1547 #line 156 "jsonpath_gram.y" /* yacc.c:1652 */
1548 { (yyval.value) = makeItemVariable(&(yyvsp[0].str)); }
1549 #line 1550 "jsonpath_gram.c" /* yacc.c:1652 */
1550 break;
1551
1552 case 16:
1553 #line 160 "jsonpath_gram.y" /* yacc.c:1652 */
1554 { (yyval.optype) = jpiEqual; }
1555 #line 1556 "jsonpath_gram.c" /* yacc.c:1652 */
1556 break;
1557
1558 case 17:
1559 #line 161 "jsonpath_gram.y" /* yacc.c:1652 */
1560 { (yyval.optype) = jpiNotEqual; }
1561 #line 1562 "jsonpath_gram.c" /* yacc.c:1652 */
1562 break;
1563
1564 case 18:
1565 #line 162 "jsonpath_gram.y" /* yacc.c:1652 */
1566 { (yyval.optype) = jpiLess; }
1567 #line 1568 "jsonpath_gram.c" /* yacc.c:1652 */
1568 break;
1569
1570 case 19:
1571 #line 163 "jsonpath_gram.y" /* yacc.c:1652 */
1572 { (yyval.optype) = jpiGreater; }
1573 #line 1574 "jsonpath_gram.c" /* yacc.c:1652 */
1574 break;
1575
1576 case 20:
1577 #line 164 "jsonpath_gram.y" /* yacc.c:1652 */
1578 { (yyval.optype) = jpiLessOrEqual; }
1579 #line 1580 "jsonpath_gram.c" /* yacc.c:1652 */
1580 break;
1581
1582 case 21:
1583 #line 165 "jsonpath_gram.y" /* yacc.c:1652 */
1584 { (yyval.optype) = jpiGreaterOrEqual; }
1585 #line 1586 "jsonpath_gram.c" /* yacc.c:1652 */
1586 break;
1587
1588 case 22:
1589 #line 169 "jsonpath_gram.y" /* yacc.c:1652 */
1590 { (yyval.value) = (yyvsp[-1].value); }
1591 #line 1592 "jsonpath_gram.c" /* yacc.c:1652 */
1592 break;
1593
1594 case 23:
1595 #line 170 "jsonpath_gram.y" /* yacc.c:1652 */
1596 { (yyval.value) = makeItemUnary(jpiExists, (yyvsp[-1].value)); }
1597 #line 1598 "jsonpath_gram.c" /* yacc.c:1652 */
1598 break;
1599
1600 case 24:
1601 #line 174 "jsonpath_gram.y" /* yacc.c:1652 */
1602 { (yyval.value) = (yyvsp[0].value); }
1603 #line 1604 "jsonpath_gram.c" /* yacc.c:1652 */
1604 break;
1605
1606 case 25:
1607 #line 175 "jsonpath_gram.y" /* yacc.c:1652 */
1608 { (yyval.value) = makeItemBinary((yyvsp[-1].optype), (yyvsp[-2].value), (yyvsp[0].value)); }
1609 #line 1610 "jsonpath_gram.c" /* yacc.c:1652 */
1610 break;
1611
1612 case 26:
1613 #line 176 "jsonpath_gram.y" /* yacc.c:1652 */
1614 { (yyval.value) = makeItemBinary(jpiAnd, (yyvsp[-2].value), (yyvsp[0].value)); }
1615 #line 1616 "jsonpath_gram.c" /* yacc.c:1652 */
1616 break;
1617
1618 case 27:
1619 #line 177 "jsonpath_gram.y" /* yacc.c:1652 */
1620 { (yyval.value) = makeItemBinary(jpiOr, (yyvsp[-2].value), (yyvsp[0].value)); }
1621 #line 1622 "jsonpath_gram.c" /* yacc.c:1652 */
1622 break;
1623
1624 case 28:
1625 #line 178 "jsonpath_gram.y" /* yacc.c:1652 */
1626 { (yyval.value) = makeItemUnary(jpiNot, (yyvsp[0].value)); }
1627 #line 1628 "jsonpath_gram.c" /* yacc.c:1652 */
1628 break;
1629
1630 case 29:
1631 #line 180 "jsonpath_gram.y" /* yacc.c:1652 */
1632 { (yyval.value) = makeItemUnary(jpiIsUnknown, (yyvsp[-3].value)); }
1633 #line 1634 "jsonpath_gram.c" /* yacc.c:1652 */
1634 break;
1635
1636 case 30:
1637 #line 182 "jsonpath_gram.y" /* yacc.c:1652 */
1638 { (yyval.value) = makeItemBinary(jpiStartsWith, (yyvsp[-3].value), (yyvsp[0].value)); }
1639 #line 1640 "jsonpath_gram.c" /* yacc.c:1652 */
1640 break;
1641
1642 case 31:
1643 #line 183 "jsonpath_gram.y" /* yacc.c:1652 */
1644 { (yyval.value) = makeItemLikeRegex((yyvsp[-2].value), &(yyvsp[0].str), NULL); }
1645 #line 1646 "jsonpath_gram.c" /* yacc.c:1652 */
1646 break;
1647
1648 case 32:
1649 #line 185 "jsonpath_gram.y" /* yacc.c:1652 */
1650 { (yyval.value) = makeItemLikeRegex((yyvsp[-4].value), &(yyvsp[-2].str), &(yyvsp[0].str)); }
1651 #line 1652 "jsonpath_gram.c" /* yacc.c:1652 */
1652 break;
1653
1654 case 33:
1655 #line 189 "jsonpath_gram.y" /* yacc.c:1652 */
1656 { (yyval.value) = makeItemString(&(yyvsp[0].str)); }
1657 #line 1658 "jsonpath_gram.c" /* yacc.c:1652 */
1658 break;
1659
1660 case 34:
1661 #line 190 "jsonpath_gram.y" /* yacc.c:1652 */
1662 { (yyval.value) = makeItemVariable(&(yyvsp[0].str)); }
1663 #line 1664 "jsonpath_gram.c" /* yacc.c:1652 */
1664 break;
1665
1666 case 35:
1667 #line 194 "jsonpath_gram.y" /* yacc.c:1652 */
1668 { (yyval.value) = (yyvsp[0].value); }
1669 #line 1670 "jsonpath_gram.c" /* yacc.c:1652 */
1670 break;
1671
1672 case 36:
1673 #line 195 "jsonpath_gram.y" /* yacc.c:1652 */
1674 { (yyval.value) = makeItemType(jpiRoot); }
1675 #line 1676 "jsonpath_gram.c" /* yacc.c:1652 */
1676 break;
1677
1678 case 37:
1679 #line 196 "jsonpath_gram.y" /* yacc.c:1652 */
1680 { (yyval.value) = makeItemType(jpiCurrent); }
1681 #line 1682 "jsonpath_gram.c" /* yacc.c:1652 */
1682 break;
1683
1684 case 38:
1685 #line 197 "jsonpath_gram.y" /* yacc.c:1652 */
1686 { (yyval.value) = makeItemType(jpiLast); }
1687 #line 1688 "jsonpath_gram.c" /* yacc.c:1652 */
1688 break;
1689
1690 case 39:
1691 #line 201 "jsonpath_gram.y" /* yacc.c:1652 */
1692 { (yyval.elems) = list_make1((yyvsp[0].value)); }
1693 #line 1694 "jsonpath_gram.c" /* yacc.c:1652 */
1694 break;
1695
1696 case 40:
1697 #line 202 "jsonpath_gram.y" /* yacc.c:1652 */
1698 { (yyval.elems) = list_make2((yyvsp[-2].value), (yyvsp[0].value)); }
1699 #line 1700 "jsonpath_gram.c" /* yacc.c:1652 */
1700 break;
1701
1702 case 41:
1703 #line 203 "jsonpath_gram.y" /* yacc.c:1652 */
1704 { (yyval.elems) = list_make2((yyvsp[-2].value), (yyvsp[0].value)); }
1705 #line 1706 "jsonpath_gram.c" /* yacc.c:1652 */
1706 break;
1707
1708 case 42:
1709 #line 204 "jsonpath_gram.y" /* yacc.c:1652 */
1710 { (yyval.elems) = lappend((yyvsp[-1].elems), (yyvsp[0].value)); }
1711 #line 1712 "jsonpath_gram.c" /* yacc.c:1652 */
1712 break;
1713
1714 case 43:
1715 #line 208 "jsonpath_gram.y" /* yacc.c:1652 */
1716 { (yyval.value) = makeItemList((yyvsp[0].elems)); }
1717 #line 1718 "jsonpath_gram.c" /* yacc.c:1652 */
1718 break;
1719
1720 case 44:
1721 #line 209 "jsonpath_gram.y" /* yacc.c:1652 */
1722 { (yyval.value) = (yyvsp[-1].value); }
1723 #line 1724 "jsonpath_gram.c" /* yacc.c:1652 */
1724 break;
1725
1726 case 45:
1727 #line 210 "jsonpath_gram.y" /* yacc.c:1652 */
1728 { (yyval.value) = makeItemUnary(jpiPlus, (yyvsp[0].value)); }
1729 #line 1730 "jsonpath_gram.c" /* yacc.c:1652 */
1730 break;
1731
1732 case 46:
1733 #line 211 "jsonpath_gram.y" /* yacc.c:1652 */
1734 { (yyval.value) = makeItemUnary(jpiMinus, (yyvsp[0].value)); }
1735 #line 1736 "jsonpath_gram.c" /* yacc.c:1652 */
1736 break;
1737
1738 case 47:
1739 #line 212 "jsonpath_gram.y" /* yacc.c:1652 */
1740 { (yyval.value) = makeItemBinary(jpiAdd, (yyvsp[-2].value), (yyvsp[0].value)); }
1741 #line 1742 "jsonpath_gram.c" /* yacc.c:1652 */
1742 break;
1743
1744 case 48:
1745 #line 213 "jsonpath_gram.y" /* yacc.c:1652 */
1746 { (yyval.value) = makeItemBinary(jpiSub, (yyvsp[-2].value), (yyvsp[0].value)); }
1747 #line 1748 "jsonpath_gram.c" /* yacc.c:1652 */
1748 break;
1749
1750 case 49:
1751 #line 214 "jsonpath_gram.y" /* yacc.c:1652 */
1752 { (yyval.value) = makeItemBinary(jpiMul, (yyvsp[-2].value), (yyvsp[0].value)); }
1753 #line 1754 "jsonpath_gram.c" /* yacc.c:1652 */
1754 break;
1755
1756 case 50:
1757 #line 215 "jsonpath_gram.y" /* yacc.c:1652 */
1758 { (yyval.value) = makeItemBinary(jpiDiv, (yyvsp[-2].value), (yyvsp[0].value)); }
1759 #line 1760 "jsonpath_gram.c" /* yacc.c:1652 */
1760 break;
1761
1762 case 51:
1763 #line 216 "jsonpath_gram.y" /* yacc.c:1652 */
1764 { (yyval.value) = makeItemBinary(jpiMod, (yyvsp[-2].value), (yyvsp[0].value)); }
1765 #line 1766 "jsonpath_gram.c" /* yacc.c:1652 */
1766 break;
1767
1768 case 52:
1769 #line 220 "jsonpath_gram.y" /* yacc.c:1652 */
1770 { (yyval.value) = makeItemBinary(jpiSubscript, (yyvsp[0].value), NULL); }
1771 #line 1772 "jsonpath_gram.c" /* yacc.c:1652 */
1772 break;
1773
1774 case 53:
1775 #line 221 "jsonpath_gram.y" /* yacc.c:1652 */
1776 { (yyval.value) = makeItemBinary(jpiSubscript, (yyvsp[-2].value), (yyvsp[0].value)); }
1777 #line 1778 "jsonpath_gram.c" /* yacc.c:1652 */
1778 break;
1779
1780 case 54:
1781 #line 225 "jsonpath_gram.y" /* yacc.c:1652 */
1782 { (yyval.indexs) = list_make1((yyvsp[0].value)); }
1783 #line 1784 "jsonpath_gram.c" /* yacc.c:1652 */
1784 break;
1785
1786 case 55:
1787 #line 226 "jsonpath_gram.y" /* yacc.c:1652 */
1788 { (yyval.indexs) = lappend((yyvsp[-2].indexs), (yyvsp[0].value)); }
1789 #line 1790 "jsonpath_gram.c" /* yacc.c:1652 */
1790 break;
1791
1792 case 56:
1793 #line 230 "jsonpath_gram.y" /* yacc.c:1652 */
1794 { (yyval.value) = makeItemType(jpiAnyArray); }
1795 #line 1796 "jsonpath_gram.c" /* yacc.c:1652 */
1796 break;
1797
1798 case 57:
1799 #line 231 "jsonpath_gram.y" /* yacc.c:1652 */
1800 { (yyval.value) = makeIndexArray((yyvsp[-1].indexs)); }
1801 #line 1802 "jsonpath_gram.c" /* yacc.c:1652 */
1802 break;
1803
1804 case 58:
1805 #line 235 "jsonpath_gram.y" /* yacc.c:1652 */
1806 { (yyval.integer) = pg_atoi((yyvsp[0].str).val, 4, 0); }
1807 #line 1808 "jsonpath_gram.c" /* yacc.c:1652 */
1808 break;
1809
1810 case 59:
1811 #line 236 "jsonpath_gram.y" /* yacc.c:1652 */
1812 { (yyval.integer) = -1; }
1813 #line 1814 "jsonpath_gram.c" /* yacc.c:1652 */
1814 break;
1815
1816 case 60:
1817 #line 240 "jsonpath_gram.y" /* yacc.c:1652 */
1818 { (yyval.value) = makeAny(0, -1); }
1819 #line 1820 "jsonpath_gram.c" /* yacc.c:1652 */
1820 break;
1821
1822 case 61:
1823 #line 241 "jsonpath_gram.y" /* yacc.c:1652 */
1824 { (yyval.value) = makeAny((yyvsp[-1].integer), (yyvsp[-1].integer)); }
1825 #line 1826 "jsonpath_gram.c" /* yacc.c:1652 */
1826 break;
1827
1828 case 62:
1829 #line 243 "jsonpath_gram.y" /* yacc.c:1652 */
1830 { (yyval.value) = makeAny((yyvsp[-3].integer), (yyvsp[-1].integer)); }
1831 #line 1832 "jsonpath_gram.c" /* yacc.c:1652 */
1832 break;
1833
1834 case 63:
1835 #line 247 "jsonpath_gram.y" /* yacc.c:1652 */
1836 { (yyval.value) = (yyvsp[0].value); }
1837 #line 1838 "jsonpath_gram.c" /* yacc.c:1652 */
1838 break;
1839
1840 case 64:
1841 #line 248 "jsonpath_gram.y" /* yacc.c:1652 */
1842 { (yyval.value) = makeItemType(jpiAnyKey); }
1843 #line 1844 "jsonpath_gram.c" /* yacc.c:1652 */
1844 break;
1845
1846 case 65:
1847 #line 249 "jsonpath_gram.y" /* yacc.c:1652 */
1848 { (yyval.value) = (yyvsp[0].value); }
1849 #line 1850 "jsonpath_gram.c" /* yacc.c:1652 */
1850 break;
1851
1852 case 66:
1853 #line 250 "jsonpath_gram.y" /* yacc.c:1652 */
1854 { (yyval.value) = (yyvsp[0].value); }
1855 #line 1856 "jsonpath_gram.c" /* yacc.c:1652 */
1856 break;
1857
1858 case 67:
1859 #line 251 "jsonpath_gram.y" /* yacc.c:1652 */
1860 { (yyval.value) = makeItemType((yyvsp[-2].optype)); }
1861 #line 1862 "jsonpath_gram.c" /* yacc.c:1652 */
1862 break;
1863
1864 case 68:
1865 #line 253 "jsonpath_gram.y" /* yacc.c:1652 */
1866 { (yyval.value) = makeItemUnary(jpiDatetime, (yyvsp[-1].value)); }
1867 #line 1868 "jsonpath_gram.c" /* yacc.c:1652 */
1868 break;
1869
1870 case 69:
1871 #line 254 "jsonpath_gram.y" /* yacc.c:1652 */
1872 { (yyval.value) = makeItemUnary(jpiFilter, (yyvsp[-1].value)); }
1873 #line 1874 "jsonpath_gram.c" /* yacc.c:1652 */
1874 break;
1875
1876 case 70:
1877 #line 258 "jsonpath_gram.y" /* yacc.c:1652 */
1878 { (yyval.value) = makeItemString(&(yyvsp[0].str)); }
1879 #line 1880 "jsonpath_gram.c" /* yacc.c:1652 */
1880 break;
1881
1882 case 71:
1883 #line 262 "jsonpath_gram.y" /* yacc.c:1652 */
1884 { (yyval.value) = (yyvsp[0].value); }
1885 #line 1886 "jsonpath_gram.c" /* yacc.c:1652 */
1886 break;
1887
1888 case 72:
1889 #line 263 "jsonpath_gram.y" /* yacc.c:1652 */
1890 { (yyval.value) = NULL; }
1891 #line 1892 "jsonpath_gram.c" /* yacc.c:1652 */
1892 break;
1893
1894 case 73:
1895 #line 267 "jsonpath_gram.y" /* yacc.c:1652 */
1896 { (yyval.value) = makeItemKey(&(yyvsp[0].str)); }
1897 #line 1898 "jsonpath_gram.c" /* yacc.c:1652 */
1898 break;
1899
1900 case 98:
1901 #line 298 "jsonpath_gram.y" /* yacc.c:1652 */
1902 { (yyval.optype) = jpiAbs; }
1903 #line 1904 "jsonpath_gram.c" /* yacc.c:1652 */
1904 break;
1905
1906 case 99:
1907 #line 299 "jsonpath_gram.y" /* yacc.c:1652 */
1908 { (yyval.optype) = jpiSize; }
1909 #line 1910 "jsonpath_gram.c" /* yacc.c:1652 */
1910 break;
1911
1912 case 100:
1913 #line 300 "jsonpath_gram.y" /* yacc.c:1652 */
1914 { (yyval.optype) = jpiType; }
1915 #line 1916 "jsonpath_gram.c" /* yacc.c:1652 */
1916 break;
1917
1918 case 101:
1919 #line 301 "jsonpath_gram.y" /* yacc.c:1652 */
1920 { (yyval.optype) = jpiFloor; }
1921 #line 1922 "jsonpath_gram.c" /* yacc.c:1652 */
1922 break;
1923
1924 case 102:
1925 #line 302 "jsonpath_gram.y" /* yacc.c:1652 */
1926 { (yyval.optype) = jpiDouble; }
1927 #line 1928 "jsonpath_gram.c" /* yacc.c:1652 */
1928 break;
1929
1930 case 103:
1931 #line 303 "jsonpath_gram.y" /* yacc.c:1652 */
1932 { (yyval.optype) = jpiCeiling; }
1933 #line 1934 "jsonpath_gram.c" /* yacc.c:1652 */
1934 break;
1935
1936 case 104:
1937 #line 304 "jsonpath_gram.y" /* yacc.c:1652 */
1938 { (yyval.optype) = jpiKeyValue; }
1939 #line 1940 "jsonpath_gram.c" /* yacc.c:1652 */
1940 break;
1941
1942
1943 #line 1944 "jsonpath_gram.c" /* yacc.c:1652 */
1944 default: break;
1945 }
1946 /* User semantic actions sometimes alter yychar, and that requires
1947 that yytoken be updated with the new translation. We take the
1948 approach of translating immediately before every use of yytoken.
1949 One alternative is translating here after every semantic action,
1950 but that translation would be missed if the semantic action invokes
1951 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1952 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1953 incorrect destructor might then be invoked immediately. In the
1954 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1955 to an incorrect destructor call or verbose syntax error message
1956 before the lookahead is translated. */
1957 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1958
1959 YYPOPSTACK (yylen);
1960 yylen = 0;
1961 YY_STACK_PRINT (yyss, yyssp);
1962
1963 *++yyvsp = yyval;
1964
1965 /* Now 'shift' the result of the reduction. Determine what state
1966 that goes to, based on the state we popped back to and the rule
1967 number reduced by. */
1968 {
1969 const int yylhs = yyr1[yyn] - YYNTOKENS;
1970 const int yyi = yypgoto[yylhs] + *yyssp;
1971 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1972 ? yytable[yyi]
1973 : yydefgoto[yylhs]);
1974 }
1975
1976 goto yynewstate;
1977
1978
1979 /*--------------------------------------.
1980 | yyerrlab -- here on detecting error. |
1981 `--------------------------------------*/
1982 yyerrlab:
1983 /* Make sure we have latest lookahead translation. See comments at
1984 user semantic actions for why this is necessary. */
1985 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1986
1987 /* If not already recovering from an error, report this error. */
1988 if (!yyerrstatus)
1989 {
1990 ++yynerrs;
1991 #if ! YYERROR_VERBOSE
1992 yyerror (result, YY_("syntax error"));
1993 #else
1994 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1995 yyssp, yytoken)
1996 {
1997 char const *yymsgp = YY_("syntax error");
1998 int yysyntax_error_status;
1999 yysyntax_error_status = YYSYNTAX_ERROR;
2000 if (yysyntax_error_status == 0)
2001 yymsgp = yymsg;
2002 else if (yysyntax_error_status == 1)
2003 {
2004 if (yymsg != yymsgbuf)
2005 YYSTACK_FREE (yymsg);
2006 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2007 if (!yymsg)
2008 {
2009 yymsg = yymsgbuf;
2010 yymsg_alloc = sizeof yymsgbuf;
2011 yysyntax_error_status = 2;
2012 }
2013 else
2014 {
2015 yysyntax_error_status = YYSYNTAX_ERROR;
2016 yymsgp = yymsg;
2017 }
2018 }
2019 yyerror (result, yymsgp);
2020 if (yysyntax_error_status == 2)
2021 goto yyexhaustedlab;
2022 }
2023 # undef YYSYNTAX_ERROR
2024 #endif
2025 }
2026
2027
2028
2029 if (yyerrstatus == 3)
2030 {
2031 /* If just tried and failed to reuse lookahead token after an
2032 error, discard it. */
2033
2034 if (yychar <= YYEOF)
2035 {
2036 /* Return failure if at end of input. */
2037 if (yychar == YYEOF)
2038 YYABORT;
2039 }
2040 else
2041 {
2042 yydestruct ("Error: discarding",
2043 yytoken, &yylval, result);
2044 yychar = YYEMPTY;
2045 }
2046 }
2047
2048 /* Else will try to reuse lookahead token after shifting the error
2049 token. */
2050 goto yyerrlab1;
2051
2052
2053 /*---------------------------------------------------.
2054 | yyerrorlab -- error raised explicitly by YYERROR. |
2055 `---------------------------------------------------*/
2056 yyerrorlab:
2057 /* Pacify compilers when the user code never invokes YYERROR and the
2058 label yyerrorlab therefore never appears in user code. */
2059 if (0)
2060 YYERROR;
2061
2062 /* Do not reclaim the symbols of the rule whose action triggered
2063 this YYERROR. */
2064 YYPOPSTACK (yylen);
2065 yylen = 0;
2066 YY_STACK_PRINT (yyss, yyssp);
2067 yystate = *yyssp;
2068 goto yyerrlab1;
2069
2070
2071 /*-------------------------------------------------------------.
2072 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2073 `-------------------------------------------------------------*/
2074 yyerrlab1:
2075 yyerrstatus = 3; /* Each real token shifted decrements this. */
2076
2077 for (;;)
2078 {
2079 yyn = yypact[yystate];
2080 if (!yypact_value_is_default (yyn))
2081 {
2082 yyn += YYTERROR;
2083 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2084 {
2085 yyn = yytable[yyn];
2086 if (0 < yyn)
2087 break;
2088 }
2089 }
2090
2091 /* Pop the current state because it cannot handle the error token. */
2092 if (yyssp == yyss)
2093 YYABORT;
2094
2095
2096 yydestruct ("Error: popping",
2097 yystos[yystate], yyvsp, result);
2098 YYPOPSTACK (1);
2099 yystate = *yyssp;
2100 YY_STACK_PRINT (yyss, yyssp);
2101 }
2102
2103 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2104 *++yyvsp = yylval;
2105 YY_IGNORE_MAYBE_UNINITIALIZED_END
2106
2107
2108 /* Shift the error token. */
2109 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2110
2111 yystate = yyn;
2112 goto yynewstate;
2113
2114
2115 /*-------------------------------------.
2116 | yyacceptlab -- YYACCEPT comes here. |
2117 `-------------------------------------*/
2118 yyacceptlab:
2119 yyresult = 0;
2120 goto yyreturn;
2121
2122
2123 /*-----------------------------------.
2124 | yyabortlab -- YYABORT comes here. |
2125 `-----------------------------------*/
2126 yyabortlab:
2127 yyresult = 1;
2128 goto yyreturn;
2129
2130
2131 #if !defined yyoverflow || YYERROR_VERBOSE
2132 /*-------------------------------------------------.
2133 | yyexhaustedlab -- memory exhaustion comes here. |
2134 `-------------------------------------------------*/
2135 yyexhaustedlab:
2136 yyerror (result, YY_("memory exhausted"));
2137 yyresult = 2;
2138 /* Fall through. */
2139 #endif
2140
2141
2142 /*-----------------------------------------------------.
2143 | yyreturn -- parsing is finished, return the result. |
2144 `-----------------------------------------------------*/
2145 yyreturn:
2146 if (yychar != YYEMPTY)
2147 {
2148 /* Make sure we have latest lookahead translation. See comments at
2149 user semantic actions for why this is necessary. */
2150 yytoken = YYTRANSLATE (yychar);
2151 yydestruct ("Cleanup: discarding lookahead",
2152 yytoken, &yylval, result);
2153 }
2154 /* Do not reclaim the symbols of the rule whose action triggered
2155 this YYABORT or YYACCEPT. */
2156 YYPOPSTACK (yylen);
2157 YY_STACK_PRINT (yyss, yyssp);
2158 while (yyssp != yyss)
2159 {
2160 yydestruct ("Cleanup: popping",
2161 yystos[*yyssp], yyvsp, result);
2162 YYPOPSTACK (1);
2163 }
2164 #ifndef yyoverflow
2165 if (yyss != yyssa)
2166 YYSTACK_FREE (yyss);
2167 #endif
2168 #if YYERROR_VERBOSE
2169 if (yymsg != yymsgbuf)
2170 YYSTACK_FREE (yymsg);
2171 #endif
2172 return yyresult;
2173 }
2174 #line 306 "jsonpath_gram.y" /* yacc.c:1918 */
2175
2176
2177 /*
2178 * The helper functions below allocate and fill JsonPathParseItem's of various
2179 * types.
2180 */
2181
2182 static JsonPathParseItem *
makeItemType(JsonPathItemType type)2183 makeItemType(JsonPathItemType type)
2184 {
2185 JsonPathParseItem *v = palloc(sizeof(*v));
2186
2187 CHECK_FOR_INTERRUPTS();
2188
2189 v->type = type;
2190 v->next = NULL;
2191
2192 return v;
2193 }
2194
2195 static JsonPathParseItem *
makeItemString(JsonPathString * s)2196 makeItemString(JsonPathString *s)
2197 {
2198 JsonPathParseItem *v;
2199
2200 if (s == NULL)
2201 {
2202 v = makeItemType(jpiNull);
2203 }
2204 else
2205 {
2206 v = makeItemType(jpiString);
2207 v->value.string.val = s->val;
2208 v->value.string.len = s->len;
2209 }
2210
2211 return v;
2212 }
2213
2214 static JsonPathParseItem *
makeItemVariable(JsonPathString * s)2215 makeItemVariable(JsonPathString *s)
2216 {
2217 JsonPathParseItem *v;
2218
2219 v = makeItemType(jpiVariable);
2220 v->value.string.val = s->val;
2221 v->value.string.len = s->len;
2222
2223 return v;
2224 }
2225
2226 static JsonPathParseItem *
makeItemKey(JsonPathString * s)2227 makeItemKey(JsonPathString *s)
2228 {
2229 JsonPathParseItem *v;
2230
2231 v = makeItemString(s);
2232 v->type = jpiKey;
2233
2234 return v;
2235 }
2236
2237 static JsonPathParseItem *
makeItemNumeric(JsonPathString * s)2238 makeItemNumeric(JsonPathString *s)
2239 {
2240 JsonPathParseItem *v;
2241
2242 v = makeItemType(jpiNumeric);
2243 v->value.numeric =
2244 DatumGetNumeric(DirectFunctionCall3(numeric_in,
2245 CStringGetDatum(s->val),
2246 ObjectIdGetDatum(InvalidOid),
2247 Int32GetDatum(-1)));
2248
2249 return v;
2250 }
2251
2252 static JsonPathParseItem *
makeItemBool(bool val)2253 makeItemBool(bool val)
2254 {
2255 JsonPathParseItem *v = makeItemType(jpiBool);
2256
2257 v->value.boolean = val;
2258
2259 return v;
2260 }
2261
2262 static JsonPathParseItem *
makeItemBinary(JsonPathItemType type,JsonPathParseItem * la,JsonPathParseItem * ra)2263 makeItemBinary(JsonPathItemType type, JsonPathParseItem *la, JsonPathParseItem *ra)
2264 {
2265 JsonPathParseItem *v = makeItemType(type);
2266
2267 v->value.args.left = la;
2268 v->value.args.right = ra;
2269
2270 return v;
2271 }
2272
2273 static JsonPathParseItem *
makeItemUnary(JsonPathItemType type,JsonPathParseItem * a)2274 makeItemUnary(JsonPathItemType type, JsonPathParseItem *a)
2275 {
2276 JsonPathParseItem *v;
2277
2278 if (type == jpiPlus && a->type == jpiNumeric && !a->next)
2279 return a;
2280
2281 if (type == jpiMinus && a->type == jpiNumeric && !a->next)
2282 {
2283 v = makeItemType(jpiNumeric);
2284 v->value.numeric =
2285 DatumGetNumeric(DirectFunctionCall1(numeric_uminus,
2286 NumericGetDatum(a->value.numeric)));
2287 return v;
2288 }
2289
2290 v = makeItemType(type);
2291
2292 v->value.arg = a;
2293
2294 return v;
2295 }
2296
2297 static JsonPathParseItem *
makeItemList(List * list)2298 makeItemList(List *list)
2299 {
2300 JsonPathParseItem *head,
2301 *end;
2302 ListCell *cell;
2303
2304 head = end = (JsonPathParseItem *) linitial(list);
2305
2306 if (list_length(list) == 1)
2307 return head;
2308
2309 /* append items to the end of already existing list */
2310 while (end->next)
2311 end = end->next;
2312
2313 for_each_from(cell, list, 1)
2314 {
2315 JsonPathParseItem *c = (JsonPathParseItem *) lfirst(cell);
2316
2317 end->next = c;
2318 end = c;
2319 }
2320
2321 return head;
2322 }
2323
2324 static JsonPathParseItem *
makeIndexArray(List * list)2325 makeIndexArray(List *list)
2326 {
2327 JsonPathParseItem *v = makeItemType(jpiIndexArray);
2328 ListCell *cell;
2329 int i = 0;
2330
2331 Assert(list_length(list) > 0);
2332 v->value.array.nelems = list_length(list);
2333
2334 v->value.array.elems = palloc(sizeof(v->value.array.elems[0]) *
2335 v->value.array.nelems);
2336
2337 foreach(cell, list)
2338 {
2339 JsonPathParseItem *jpi = lfirst(cell);
2340
2341 Assert(jpi->type == jpiSubscript);
2342
2343 v->value.array.elems[i].from = jpi->value.args.left;
2344 v->value.array.elems[i++].to = jpi->value.args.right;
2345 }
2346
2347 return v;
2348 }
2349
2350 static JsonPathParseItem *
makeAny(int first,int last)2351 makeAny(int first, int last)
2352 {
2353 JsonPathParseItem *v = makeItemType(jpiAny);
2354
2355 v->value.anybounds.first = (first >= 0) ? first : PG_UINT32_MAX;
2356 v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX;
2357
2358 return v;
2359 }
2360
2361 static JsonPathParseItem *
makeItemLikeRegex(JsonPathParseItem * expr,JsonPathString * pattern,JsonPathString * flags)2362 makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
2363 JsonPathString *flags)
2364 {
2365 JsonPathParseItem *v = makeItemType(jpiLikeRegex);
2366 int i;
2367 int cflags;
2368
2369 v->value.like_regex.expr = expr;
2370 v->value.like_regex.pattern = pattern->val;
2371 v->value.like_regex.patternlen = pattern->len;
2372
2373 /* Parse the flags string, convert to bitmask. Duplicate flags are OK. */
2374 v->value.like_regex.flags = 0;
2375 for (i = 0; flags && i < flags->len; i++)
2376 {
2377 switch (flags->val[i])
2378 {
2379 case 'i':
2380 v->value.like_regex.flags |= JSP_REGEX_ICASE;
2381 break;
2382 case 's':
2383 v->value.like_regex.flags |= JSP_REGEX_DOTALL;
2384 break;
2385 case 'm':
2386 v->value.like_regex.flags |= JSP_REGEX_MLINE;
2387 break;
2388 case 'x':
2389 v->value.like_regex.flags |= JSP_REGEX_WSPACE;
2390 break;
2391 case 'q':
2392 v->value.like_regex.flags |= JSP_REGEX_QUOTE;
2393 break;
2394 default:
2395 ereport(ERROR,
2396 (errcode(ERRCODE_SYNTAX_ERROR),
2397 errmsg("invalid input syntax for type %s", "jsonpath"),
2398 errdetail("unrecognized flag character \"%c\" in LIKE_REGEX predicate",
2399 flags->val[i])));
2400 break;
2401 }
2402 }
2403
2404 /* Convert flags to what RE_compile_and_cache needs */
2405 cflags = jspConvertRegexFlags(v->value.like_regex.flags);
2406
2407 /* check regex validity */
2408 (void) RE_compile_and_cache(cstring_to_text_with_len(pattern->val,
2409 pattern->len),
2410 cflags, DEFAULT_COLLATION_OID);
2411
2412 return v;
2413 }
2414
2415 /*
2416 * Convert from XQuery regex flags to those recognized by our regex library.
2417 */
2418 int
jspConvertRegexFlags(uint32 xflags)2419 jspConvertRegexFlags(uint32 xflags)
2420 {
2421 /* By default, XQuery is very nearly the same as Spencer's AREs */
2422 int cflags = REG_ADVANCED;
2423
2424 /* Ignore-case means the same thing, too, modulo locale issues */
2425 if (xflags & JSP_REGEX_ICASE)
2426 cflags |= REG_ICASE;
2427
2428 /* Per XQuery spec, if 'q' is specified then 'm', 's', 'x' are ignored */
2429 if (xflags & JSP_REGEX_QUOTE)
2430 {
2431 cflags &= ~REG_ADVANCED;
2432 cflags |= REG_QUOTE;
2433 }
2434 else
2435 {
2436 /* Note that dotall mode is the default in POSIX */
2437 if (!(xflags & JSP_REGEX_DOTALL))
2438 cflags |= REG_NLSTOP;
2439 if (xflags & JSP_REGEX_MLINE)
2440 cflags |= REG_NLANCH;
2441
2442 /*
2443 * XQuery's 'x' mode is related to Spencer's expanded mode, but it's
2444 * not really enough alike to justify treating JSP_REGEX_WSPACE as
2445 * REG_EXPANDED. For now we treat 'x' as unimplemented; perhaps in
2446 * future we'll modify the regex library to have an option for
2447 * XQuery-style ignore-whitespace mode.
2448 */
2449 if (xflags & JSP_REGEX_WSPACE)
2450 ereport(ERROR,
2451 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2452 errmsg("XQuery \"x\" flag (expanded regular expressions) is not implemented")));
2453 }
2454
2455 return cflags;
2456 }
2457
2458 /*
2459 * jsonpath_scan.l is compiled as part of jsonpath_gram.y. Currently, this is
2460 * unavoidable because jsonpath_gram does not create a .h file to export its
2461 * token symbols. If these files ever grow large enough to be worth compiling
2462 * separately, that could be fixed; but for now it seems like useless
2463 * complication.
2464 */
2465
2466 #include "jsonpath_scan.c"
2467