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