s3-mdssvc: lexer and parser for Spotlight queries
[Samba.git] / source3 / rpc_server / mdssvc / sparql_parser.c
blob81702907ffdb8c23b6fb007c2eb97fd4978501db
1 /* A Bison parser, made by GNU Bison 3.0.2. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
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.
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.
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/>. */
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.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
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. */
43 /* Identify Bison output. */
44 #define YYBISON 1
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.2"
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
52 /* Pure parsers. */
53 #define YYPURE 0
55 /* Push parsers. */
56 #define YYPUSH 0
58 /* Pull parsers. */
59 #define YYPULL 1
64 /* Copy the first part of user declarations. */
65 #line 21 "sparql_parser.y" /* yacc.c:339 */
67 #include "includes.h"
68 #include "mdssvc.h"
69 #include "sparql_parser.h"
70 #include "sparql_mapping.h"
72 #define YYMALLOC SMB_MALLOC
73 #define YYREALLOC SMB_REALLOC
75 struct yy_buffer_state;
76 typedef struct yy_buffer_state *YY_BUFFER_STATE;
77 extern int yylex (void);
78 extern void yyerror (char const *);
79 extern void *yyterminate(void);
80 extern YY_BUFFER_STATE yy_scan_string( const char *str);
81 extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
83 /* forward declarations */
84 static const char *map_expr(const char *attr, char op, const char *val);
85 static const char *map_daterange(const char *dateattr,
86 time_t date1, time_t date2);
87 static time_t isodate2unix(const char *s);
89 /* global vars, eg needed by the lexer */
90 struct sparql_parser_state {
91 TALLOC_CTX *frame;
92 YY_BUFFER_STATE s;
93 char var;
94 const char *result;
95 } *global_sparql_parser_state;
97 #line 98 "sparql_parser.c" /* yacc.c:339 */
99 # ifndef YY_NULLPTR
100 # if defined __cplusplus && 201103L <= __cplusplus
101 # define YY_NULLPTR nullptr
102 # else
103 # define YY_NULLPTR 0
104 # endif
105 # endif
107 /* Enabling verbose error messages. */
108 #ifdef YYERROR_VERBOSE
109 # undef YYERROR_VERBOSE
110 # define YYERROR_VERBOSE 1
111 #else
112 # define YYERROR_VERBOSE 1
113 #endif
115 /* In a future release of Bison, this section will be replaced
116 by #include "sparql_parser.h". */
117 #ifndef YY_YY_SPARQL_PARSER_H_INCLUDED
118 # define YY_YY_SPARQL_PARSER_H_INCLUDED
119 /* Debug traces. */
120 #ifndef YYDEBUG
121 # define YYDEBUG 0
122 #endif
123 #if YYDEBUG
124 extern int yydebug;
125 #endif
127 /* Token type. */
128 #ifndef YYTOKENTYPE
129 # define YYTOKENTYPE
130 enum yytokentype
132 WORD = 258,
133 BOOL = 259,
134 FUNC_INRANGE = 260,
135 DATE_ISO = 261,
136 OBRACE = 262,
137 CBRACE = 263,
138 EQUAL = 264,
139 UNEQUAL = 265,
140 GT = 266,
141 LT = 267,
142 COMMA = 268,
143 QUOTE = 269,
144 AND = 270,
145 OR = 271
147 #endif
149 /* Value type. */
150 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
151 typedef union YYSTYPE YYSTYPE;
152 union YYSTYPE
154 #line 61 "sparql_parser.y" /* yacc.c:355 */
156 int ival;
157 const char *sval;
158 bool bval;
159 time_t tval;
161 #line 162 "sparql_parser.c" /* yacc.c:355 */
163 # define YYSTYPE_IS_TRIVIAL 1
164 # define YYSTYPE_IS_DECLARED 1
165 #endif
168 extern YYSTYPE yylval;
170 int yyparse (void);
171 /* "%code provides" blocks. */
172 #line 53 "sparql_parser.y" /* yacc.c:355 */
174 #include <stdbool.h>
175 #include "mdssvc.h"
176 #define SPRAW_TIME_OFFSET 978307200
177 extern int yywrap(void);
178 extern bool map_spotlight_to_sparql_query(struct sl_query *slq);
180 #line 181 "sparql_parser.c" /* yacc.c:355 */
182 #endif /* !YY_YY_SPARQL_PARSER_H_INCLUDED */
184 /* Copy the second part of user declarations. */
186 #line 187 "sparql_parser.c" /* yacc.c:358 */
188 #ifdef short
189 # undef short
190 #endif
192 #ifdef YYTYPE_UINT8
193 typedef YYTYPE_UINT8 yytype_uint8;
194 #else
195 typedef unsigned char yytype_uint8;
196 #endif
198 #ifdef YYTYPE_INT8
199 typedef YYTYPE_INT8 yytype_int8;
200 #else
201 typedef signed char yytype_int8;
202 #endif
204 #ifdef YYTYPE_UINT16
205 typedef YYTYPE_UINT16 yytype_uint16;
206 #else
207 typedef unsigned short int yytype_uint16;
208 #endif
210 #ifdef YYTYPE_INT16
211 typedef YYTYPE_INT16 yytype_int16;
212 #else
213 typedef short int yytype_int16;
214 #endif
216 #ifndef YYSIZE_T
217 # ifdef __SIZE_TYPE__
218 # define YYSIZE_T __SIZE_TYPE__
219 # elif defined size_t
220 # define YYSIZE_T size_t
221 # elif ! defined YYSIZE_T
222 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
223 # define YYSIZE_T size_t
224 # else
225 # define YYSIZE_T unsigned int
226 # endif
227 #endif
229 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
231 #ifndef YY_
232 # if defined YYENABLE_NLS && YYENABLE_NLS
233 # if ENABLE_NLS
234 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
235 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
236 # endif
237 # endif
238 # ifndef YY_
239 # define YY_(Msgid) Msgid
240 # endif
241 #endif
243 #ifndef YY_ATTRIBUTE
244 # if (defined __GNUC__ \
245 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
246 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
247 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
248 # else
249 # define YY_ATTRIBUTE(Spec) /* empty */
250 # endif
251 #endif
253 #ifndef YY_ATTRIBUTE_PURE
254 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
255 #endif
257 #ifndef YY_ATTRIBUTE_UNUSED
258 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
259 #endif
261 #if !defined _Noreturn \
262 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
263 # if defined _MSC_VER && 1200 <= _MSC_VER
264 # define _Noreturn __declspec (noreturn)
265 # else
266 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
267 # endif
268 #endif
270 /* Suppress unused-variable warnings by "using" E. */
271 #if ! defined lint || defined __GNUC__
272 # define YYUSE(E) ((void) (E))
273 #else
274 # define YYUSE(E) /* empty */
275 #endif
277 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
278 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
279 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
280 _Pragma ("GCC diagnostic push") \
281 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
282 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
283 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
284 _Pragma ("GCC diagnostic pop")
285 #else
286 # define YY_INITIAL_VALUE(Value) Value
287 #endif
288 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
289 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
290 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
291 #endif
292 #ifndef YY_INITIAL_VALUE
293 # define YY_INITIAL_VALUE(Value) /* Nothing. */
294 #endif
297 #if ! defined yyoverflow || YYERROR_VERBOSE
299 /* The parser invokes alloca or malloc; define the necessary symbols. */
301 # ifdef YYSTACK_USE_ALLOCA
302 # if YYSTACK_USE_ALLOCA
303 # ifdef __GNUC__
304 # define YYSTACK_ALLOC __builtin_alloca
305 # elif defined __BUILTIN_VA_ARG_INCR
306 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
307 # elif defined _AIX
308 # define YYSTACK_ALLOC __alloca
309 # elif defined _MSC_VER
310 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
311 # define alloca _alloca
312 # else
313 # define YYSTACK_ALLOC alloca
314 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
315 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
316 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
317 # ifndef EXIT_SUCCESS
318 # define EXIT_SUCCESS 0
319 # endif
320 # endif
321 # endif
322 # endif
323 # endif
325 # ifdef YYSTACK_ALLOC
326 /* Pacify GCC's 'empty if-body' warning. */
327 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
328 # ifndef YYSTACK_ALLOC_MAXIMUM
329 /* The OS might guarantee only one guard page at the bottom of the stack,
330 and a page size can be as small as 4096 bytes. So we cannot safely
331 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
332 to allow for a few compiler-allocated temporary stack slots. */
333 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
334 # endif
335 # else
336 # define YYSTACK_ALLOC YYMALLOC
337 # define YYSTACK_FREE YYFREE
338 # ifndef YYSTACK_ALLOC_MAXIMUM
339 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
340 # endif
341 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
342 && ! ((defined YYMALLOC || defined malloc) \
343 && (defined YYFREE || defined free)))
344 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
345 # ifndef EXIT_SUCCESS
346 # define EXIT_SUCCESS 0
347 # endif
348 # endif
349 # ifndef YYMALLOC
350 # define YYMALLOC malloc
351 # if ! defined malloc && ! defined EXIT_SUCCESS
352 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
353 # endif
354 # endif
355 # ifndef YYFREE
356 # define YYFREE free
357 # if ! defined free && ! defined EXIT_SUCCESS
358 void free (void *); /* INFRINGES ON USER NAME SPACE */
359 # endif
360 # endif
361 # endif
362 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
365 #if (! defined yyoverflow \
366 && (! defined __cplusplus \
367 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
369 /* A type that is properly aligned for any stack member. */
370 union yyalloc
372 yytype_int16 yyss_alloc;
373 YYSTYPE yyvs_alloc;
376 /* The size of the maximum gap between one aligned stack and the next. */
377 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
379 /* The size of an array large to enough to hold all stacks, each with
380 N elements. */
381 # define YYSTACK_BYTES(N) \
382 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
383 + YYSTACK_GAP_MAXIMUM)
385 # define YYCOPY_NEEDED 1
387 /* Relocate STACK from its old location to the new one. The
388 local variables YYSIZE and YYSTACKSIZE give the old and new number of
389 elements in the stack, and YYPTR gives the new location of the
390 stack. Advance YYPTR to a properly aligned location for the next
391 stack. */
392 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
393 do \
395 YYSIZE_T yynewbytes; \
396 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
397 Stack = &yyptr->Stack_alloc; \
398 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
399 yyptr += yynewbytes / sizeof (*yyptr); \
401 while (0)
403 #endif
405 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
406 /* Copy COUNT objects from SRC to DST. The source and destination do
407 not overlap. */
408 # ifndef YYCOPY
409 # if defined __GNUC__ && 1 < __GNUC__
410 # define YYCOPY(Dst, Src, Count) \
411 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
412 # else
413 # define YYCOPY(Dst, Src, Count) \
414 do \
416 YYSIZE_T yyi; \
417 for (yyi = 0; yyi < (Count); yyi++) \
418 (Dst)[yyi] = (Src)[yyi]; \
420 while (0)
421 # endif
422 # endif
423 #endif /* !YYCOPY_NEEDED */
425 /* YYFINAL -- State number of the termination state. */
426 #define YYFINAL 2
427 /* YYLAST -- Last index in YYTABLE. */
428 #define YYLAST 52
430 /* YYNTOKENS -- Number of terminals. */
431 #define YYNTOKENS 17
432 /* YYNNTS -- Number of nonterminals. */
433 #define YYNNTS 7
434 /* YYNRULES -- Number of rules. */
435 #define YYNRULES 22
436 /* YYNSTATES -- Number of states. */
437 #define YYNSTATES 51
439 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
440 by yylex, with out-of-bounds checking. */
441 #define YYUNDEFTOK 2
442 #define YYMAXUTOK 271
444 #define YYTRANSLATE(YYX) \
445 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
447 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
448 as returned by yylex, without out-of-bounds checking. */
449 static const yytype_uint8 yytranslate[] =
451 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
452 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
453 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
454 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
455 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
456 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
457 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
458 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
459 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
460 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
461 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
462 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
463 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
464 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
477 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
478 15, 16
481 #if YYDEBUG
482 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
483 static const yytype_uint8 yyrline[] =
485 0, 83, 83, 85, 89, 95, 118, 125, 128, 131,
486 134, 137, 147, 151, 155, 159, 163, 167, 171, 175,
487 182, 189, 190
489 #endif
491 #if YYDEBUG || YYERROR_VERBOSE || 1
492 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
493 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
494 static const char *const yytname[] =
496 "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE",
497 "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
498 "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
499 "function", "date", YY_NULLPTR
501 #endif
503 # ifdef YYPRINT
504 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
505 (internal) symbol number NUM (which must be that of a token). */
506 static const yytype_uint16 yytoknum[] =
508 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
509 265, 266, 267, 268, 269, 270, 271
511 # endif
513 #define YYPACT_NINF -10
515 #define yypact_value_is_default(Yystate) \
516 (!!((Yystate) == (-10)))
518 #define YYTABLE_NINF -1
520 #define yytable_value_is_error(Yytable_value) \
523 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
524 STATE-NUM. */
525 static const yytype_int8 yypact[] =
527 -10, 10, -10, 9, -10, -2, -1, -10, 8, -9,
528 -10, 2, 12, 13, 14, 26, -7, -1, -1, 27,
529 28, 29, 30, 31, 22, -10, 20, -10, -10, 23,
530 24, 25, 32, 19, 37, 38, 39, 40, -10, 41,
531 34, -10, -10, -10, -10, 42, 19, 36, 43, -10,
535 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
536 Performed when YYTABLE does not specify something else to do. Zero
537 means the default is an error. */
538 static const yytype_uint8 yydefact[] =
540 2, 0, 1, 0, 5, 0, 0, 3, 4, 7,
541 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
542 0, 0, 0, 0, 0, 9, 10, 11, 6, 0,
543 0, 0, 0, 0, 12, 13, 15, 14, 22, 0,
544 0, 16, 17, 19, 18, 0, 0, 0, 0, 21,
548 /* YYPGOTO[NTERM-NUM]. */
549 static const yytype_int8 yypgoto[] =
551 -10, -10, -10, -6, 33, -10, 3
554 /* YYDEFGOTO[NTERM-NUM]. */
555 static const yytype_int8 yydefgoto[] =
557 -1, 1, 7, 8, 9, 10, 40
560 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
561 positive, shift that token. If negative, reduce the rule whose
562 number is the opposite. If YYTABLE_NINF, syntax error. */
563 static const yytype_uint8 yytable[] =
565 16, 25, 3, 4, 5, 15, 6, 19, 17, 18,
566 2, 26, 27, 3, 4, 5, 20, 6, 11, 12,
567 13, 14, 38, 17, 18, 39, 21, 22, 23, 24,
568 3, 29, 30, 31, 32, 33, 18, 34, 35, 36,
569 41, 42, 43, 44, 49, 47, 37, 46, 45, 48,
570 0, 50, 28
573 static const yytype_int8 yycheck[] =
575 6, 8, 3, 4, 5, 7, 7, 16, 15, 16,
576 0, 17, 18, 3, 4, 5, 14, 7, 9, 10,
577 11, 12, 3, 15, 16, 6, 14, 14, 14, 3,
578 3, 3, 3, 3, 3, 13, 16, 14, 14, 14,
579 3, 3, 3, 3, 8, 3, 14, 13, 7, 46,
580 -1, 8, 19
583 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
584 symbol of state STATE-NUM. */
585 static const yytype_uint8 yystos[] =
587 0, 18, 0, 3, 4, 5, 7, 19, 20, 21,
588 22, 9, 10, 11, 12, 7, 20, 15, 16, 16,
589 14, 14, 14, 14, 3, 8, 20, 20, 21, 3,
590 3, 3, 3, 13, 14, 14, 14, 14, 3, 6,
591 23, 3, 3, 3, 3, 7, 13, 3, 23, 8,
595 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
596 static const yytype_uint8 yyr1[] =
598 0, 17, 18, 18, 19, 20, 20, 20, 20, 20,
599 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
600 22, 23, 23
603 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
604 static const yytype_uint8 yyr2[] =
606 0, 2, 0, 2, 1, 1, 3, 1, 1, 3,
607 3, 3, 5, 5, 5, 5, 6, 6, 6, 6,
608 8, 4, 1
612 #define yyerrok (yyerrstatus = 0)
613 #define yyclearin (yychar = YYEMPTY)
614 #define YYEMPTY (-2)
615 #define YYEOF 0
617 #define YYACCEPT goto yyacceptlab
618 #define YYABORT goto yyabortlab
619 #define YYERROR goto yyerrorlab
622 #define YYRECOVERING() (!!yyerrstatus)
624 #define YYBACKUP(Token, Value) \
625 do \
626 if (yychar == YYEMPTY) \
628 yychar = (Token); \
629 yylval = (Value); \
630 YYPOPSTACK (yylen); \
631 yystate = *yyssp; \
632 goto yybackup; \
634 else \
636 yyerror (YY_("syntax error: cannot back up")); \
637 YYERROR; \
639 while (0)
641 /* Error token number */
642 #define YYTERROR 1
643 #define YYERRCODE 256
647 /* Enable debugging if requested. */
648 #if YYDEBUG
650 # ifndef YYFPRINTF
651 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
652 # define YYFPRINTF fprintf
653 # endif
655 # define YYDPRINTF(Args) \
656 do { \
657 if (yydebug) \
658 YYFPRINTF Args; \
659 } while (0)
661 /* This macro is provided for backward compatibility. */
662 #ifndef YY_LOCATION_PRINT
663 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
664 #endif
667 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
668 do { \
669 if (yydebug) \
671 YYFPRINTF (stderr, "%s ", Title); \
672 yy_symbol_print (stderr, \
673 Type, Value); \
674 YYFPRINTF (stderr, "\n"); \
676 } while (0)
679 /*----------------------------------------.
680 | Print this symbol's value on YYOUTPUT. |
681 `----------------------------------------*/
683 static void
684 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
686 FILE *yyo = yyoutput;
687 YYUSE (yyo);
688 if (!yyvaluep)
689 return;
690 # ifdef YYPRINT
691 if (yytype < YYNTOKENS)
692 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
693 # endif
694 YYUSE (yytype);
698 /*--------------------------------.
699 | Print this symbol on YYOUTPUT. |
700 `--------------------------------*/
702 static void
703 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
705 YYFPRINTF (yyoutput, "%s %s (",
706 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
708 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
709 YYFPRINTF (yyoutput, ")");
712 /*------------------------------------------------------------------.
713 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
714 | TOP (included). |
715 `------------------------------------------------------------------*/
717 static void
718 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
720 YYFPRINTF (stderr, "Stack now");
721 for (; yybottom <= yytop; yybottom++)
723 int yybot = *yybottom;
724 YYFPRINTF (stderr, " %d", yybot);
726 YYFPRINTF (stderr, "\n");
729 # define YY_STACK_PRINT(Bottom, Top) \
730 do { \
731 if (yydebug) \
732 yy_stack_print ((Bottom), (Top)); \
733 } while (0)
736 /*------------------------------------------------.
737 | Report that the YYRULE is going to be reduced. |
738 `------------------------------------------------*/
740 static void
741 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
743 unsigned long int yylno = yyrline[yyrule];
744 int yynrhs = yyr2[yyrule];
745 int yyi;
746 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
747 yyrule - 1, yylno);
748 /* The symbols being reduced. */
749 for (yyi = 0; yyi < yynrhs; yyi++)
751 YYFPRINTF (stderr, " $%d = ", yyi + 1);
752 yy_symbol_print (stderr,
753 yystos[yyssp[yyi + 1 - yynrhs]],
754 &(yyvsp[(yyi + 1) - (yynrhs)])
756 YYFPRINTF (stderr, "\n");
760 # define YY_REDUCE_PRINT(Rule) \
761 do { \
762 if (yydebug) \
763 yy_reduce_print (yyssp, yyvsp, Rule); \
764 } while (0)
766 /* Nonzero means print parse trace. It is left uninitialized so that
767 multiple parsers can coexist. */
768 int yydebug;
769 #else /* !YYDEBUG */
770 # define YYDPRINTF(Args)
771 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
772 # define YY_STACK_PRINT(Bottom, Top)
773 # define YY_REDUCE_PRINT(Rule)
774 #endif /* !YYDEBUG */
777 /* YYINITDEPTH -- initial size of the parser's stacks. */
778 #ifndef YYINITDEPTH
779 # define YYINITDEPTH 200
780 #endif
782 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
783 if the built-in stack extension method is used).
785 Do not make this value too large; the results are undefined if
786 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
787 evaluated with infinite-precision integer arithmetic. */
789 #ifndef YYMAXDEPTH
790 # define YYMAXDEPTH 10000
791 #endif
794 #if YYERROR_VERBOSE
796 # ifndef yystrlen
797 # if defined __GLIBC__ && defined _STRING_H
798 # define yystrlen strlen
799 # else
800 /* Return the length of YYSTR. */
801 static YYSIZE_T
802 yystrlen (const char *yystr)
804 YYSIZE_T yylen;
805 for (yylen = 0; yystr[yylen]; yylen++)
806 continue;
807 return yylen;
809 # endif
810 # endif
812 # ifndef yystpcpy
813 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
814 # define yystpcpy stpcpy
815 # else
816 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
817 YYDEST. */
818 static char *
819 yystpcpy (char *yydest, const char *yysrc)
821 char *yyd = yydest;
822 const char *yys = yysrc;
824 while ((*yyd++ = *yys++) != '\0')
825 continue;
827 return yyd - 1;
829 # endif
830 # endif
832 # ifndef yytnamerr
833 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
834 quotes and backslashes, so that it's suitable for yyerror. The
835 heuristic is that double-quoting is unnecessary unless the string
836 contains an apostrophe, a comma, or backslash (other than
837 backslash-backslash). YYSTR is taken from yytname. If YYRES is
838 null, do not copy; instead, return the length of what the result
839 would have been. */
840 static YYSIZE_T
841 yytnamerr (char *yyres, const char *yystr)
843 if (*yystr == '"')
845 YYSIZE_T yyn = 0;
846 char const *yyp = yystr;
848 for (;;)
849 switch (*++yyp)
851 case '\'':
852 case ',':
853 goto do_not_strip_quotes;
855 case '\\':
856 if (*++yyp != '\\')
857 goto do_not_strip_quotes;
858 /* Fall through. */
859 default:
860 if (yyres)
861 yyres[yyn] = *yyp;
862 yyn++;
863 break;
865 case '"':
866 if (yyres)
867 yyres[yyn] = '\0';
868 return yyn;
870 do_not_strip_quotes: ;
873 if (! yyres)
874 return yystrlen (yystr);
876 return yystpcpy (yyres, yystr) - yyres;
878 # endif
880 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
881 about the unexpected token YYTOKEN for the state stack whose top is
882 YYSSP.
884 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
885 not large enough to hold the message. In that case, also set
886 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
887 required number of bytes is too large to store. */
888 static int
889 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
890 yytype_int16 *yyssp, int yytoken)
892 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
893 YYSIZE_T yysize = yysize0;
894 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
895 /* Internationalized format string. */
896 const char *yyformat = YY_NULLPTR;
897 /* Arguments of yyformat. */
898 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
899 /* Number of reported tokens (one for the "unexpected", one per
900 "expected"). */
901 int yycount = 0;
903 /* There are many possibilities here to consider:
904 - If this state is a consistent state with a default action, then
905 the only way this function was invoked is if the default action
906 is an error action. In that case, don't check for expected
907 tokens because there are none.
908 - The only way there can be no lookahead present (in yychar) is if
909 this state is a consistent state with a default action. Thus,
910 detecting the absence of a lookahead is sufficient to determine
911 that there is no unexpected or expected token to report. In that
912 case, just report a simple "syntax error".
913 - Don't assume there isn't a lookahead just because this state is a
914 consistent state with a default action. There might have been a
915 previous inconsistent state, consistent state with a non-default
916 action, or user semantic action that manipulated yychar.
917 - Of course, the expected token list depends on states to have
918 correct lookahead information, and it depends on the parser not
919 to perform extra reductions after fetching a lookahead from the
920 scanner and before detecting a syntax error. Thus, state merging
921 (from LALR or IELR) and default reductions corrupt the expected
922 token list. However, the list is correct for canonical LR with
923 one exception: it will still contain any token that will not be
924 accepted due to an error action in a later state.
926 if (yytoken != YYEMPTY)
928 int yyn = yypact[*yyssp];
929 yyarg[yycount++] = yytname[yytoken];
930 if (!yypact_value_is_default (yyn))
932 /* Start YYX at -YYN if negative to avoid negative indexes in
933 YYCHECK. In other words, skip the first -YYN actions for
934 this state because they are default actions. */
935 int yyxbegin = yyn < 0 ? -yyn : 0;
936 /* Stay within bounds of both yycheck and yytname. */
937 int yychecklim = YYLAST - yyn + 1;
938 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
939 int yyx;
941 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
942 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
943 && !yytable_value_is_error (yytable[yyx + yyn]))
945 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
947 yycount = 1;
948 yysize = yysize0;
949 break;
951 yyarg[yycount++] = yytname[yyx];
953 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
954 if (! (yysize <= yysize1
955 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
956 return 2;
957 yysize = yysize1;
963 switch (yycount)
965 # define YYCASE_(N, S) \
966 case N: \
967 yyformat = S; \
968 break
969 YYCASE_(0, YY_("syntax error"));
970 YYCASE_(1, YY_("syntax error, unexpected %s"));
971 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
972 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
973 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
974 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
975 # undef YYCASE_
979 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
980 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
981 return 2;
982 yysize = yysize1;
985 if (*yymsg_alloc < yysize)
987 *yymsg_alloc = 2 * yysize;
988 if (! (yysize <= *yymsg_alloc
989 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
990 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
991 return 1;
994 /* Avoid sprintf, as that infringes on the user's name space.
995 Don't have undefined behavior even if the translation
996 produced a string with the wrong number of "%s"s. */
998 char *yyp = *yymsg;
999 int yyi = 0;
1000 while ((*yyp = *yyformat) != '\0')
1001 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1003 yyp += yytnamerr (yyp, yyarg[yyi++]);
1004 yyformat += 2;
1006 else
1008 yyp++;
1009 yyformat++;
1012 return 0;
1014 #endif /* YYERROR_VERBOSE */
1016 /*-----------------------------------------------.
1017 | Release the memory associated to this symbol. |
1018 `-----------------------------------------------*/
1020 static void
1021 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1023 YYUSE (yyvaluep);
1024 if (!yymsg)
1025 yymsg = "Deleting";
1026 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1028 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1029 YYUSE (yytype);
1030 YY_IGNORE_MAYBE_UNINITIALIZED_END
1036 /* The lookahead symbol. */
1037 int yychar;
1039 /* The semantic value of the lookahead symbol. */
1040 YYSTYPE yylval;
1041 /* Number of syntax errors so far. */
1042 int yynerrs;
1045 /*----------.
1046 | yyparse. |
1047 `----------*/
1050 yyparse (void)
1052 int yystate;
1053 /* Number of tokens to shift before error messages enabled. */
1054 int yyerrstatus;
1056 /* The stacks and their tools:
1057 'yyss': related to states.
1058 'yyvs': related to semantic values.
1060 Refer to the stacks through separate pointers, to allow yyoverflow
1061 to reallocate them elsewhere. */
1063 /* The state stack. */
1064 yytype_int16 yyssa[YYINITDEPTH];
1065 yytype_int16 *yyss;
1066 yytype_int16 *yyssp;
1068 /* The semantic value stack. */
1069 YYSTYPE yyvsa[YYINITDEPTH];
1070 YYSTYPE *yyvs;
1071 YYSTYPE *yyvsp;
1073 YYSIZE_T yystacksize;
1075 int yyn;
1076 int yyresult;
1077 /* Lookahead token as an internal (translated) token number. */
1078 int yytoken = 0;
1079 /* The variables used to return semantic value and location from the
1080 action routines. */
1081 YYSTYPE yyval;
1083 #if YYERROR_VERBOSE
1084 /* Buffer for error messages, and its allocated size. */
1085 char yymsgbuf[128];
1086 char *yymsg = yymsgbuf;
1087 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1088 #endif
1090 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1092 /* The number of symbols on the RHS of the reduced rule.
1093 Keep to zero when no symbol should be popped. */
1094 int yylen = 0;
1096 yyssp = yyss = yyssa;
1097 yyvsp = yyvs = yyvsa;
1098 yystacksize = YYINITDEPTH;
1100 YYDPRINTF ((stderr, "Starting parse\n"));
1102 yystate = 0;
1103 yyerrstatus = 0;
1104 yynerrs = 0;
1105 yychar = YYEMPTY; /* Cause a token to be read. */
1106 goto yysetstate;
1108 /*------------------------------------------------------------.
1109 | yynewstate -- Push a new state, which is found in yystate. |
1110 `------------------------------------------------------------*/
1111 yynewstate:
1112 /* In all cases, when you get here, the value and location stacks
1113 have just been pushed. So pushing a state here evens the stacks. */
1114 yyssp++;
1116 yysetstate:
1117 *yyssp = yystate;
1119 if (yyss + yystacksize - 1 <= yyssp)
1121 /* Get the current used size of the three stacks, in elements. */
1122 YYSIZE_T yysize = yyssp - yyss + 1;
1124 #ifdef yyoverflow
1126 /* Give user a chance to reallocate the stack. Use copies of
1127 these so that the &'s don't force the real ones into
1128 memory. */
1129 YYSTYPE *yyvs1 = yyvs;
1130 yytype_int16 *yyss1 = yyss;
1132 /* Each stack pointer address is followed by the size of the
1133 data in use in that stack, in bytes. This used to be a
1134 conditional around just the two extra args, but that might
1135 be undefined if yyoverflow is a macro. */
1136 yyoverflow (YY_("memory exhausted"),
1137 &yyss1, yysize * sizeof (*yyssp),
1138 &yyvs1, yysize * sizeof (*yyvsp),
1139 &yystacksize);
1141 yyss = yyss1;
1142 yyvs = yyvs1;
1144 #else /* no yyoverflow */
1145 # ifndef YYSTACK_RELOCATE
1146 goto yyexhaustedlab;
1147 # else
1148 /* Extend the stack our own way. */
1149 if (YYMAXDEPTH <= yystacksize)
1150 goto yyexhaustedlab;
1151 yystacksize *= 2;
1152 if (YYMAXDEPTH < yystacksize)
1153 yystacksize = YYMAXDEPTH;
1156 yytype_int16 *yyss1 = yyss;
1157 union yyalloc *yyptr =
1158 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1159 if (! yyptr)
1160 goto yyexhaustedlab;
1161 YYSTACK_RELOCATE (yyss_alloc, yyss);
1162 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1163 # undef YYSTACK_RELOCATE
1164 if (yyss1 != yyssa)
1165 YYSTACK_FREE (yyss1);
1167 # endif
1168 #endif /* no yyoverflow */
1170 yyssp = yyss + yysize - 1;
1171 yyvsp = yyvs + yysize - 1;
1173 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1174 (unsigned long int) yystacksize));
1176 if (yyss + yystacksize - 1 <= yyssp)
1177 YYABORT;
1180 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1182 if (yystate == YYFINAL)
1183 YYACCEPT;
1185 goto yybackup;
1187 /*-----------.
1188 | yybackup. |
1189 `-----------*/
1190 yybackup:
1192 /* Do appropriate processing given the current state. Read a
1193 lookahead token if we need one and don't already have one. */
1195 /* First try to decide what to do without reference to lookahead token. */
1196 yyn = yypact[yystate];
1197 if (yypact_value_is_default (yyn))
1198 goto yydefault;
1200 /* Not known => get a lookahead token if don't already have one. */
1202 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1203 if (yychar == YYEMPTY)
1205 YYDPRINTF ((stderr, "Reading a token: "));
1206 yychar = yylex ();
1209 if (yychar <= YYEOF)
1211 yychar = yytoken = YYEOF;
1212 YYDPRINTF ((stderr, "Now at end of input.\n"));
1214 else
1216 yytoken = YYTRANSLATE (yychar);
1217 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1220 /* If the proper action on seeing token YYTOKEN is to reduce or to
1221 detect an error, take that action. */
1222 yyn += yytoken;
1223 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1224 goto yydefault;
1225 yyn = yytable[yyn];
1226 if (yyn <= 0)
1228 if (yytable_value_is_error (yyn))
1229 goto yyerrlab;
1230 yyn = -yyn;
1231 goto yyreduce;
1234 /* Count tokens shifted since error; after three, turn off error
1235 status. */
1236 if (yyerrstatus)
1237 yyerrstatus--;
1239 /* Shift the lookahead token. */
1240 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1242 /* Discard the shifted token. */
1243 yychar = YYEMPTY;
1245 yystate = yyn;
1246 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1247 *++yyvsp = yylval;
1248 YY_IGNORE_MAYBE_UNINITIALIZED_END
1250 goto yynewstate;
1253 /*-----------------------------------------------------------.
1254 | yydefault -- do the default action for the current state. |
1255 `-----------------------------------------------------------*/
1256 yydefault:
1257 yyn = yydefact[yystate];
1258 if (yyn == 0)
1259 goto yyerrlab;
1260 goto yyreduce;
1263 /*-----------------------------.
1264 | yyreduce -- Do a reduction. |
1265 `-----------------------------*/
1266 yyreduce:
1267 /* yyn is the number of a rule to reduce with. */
1268 yylen = yyr2[yyn];
1270 /* If YYLEN is nonzero, implement the default value of the action:
1271 '$$ = $1'.
1273 Otherwise, the following line sets YYVAL to garbage.
1274 This behavior is undocumented and Bison
1275 users should not rely upon it. Assigning to YYVAL
1276 unconditionally makes the parser a bit smaller, and it avoids a
1277 GCC warning that YYVAL may be used uninitialized. */
1278 yyval = yyvsp[1-yylen];
1281 YY_REDUCE_PRINT (yyn);
1282 switch (yyn)
1284 case 4:
1285 #line 89 "sparql_parser.y" /* yacc.c:1646 */
1287 global_sparql_parser_state->result = (yyvsp[0].sval);
1289 #line 1290 "sparql_parser.c" /* yacc.c:1646 */
1290 break;
1292 case 5:
1293 #line 95 "sparql_parser.y" /* yacc.c:1646 */
1296 * We can't properly handle these in expressions, fortunately this
1297 * is probably only ever used by OS X as sole element in an
1298 * expression ie "False" (when Finder window selected our share
1299 * but no search string entered yet). Packet traces showed that OS
1300 * X Spotlight server then returns a failure (ie -1) which is what
1301 * we do here too by calling YYABORT.
1303 YYABORT;
1305 #line 1306 "sparql_parser.c" /* yacc.c:1646 */
1306 break;
1308 case 6:
1309 #line 118 "sparql_parser.y" /* yacc.c:1646 */
1311 if (strcmp((yyvsp[-2].sval), (yyvsp[0].sval)) != 0) {
1312 (yyval.sval) = talloc_asprintf(talloc_tos(), "{ %s } UNION { %s }", (yyvsp[-2].sval), (yyvsp[0].sval));
1313 } else {
1314 (yyval.sval) = talloc_asprintf(talloc_tos(), "%s", (yyvsp[-2].sval));
1317 #line 1318 "sparql_parser.c" /* yacc.c:1646 */
1318 break;
1320 case 7:
1321 #line 125 "sparql_parser.y" /* yacc.c:1646 */
1323 (yyval.sval) = (yyvsp[0].sval);
1325 #line 1326 "sparql_parser.c" /* yacc.c:1646 */
1326 break;
1328 case 8:
1329 #line 128 "sparql_parser.y" /* yacc.c:1646 */
1331 (yyval.sval) = (yyvsp[0].sval);
1333 #line 1334 "sparql_parser.c" /* yacc.c:1646 */
1334 break;
1336 case 9:
1337 #line 131 "sparql_parser.y" /* yacc.c:1646 */
1339 (yyval.sval) = talloc_asprintf(talloc_tos(), "%s", (yyvsp[-1].sval));
1341 #line 1342 "sparql_parser.c" /* yacc.c:1646 */
1342 break;
1344 case 10:
1345 #line 134 "sparql_parser.y" /* yacc.c:1646 */
1347 (yyval.sval) = talloc_asprintf(talloc_tos(), "%s . %s", (yyvsp[-2].sval), (yyvsp[0].sval));
1349 #line 1350 "sparql_parser.c" /* yacc.c:1646 */
1350 break;
1352 case 11:
1353 #line 137 "sparql_parser.y" /* yacc.c:1646 */
1355 if (strcmp((yyvsp[-2].sval), (yyvsp[0].sval)) != 0) {
1356 (yyval.sval) = talloc_asprintf(talloc_tos(), "{ %s } UNION { %s }", (yyvsp[-2].sval), (yyvsp[0].sval));
1357 } else {
1358 (yyval.sval) = talloc_asprintf(talloc_tos(), "%s", (yyvsp[-2].sval));
1361 #line 1362 "sparql_parser.c" /* yacc.c:1646 */
1362 break;
1364 case 12:
1365 #line 147 "sparql_parser.y" /* yacc.c:1646 */
1367 (yyval.sval) = map_expr((yyvsp[-4].sval), '=', (yyvsp[-1].sval));
1368 if ((yyval.sval) == NULL) YYABORT;
1370 #line 1371 "sparql_parser.c" /* yacc.c:1646 */
1371 break;
1373 case 13:
1374 #line 151 "sparql_parser.y" /* yacc.c:1646 */
1376 (yyval.sval) = map_expr((yyvsp[-4].sval), '!', (yyvsp[-1].sval));
1377 if ((yyval.sval) == NULL) YYABORT;
1379 #line 1380 "sparql_parser.c" /* yacc.c:1646 */
1380 break;
1382 case 14:
1383 #line 155 "sparql_parser.y" /* yacc.c:1646 */
1385 (yyval.sval) = map_expr((yyvsp[-4].sval), '<', (yyvsp[-1].sval));
1386 if ((yyval.sval) == NULL) YYABORT;
1388 #line 1389 "sparql_parser.c" /* yacc.c:1646 */
1389 break;
1391 case 15:
1392 #line 159 "sparql_parser.y" /* yacc.c:1646 */
1394 (yyval.sval) = map_expr((yyvsp[-4].sval), '>', (yyvsp[-1].sval));
1395 if ((yyval.sval) == NULL) YYABORT;
1397 #line 1398 "sparql_parser.c" /* yacc.c:1646 */
1398 break;
1400 case 16:
1401 #line 163 "sparql_parser.y" /* yacc.c:1646 */
1403 (yyval.sval) = map_expr((yyvsp[-5].sval), '=', (yyvsp[-2].sval));
1404 if ((yyval.sval) == NULL) YYABORT;
1406 #line 1407 "sparql_parser.c" /* yacc.c:1646 */
1407 break;
1409 case 17:
1410 #line 167 "sparql_parser.y" /* yacc.c:1646 */
1412 (yyval.sval) = map_expr((yyvsp[-5].sval), '!', (yyvsp[-2].sval));
1413 if ((yyval.sval) == NULL) YYABORT;
1415 #line 1416 "sparql_parser.c" /* yacc.c:1646 */
1416 break;
1418 case 18:
1419 #line 171 "sparql_parser.y" /* yacc.c:1646 */
1421 (yyval.sval) = map_expr((yyvsp[-5].sval), '<', (yyvsp[-2].sval));
1422 if ((yyval.sval) == NULL) YYABORT;
1424 #line 1425 "sparql_parser.c" /* yacc.c:1646 */
1425 break;
1427 case 19:
1428 #line 175 "sparql_parser.y" /* yacc.c:1646 */
1430 (yyval.sval) = map_expr((yyvsp[-5].sval), '>', (yyvsp[-2].sval));
1431 if ((yyval.sval) == NULL) YYABORT;
1433 #line 1434 "sparql_parser.c" /* yacc.c:1646 */
1434 break;
1436 case 20:
1437 #line 182 "sparql_parser.y" /* yacc.c:1646 */
1439 (yyval.sval) = map_daterange((yyvsp[-5].sval), (yyvsp[-3].tval), (yyvsp[-1].tval));
1440 if ((yyval.sval) == NULL) YYABORT;
1442 #line 1443 "sparql_parser.c" /* yacc.c:1646 */
1443 break;
1445 case 21:
1446 #line 189 "sparql_parser.y" /* yacc.c:1646 */
1447 {(yyval.tval) = isodate2unix((yyvsp[-1].sval));}
1448 #line 1449 "sparql_parser.c" /* yacc.c:1646 */
1449 break;
1451 case 22:
1452 #line 190 "sparql_parser.y" /* yacc.c:1646 */
1453 {(yyval.tval) = atoi((yyvsp[0].sval)) + SPRAW_TIME_OFFSET;}
1454 #line 1455 "sparql_parser.c" /* yacc.c:1646 */
1455 break;
1458 #line 1459 "sparql_parser.c" /* yacc.c:1646 */
1459 default: break;
1461 /* User semantic actions sometimes alter yychar, and that requires
1462 that yytoken be updated with the new translation. We take the
1463 approach of translating immediately before every use of yytoken.
1464 One alternative is translating here after every semantic action,
1465 but that translation would be missed if the semantic action invokes
1466 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1467 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1468 incorrect destructor might then be invoked immediately. In the
1469 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1470 to an incorrect destructor call or verbose syntax error message
1471 before the lookahead is translated. */
1472 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1474 YYPOPSTACK (yylen);
1475 yylen = 0;
1476 YY_STACK_PRINT (yyss, yyssp);
1478 *++yyvsp = yyval;
1480 /* Now 'shift' the result of the reduction. Determine what state
1481 that goes to, based on the state we popped back to and the rule
1482 number reduced by. */
1484 yyn = yyr1[yyn];
1486 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1487 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1488 yystate = yytable[yystate];
1489 else
1490 yystate = yydefgoto[yyn - YYNTOKENS];
1492 goto yynewstate;
1495 /*--------------------------------------.
1496 | yyerrlab -- here on detecting error. |
1497 `--------------------------------------*/
1498 yyerrlab:
1499 /* Make sure we have latest lookahead translation. See comments at
1500 user semantic actions for why this is necessary. */
1501 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1503 /* If not already recovering from an error, report this error. */
1504 if (!yyerrstatus)
1506 ++yynerrs;
1507 #if ! YYERROR_VERBOSE
1508 yyerror (YY_("syntax error"));
1509 #else
1510 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1511 yyssp, yytoken)
1513 char const *yymsgp = YY_("syntax error");
1514 int yysyntax_error_status;
1515 yysyntax_error_status = YYSYNTAX_ERROR;
1516 if (yysyntax_error_status == 0)
1517 yymsgp = yymsg;
1518 else if (yysyntax_error_status == 1)
1520 if (yymsg != yymsgbuf)
1521 YYSTACK_FREE (yymsg);
1522 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1523 if (!yymsg)
1525 yymsg = yymsgbuf;
1526 yymsg_alloc = sizeof yymsgbuf;
1527 yysyntax_error_status = 2;
1529 else
1531 yysyntax_error_status = YYSYNTAX_ERROR;
1532 yymsgp = yymsg;
1535 yyerror (yymsgp);
1536 if (yysyntax_error_status == 2)
1537 goto yyexhaustedlab;
1539 # undef YYSYNTAX_ERROR
1540 #endif
1545 if (yyerrstatus == 3)
1547 /* If just tried and failed to reuse lookahead token after an
1548 error, discard it. */
1550 if (yychar <= YYEOF)
1552 /* Return failure if at end of input. */
1553 if (yychar == YYEOF)
1554 YYABORT;
1556 else
1558 yydestruct ("Error: discarding",
1559 yytoken, &yylval);
1560 yychar = YYEMPTY;
1564 /* Else will try to reuse lookahead token after shifting the error
1565 token. */
1566 goto yyerrlab1;
1569 /*---------------------------------------------------.
1570 | yyerrorlab -- error raised explicitly by YYERROR. |
1571 `---------------------------------------------------*/
1572 yyerrorlab:
1574 /* Pacify compilers like GCC when the user code never invokes
1575 YYERROR and the label yyerrorlab therefore never appears in user
1576 code. */
1577 if (/*CONSTCOND*/ 0)
1578 goto yyerrorlab;
1580 /* Do not reclaim the symbols of the rule whose action triggered
1581 this YYERROR. */
1582 YYPOPSTACK (yylen);
1583 yylen = 0;
1584 YY_STACK_PRINT (yyss, yyssp);
1585 yystate = *yyssp;
1586 goto yyerrlab1;
1589 /*-------------------------------------------------------------.
1590 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1591 `-------------------------------------------------------------*/
1592 yyerrlab1:
1593 yyerrstatus = 3; /* Each real token shifted decrements this. */
1595 for (;;)
1597 yyn = yypact[yystate];
1598 if (!yypact_value_is_default (yyn))
1600 yyn += YYTERROR;
1601 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1603 yyn = yytable[yyn];
1604 if (0 < yyn)
1605 break;
1609 /* Pop the current state because it cannot handle the error token. */
1610 if (yyssp == yyss)
1611 YYABORT;
1614 yydestruct ("Error: popping",
1615 yystos[yystate], yyvsp);
1616 YYPOPSTACK (1);
1617 yystate = *yyssp;
1618 YY_STACK_PRINT (yyss, yyssp);
1621 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1622 *++yyvsp = yylval;
1623 YY_IGNORE_MAYBE_UNINITIALIZED_END
1626 /* Shift the error token. */
1627 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1629 yystate = yyn;
1630 goto yynewstate;
1633 /*-------------------------------------.
1634 | yyacceptlab -- YYACCEPT comes here. |
1635 `-------------------------------------*/
1636 yyacceptlab:
1637 yyresult = 0;
1638 goto yyreturn;
1640 /*-----------------------------------.
1641 | yyabortlab -- YYABORT comes here. |
1642 `-----------------------------------*/
1643 yyabortlab:
1644 yyresult = 1;
1645 goto yyreturn;
1647 #if !defined yyoverflow || YYERROR_VERBOSE
1648 /*-------------------------------------------------.
1649 | yyexhaustedlab -- memory exhaustion comes here. |
1650 `-------------------------------------------------*/
1651 yyexhaustedlab:
1652 yyerror (YY_("memory exhausted"));
1653 yyresult = 2;
1654 /* Fall through. */
1655 #endif
1657 yyreturn:
1658 if (yychar != YYEMPTY)
1660 /* Make sure we have latest lookahead translation. See comments at
1661 user semantic actions for why this is necessary. */
1662 yytoken = YYTRANSLATE (yychar);
1663 yydestruct ("Cleanup: discarding lookahead",
1664 yytoken, &yylval);
1666 /* Do not reclaim the symbols of the rule whose action triggered
1667 this YYABORT or YYACCEPT. */
1668 YYPOPSTACK (yylen);
1669 YY_STACK_PRINT (yyss, yyssp);
1670 while (yyssp != yyss)
1672 yydestruct ("Cleanup: popping",
1673 yystos[*yyssp], yyvsp);
1674 YYPOPSTACK (1);
1676 #ifndef yyoverflow
1677 if (yyss != yyssa)
1678 YYSTACK_FREE (yyss);
1679 #endif
1680 #if YYERROR_VERBOSE
1681 if (yymsg != yymsgbuf)
1682 YYSTACK_FREE (yymsg);
1683 #endif
1684 return yyresult;
1686 #line 193 "sparql_parser.y" /* yacc.c:1906 */
1689 static time_t isodate2unix(const char *s)
1691 struct tm tm;
1692 const char *p;
1694 p = strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm);
1695 if (p == NULL) {
1696 return (time_t)-1;
1698 return mktime(&tm);
1701 static const char *map_daterange(const char *dateattr,
1702 time_t date1, time_t date2)
1704 struct sparql_parser_state *s = global_sparql_parser_state;
1705 int result = 0;
1706 char *sparql = NULL;
1707 const struct sl_attr_map *p;
1708 struct tm *tmp;
1709 char buf1[64], buf2[64];
1711 if (s->var == 'z') {
1712 return NULL;
1715 tmp = localtime(&date1);
1716 if (tmp == NULL) {
1717 return NULL;
1719 result = strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1720 if (result == 0) {
1721 return NULL;
1724 tmp = localtime(&date2);
1725 if (tmp == NULL) {
1726 return NULL;
1728 result = strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
1729 if (result == 0) {
1730 return NULL;
1733 p = sl_attr_map_by_spotlight(dateattr);
1734 if (p == NULL) {
1735 return NULL;
1738 sparql = talloc_asprintf(talloc_tos(),
1739 "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')",
1740 p->sparql_attr,
1741 s->var,
1742 s->var,
1743 buf1,
1744 s->var,
1745 buf2);
1746 if (sparql == NULL) {
1747 return NULL;
1750 s->var++;
1751 return sparql;
1754 static char *map_type_search(const char *attr, char op, const char *val)
1756 char *result = NULL;
1757 const char *sparqlAttr;
1758 const struct sl_type_map *p;
1760 p = sl_type_map_by_spotlight(val);
1761 if (p == NULL) {
1762 return NULL;
1765 switch (p->type) {
1766 case kMDTypeMapRDF:
1767 sparqlAttr = "rdf:type";
1768 break;
1769 case kMDTypeMapMime:
1770 sparqlAttr = "nie:mimeType";
1771 break;
1772 default:
1773 return NULL;
1776 result = talloc_asprintf(talloc_tos(), "?obj %s '%s'",
1777 sparqlAttr,
1778 p->sparql_type);
1779 if (result == NULL) {
1780 return NULL;
1783 return result;
1786 static const char *map_expr(const char *attr, char op, const char *val)
1788 struct sparql_parser_state *s = global_sparql_parser_state;
1789 int result = 0;
1790 char *sparql = NULL;
1791 const struct sl_attr_map *p;
1792 time_t t;
1793 struct tm *tmp;
1794 char buf1[64];
1795 char *q;
1796 const char *start;
1798 if (s->var == 'z') {
1799 return NULL;
1802 p = sl_attr_map_by_spotlight(attr);
1803 if (p == NULL) {
1804 return NULL;
1807 if ((p->type != ssmt_type) && (p->sparql_attr == NULL)) {
1808 yyerror("unsupported Spotlight attribute");
1809 return NULL;
1812 switch (p->type) {
1813 case ssmt_bool:
1814 sparql = talloc_asprintf(talloc_tos(), "?obj %s '%s'",
1815 p->sparql_attr, val);
1816 if (sparql == NULL) {
1817 return NULL;
1819 break;
1821 case ssmt_num:
1822 sparql = talloc_asprintf(talloc_tos(),
1823 "?obj %s ?%c FILTER(?%c %c%c '%s')",
1824 p->sparql_attr,
1825 s->var,
1826 s->var,
1828 /* append '=' to '!' */
1829 op == '!' ? '=' : ' ',
1830 val);
1831 if (sparql == NULL) {
1832 return NULL;
1834 s->var++;
1835 break;
1837 case ssmt_str:
1838 q = talloc_strdup(talloc_tos(), "");
1839 if (q == NULL) {
1840 return NULL;
1842 start = val;
1843 while (*val) {
1844 if (*val != '*') {
1845 val++;
1846 continue;
1848 if (val > start) {
1849 q = talloc_strndup_append(q, start, val - start);
1850 if (q == NULL) {
1851 return NULL;
1854 q = talloc_strdup_append(q, ".*");
1855 if (q == NULL) {
1856 return NULL;
1858 val++;
1859 start = val;
1861 if (val > start) {
1862 q = talloc_strndup_append(q, start, val - start);
1863 if (q == NULL) {
1864 return NULL;
1867 sparql = talloc_asprintf(talloc_tos(),
1868 "?obj %s ?%c "
1869 "FILTER(regex(?%c, '^%s$', 'i'))",
1870 p->sparql_attr,
1871 s->var,
1872 s->var,
1874 TALLOC_FREE(q);
1875 if (sparql == NULL) {
1876 return NULL;
1878 s->var++;
1879 break;
1881 case ssmt_fts:
1882 sparql = talloc_asprintf(talloc_tos(), "?obj %s '%s'",
1883 p->sparql_attr, val);
1884 if (sparql == NULL) {
1885 return NULL;
1887 break;
1889 case ssmt_date:
1890 t = atoi(val) + SPRAW_TIME_OFFSET;
1891 tmp = localtime(&t);
1892 if (tmp == NULL) {
1893 return NULL;
1895 result = strftime(buf1, sizeof(buf1),
1896 "%Y-%m-%dT%H:%M:%SZ", tmp);
1897 if (result == 0) {
1898 return NULL;
1900 sparql = talloc_asprintf(talloc_tos(),
1901 "?obj %s ?%c FILTER(?%c %c '%s')",
1902 p->sparql_attr,
1903 s->var,
1904 s->var,
1906 buf1);
1907 if (sparql == NULL) {
1908 return NULL;
1910 s->var++;
1911 break;
1913 case ssmt_type:
1914 sparql = map_type_search(attr, op, val);
1915 if (sparql == NULL) {
1916 return NULL;
1918 break;
1920 default:
1921 return NULL;
1924 return sparql;
1927 void yyerror(const char *str)
1929 DEBUG(1, ("yyerror: %s\n", str));
1932 int yywrap(void)
1934 return 1;
1938 * Map a Spotlight RAW query string to a SPARQL query string
1940 bool map_spotlight_to_sparql_query(struct sl_query *slq)
1942 struct sparql_parser_state s = {
1943 .frame = talloc_stackframe(),
1944 .var = 'a',
1946 int result;
1948 s.s = yy_scan_string(slq->query_string);
1949 if (s.s == NULL) {
1950 TALLOC_FREE(s.frame);
1951 return false;
1953 global_sparql_parser_state = &s;
1954 result = yyparse();
1955 global_sparql_parser_state = NULL;
1956 yy_delete_buffer(s.s);
1958 if (result != 0) {
1959 TALLOC_FREE(s.frame);
1960 return false;
1963 slq->sparql_query = talloc_asprintf(slq,
1964 "SELECT ?url WHERE { %s . ?obj nie:url ?url . "
1965 "FILTER(tracker:uri-is-descendant('file://%s/', ?url)) }",
1966 s.result, slq->path_scope);
1967 TALLOC_FREE(s.frame);
1968 if (slq->sparql_query == NULL) {
1969 return false;
1972 return true;