1 /* A Bison parser, made by GNU Bison 2.5. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2011 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. */
47 #define YYBISON_VERSION "2.5"
50 #define YYSKELETON_NAME "yacc.c"
61 /* Using locations. */
62 #define YYLSP_NEEDED 0
66 /* Copy the first part of user declarations. */
68 /* Line 268 of yacc.c */
69 #line 1 "slmod_sparql_parser.y"
71 #include <atalk/standards.h>
80 #include <atalk/talloc.h>
81 #include <atalk/logger.h>
82 #include <atalk/errchk.h>
83 #include <atalk/spotlight.h>
85 #include "slmod_sparql_map.h"
87 struct yy_buffer_state;
88 typedef struct yy_buffer_state *YY_BUFFER_STATE;
89 extern int yylex (void);
90 extern void yyerror (char const *);
91 extern void *yyterminate(void);
92 extern YY_BUFFER_STATE yy_scan_string( const char *str);
93 extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
95 /* forward declarations */
96 static const char *map_expr(const char *attr, char op, const char *val);
97 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2);
98 static time_t isodate2unix(const char *s);
100 /* global vars, eg needed by the lexer */
104 static gchar *ssp_result;
105 static char sparqlvar;
108 /* Line 268 of yacc.c */
109 #line 110 "slmod_sparql_parser.c"
111 /* Enabling traces. */
116 /* Enabling verbose error messages. */
117 #ifdef YYERROR_VERBOSE
118 # undef YYERROR_VERBOSE
119 # define YYERROR_VERBOSE 1
121 # define YYERROR_VERBOSE 1
124 /* Enabling the token table. */
125 #ifndef YYTOKEN_TABLE
126 # define YYTOKEN_TABLE 0
133 /* Put the tokens into the symbol table, so that GDB and other debuggers
155 #define FUNC_INRANGE 260
171 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
172 typedef union YYSTYPE
175 /* Line 293 of yacc.c */
176 #line 45 "slmod_sparql_parser.y"
185 /* Line 293 of yacc.c */
186 #line 187 "slmod_sparql_parser.c"
188 # define YYSTYPE_IS_TRIVIAL 1
189 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
190 # define YYSTYPE_IS_DECLARED 1
193 /* "%code provides" blocks. */
195 /* Line 340 of yacc.c */
196 #line 39 "slmod_sparql_parser.y"
198 #define SPRAW_TIME_OFFSET 978307200
199 extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
200 extern slq_t *ssp_slq;
204 /* Line 340 of yacc.c */
205 #line 206 "slmod_sparql_parser.c"
207 /* Copy the second part of user declarations. */
210 /* Line 343 of yacc.c */
211 #line 212 "slmod_sparql_parser.c"
218 typedef YYTYPE_UINT8 yytype_uint8;
220 typedef unsigned char yytype_uint8;
224 typedef YYTYPE_INT8 yytype_int8;
225 #elif (defined __STDC__ || defined __C99__FUNC__ \
226 || defined __cplusplus || defined _MSC_VER)
227 typedef signed char yytype_int8;
229 typedef short int yytype_int8;
233 typedef YYTYPE_UINT16 yytype_uint16;
235 typedef unsigned short int yytype_uint16;
239 typedef YYTYPE_INT16 yytype_int16;
241 typedef short int yytype_int16;
245 # ifdef __SIZE_TYPE__
246 # define YYSIZE_T __SIZE_TYPE__
247 # elif defined size_t
248 # define YYSIZE_T size_t
249 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
250 || defined __cplusplus || defined _MSC_VER)
251 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
252 # define YYSIZE_T size_t
254 # define YYSIZE_T unsigned int
258 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
261 # if defined YYENABLE_NLS && YYENABLE_NLS
263 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
264 # define YY_(msgid) dgettext ("bison-runtime", msgid)
268 # define YY_(msgid) msgid
272 /* Suppress unused-variable warnings by "using" E. */
273 #if ! defined lint || defined __GNUC__
274 # define YYUSE(e) ((void) (e))
276 # define YYUSE(e) /* empty */
279 /* Identity function, used to suppress warnings about constant conditions. */
283 #if (defined __STDC__ || defined __C99__FUNC__ \
284 || defined __cplusplus || defined _MSC_VER)
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
304 # define YYSTACK_ALLOC __builtin_alloca
305 # elif defined __BUILTIN_VA_ARG_INCR
306 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
308 # define YYSTACK_ALLOC __alloca
309 # elif defined _MSC_VER
310 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
311 # define alloca _alloca
313 # define YYSTACK_ALLOC alloca
314 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
315 || defined __cplusplus || defined _MSC_VER)
316 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
317 # ifndef EXIT_SUCCESS
318 # define EXIT_SUCCESS 0
325 # ifdef YYSTACK_ALLOC
326 /* Pacify GCC's `empty if-body' warning. */
327 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (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 */
336 # define YYSTACK_ALLOC YYMALLOC
337 # define YYSTACK_FREE YYFREE
338 # ifndef YYSTACK_ALLOC_MAXIMUM
339 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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
350 # define YYMALLOC malloc
351 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
352 || defined __cplusplus || defined _MSC_VER)
353 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
358 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
359 || defined __cplusplus || defined _MSC_VER)
360 void free (void *); /* INFRINGES ON USER NAME SPACE */
364 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
367 #if (! defined yyoverflow \
368 && (! defined __cplusplus \
369 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
371 /* A type that is properly aligned for any stack member. */
374 yytype_int16 yyss_alloc;
378 /* The size of the maximum gap between one aligned stack and the next. */
379 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
381 /* The size of an array large to enough to hold all stacks, each with
383 # define YYSTACK_BYTES(N) \
384 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
385 + YYSTACK_GAP_MAXIMUM)
387 # define YYCOPY_NEEDED 1
389 /* Relocate STACK from its old location to the new one. The
390 local variables YYSIZE and YYSTACKSIZE give the old and new number of
391 elements in the stack, and YYPTR gives the new location of the
392 stack. Advance YYPTR to a properly aligned location for the next
394 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
397 YYSIZE_T yynewbytes; \
398 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
399 Stack = &yyptr->Stack_alloc; \
400 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
401 yyptr += yynewbytes / sizeof (*yyptr); \
407 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
408 /* Copy COUNT objects from FROM to TO. The source and destination do
411 # if defined __GNUC__ && 1 < __GNUC__
412 # define YYCOPY(To, From, Count) \
413 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
415 # define YYCOPY(To, From, Count) \
419 for (yyi = 0; yyi < (Count); yyi++) \
420 (To)[yyi] = (From)[yyi]; \
425 #endif /* !YYCOPY_NEEDED */
427 /* YYFINAL -- State number of the termination state. */
429 /* YYLAST -- Last index in YYTABLE. */
432 /* YYNTOKENS -- Number of terminals. */
434 /* YYNNTS -- Number of nonterminals. */
436 /* YYNRULES -- Number of rules. */
438 /* YYNRULES -- Number of states. */
441 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
443 #define YYMAXUTOK 271
445 #define YYTRANSLATE(YYX) \
446 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
448 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
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,
482 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
484 static const yytype_uint8 yyprhs[] =
486 0, 0, 3, 4, 7, 9, 11, 15, 17, 19,
487 23, 27, 31, 37, 43, 49, 55, 62, 69, 76,
491 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
492 static const yytype_int8 yyrhs[] =
494 18, 0, -1, -1, 18, 19, -1, 20, -1, 4,
495 -1, 21, 16, 21, -1, 21, -1, 22, -1, 7,
496 20, 8, -1, 20, 15, 20, -1, 20, 16, 20,
497 -1, 3, 9, 14, 3, 14, -1, 3, 10, 14,
498 3, 14, -1, 3, 12, 14, 3, 14, -1, 3,
499 11, 14, 3, 14, -1, 3, 9, 14, 3, 14,
500 3, -1, 3, 10, 14, 3, 14, 3, -1, 3,
501 12, 14, 3, 14, 3, -1, 3, 11, 14, 3,
502 14, 3, -1, 5, 7, 3, 13, 23, 13, 23,
503 8, -1, 6, 7, 3, 8, -1, 3, -1
506 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
507 static const yytype_uint8 yyrline[] =
509 0, 67, 67, 69, 73, 83, 89, 95, 96, 97,
510 98, 99, 108, 109, 110, 111, 112, 113, 114, 115,
515 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
516 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
517 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
518 static const char *const yytname[] =
520 "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE",
521 "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
522 "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
523 "function", "date", 0
528 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
530 static const yytype_uint16 yytoknum[] =
532 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
533 265, 266, 267, 268, 269, 270, 271
537 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
538 static const yytype_uint8 yyr1[] =
540 0, 17, 18, 18, 19, 20, 20, 20, 20, 20,
541 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
545 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
546 static const yytype_uint8 yyr2[] =
548 0, 2, 0, 2, 1, 1, 3, 1, 1, 3,
549 3, 3, 5, 5, 5, 5, 6, 6, 6, 6,
553 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
554 Performed when YYTABLE doesn't specify something else to do. Zero
555 means the default is an error. */
556 static const yytype_uint8 yydefact[] =
558 2, 0, 1, 0, 5, 0, 0, 3, 4, 7,
559 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
560 0, 0, 0, 0, 0, 9, 10, 11, 6, 0,
561 0, 0, 0, 0, 12, 13, 15, 14, 22, 0,
562 0, 16, 17, 19, 18, 0, 0, 0, 0, 21,
566 /* YYDEFGOTO[NTERM-NUM]. */
567 static const yytype_int8 yydefgoto[] =
569 -1, 1, 7, 8, 9, 10, 40
572 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
574 #define YYPACT_NINF -10
575 static const yytype_int8 yypact[] =
577 -10, 10, -10, 9, -10, -2, -1, -10, 8, -9,
578 -10, 2, 12, 13, 14, 26, -7, -1, -1, 27,
579 28, 29, 30, 31, 22, -10, 20, -10, -10, 23,
580 24, 25, 32, 19, 37, 38, 39, 40, -10, 41,
581 34, -10, -10, -10, -10, 42, 19, 36, 43, -10,
585 /* YYPGOTO[NTERM-NUM]. */
586 static const yytype_int8 yypgoto[] =
588 -10, -10, -10, -6, 33, -10, 3
591 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
592 positive, shift that token. If negative, reduce the rule which
593 number is the opposite. If YYTABLE_NINF, syntax error. */
594 #define YYTABLE_NINF -1
595 static const yytype_uint8 yytable[] =
597 16, 25, 3, 4, 5, 15, 6, 19, 17, 18,
598 2, 26, 27, 3, 4, 5, 20, 6, 11, 12,
599 13, 14, 38, 17, 18, 39, 21, 22, 23, 24,
600 3, 29, 30, 31, 32, 33, 18, 34, 35, 36,
601 41, 42, 43, 44, 49, 47, 37, 46, 45, 48,
605 #define yypact_value_is_default(yystate) \
608 #define yytable_value_is_error(yytable_value) \
611 static const yytype_int8 yycheck[] =
613 6, 8, 3, 4, 5, 7, 7, 16, 15, 16,
614 0, 17, 18, 3, 4, 5, 14, 7, 9, 10,
615 11, 12, 3, 15, 16, 6, 14, 14, 14, 3,
616 3, 3, 3, 3, 3, 13, 16, 14, 14, 14,
617 3, 3, 3, 3, 8, 3, 14, 13, 7, 46,
621 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
622 symbol of state STATE-NUM. */
623 static const yytype_uint8 yystos[] =
625 0, 18, 0, 3, 4, 5, 7, 19, 20, 21,
626 22, 9, 10, 11, 12, 7, 20, 15, 16, 16,
627 14, 14, 14, 14, 3, 8, 20, 20, 21, 3,
628 3, 3, 3, 13, 14, 14, 14, 14, 3, 6,
629 23, 3, 3, 3, 3, 7, 13, 3, 23, 8,
633 #define yyerrok (yyerrstatus = 0)
634 #define yyclearin (yychar = YYEMPTY)
638 #define YYACCEPT goto yyacceptlab
639 #define YYABORT goto yyabortlab
640 #define YYERROR goto yyerrorlab
643 /* Like YYERROR except do call yyerror. This remains here temporarily
644 to ease the transition to the new meaning of YYERROR, for GCC.
645 Once GCC version 2 has supplanted version 1, this can go. However,
646 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
647 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
650 #define YYFAIL goto yyerrlab
652 /* This is here to suppress warnings from the GCC cpp's
653 -Wunused-macros. Normally we don't worry about that warning, but
654 some users do, and we want to make it easy for users to remove
655 YYFAIL uses, which will produce warnings from Bison 2.5. */
658 #define YYRECOVERING() (!!yyerrstatus)
660 #define YYBACKUP(Token, Value) \
662 if (yychar == YYEMPTY && yylen == 1) \
671 yyerror (YY_("syntax error: cannot back up")); \
678 #define YYERRCODE 256
681 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
682 If N is 0, then set CURRENT to the empty location which ends
683 the previous symbol: RHS[0] (always defined). */
685 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
686 #ifndef YYLLOC_DEFAULT
687 # define YYLLOC_DEFAULT(Current, Rhs, N) \
691 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
692 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
693 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
694 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
698 (Current).first_line = (Current).last_line = \
699 YYRHSLOC (Rhs, 0).last_line; \
700 (Current).first_column = (Current).last_column = \
701 YYRHSLOC (Rhs, 0).last_column; \
707 /* This macro is provided for backward compatibility. */
709 #ifndef YY_LOCATION_PRINT
710 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
714 /* YYLEX -- calling `yylex' with the right arguments. */
717 # define YYLEX yylex (YYLEX_PARAM)
719 # define YYLEX yylex ()
722 /* Enable debugging if requested. */
726 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
727 # define YYFPRINTF fprintf
730 # define YYDPRINTF(Args) \
736 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
740 YYFPRINTF (stderr, "%s ", Title); \
741 yy_symbol_print (stderr, \
743 YYFPRINTF (stderr, "\n"); \
748 /*--------------------------------.
749 | Print this symbol on YYOUTPUT. |
750 `--------------------------------*/
753 #if (defined __STDC__ || defined __C99__FUNC__ \
754 || defined __cplusplus || defined _MSC_VER)
756 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
759 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
762 YYSTYPE const * const yyvaluep;
768 if (yytype < YYNTOKENS)
769 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
781 /*--------------------------------.
782 | Print this symbol on YYOUTPUT. |
783 `--------------------------------*/
785 #if (defined __STDC__ || defined __C99__FUNC__ \
786 || defined __cplusplus || defined _MSC_VER)
788 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
791 yy_symbol_print (yyoutput, yytype, yyvaluep)
794 YYSTYPE const * const yyvaluep;
797 if (yytype < YYNTOKENS)
798 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
800 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
802 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
803 YYFPRINTF (yyoutput, ")");
806 /*------------------------------------------------------------------.
807 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
809 `------------------------------------------------------------------*/
811 #if (defined __STDC__ || defined __C99__FUNC__ \
812 || defined __cplusplus || defined _MSC_VER)
814 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
817 yy_stack_print (yybottom, yytop)
818 yytype_int16 *yybottom;
822 YYFPRINTF (stderr, "Stack now");
823 for (; yybottom <= yytop; yybottom++)
825 int yybot = *yybottom;
826 YYFPRINTF (stderr, " %d", yybot);
828 YYFPRINTF (stderr, "\n");
831 # define YY_STACK_PRINT(Bottom, Top) \
834 yy_stack_print ((Bottom), (Top)); \
838 /*------------------------------------------------.
839 | Report that the YYRULE is going to be reduced. |
840 `------------------------------------------------*/
842 #if (defined __STDC__ || defined __C99__FUNC__ \
843 || defined __cplusplus || defined _MSC_VER)
845 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
848 yy_reduce_print (yyvsp, yyrule)
853 int yynrhs = yyr2[yyrule];
855 unsigned long int yylno = yyrline[yyrule];
856 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
858 /* The symbols being reduced. */
859 for (yyi = 0; yyi < yynrhs; yyi++)
861 YYFPRINTF (stderr, " $%d = ", yyi + 1);
862 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
863 &(yyvsp[(yyi + 1) - (yynrhs)])
865 YYFPRINTF (stderr, "\n");
869 # define YY_REDUCE_PRINT(Rule) \
872 yy_reduce_print (yyvsp, Rule); \
875 /* Nonzero means print parse trace. It is left uninitialized so that
876 multiple parsers can coexist. */
879 # define YYDPRINTF(Args)
880 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
881 # define YY_STACK_PRINT(Bottom, Top)
882 # define YY_REDUCE_PRINT(Rule)
883 #endif /* !YYDEBUG */
886 /* YYINITDEPTH -- initial size of the parser's stacks. */
888 # define YYINITDEPTH 200
891 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
892 if the built-in stack extension method is used).
894 Do not make this value too large; the results are undefined if
895 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
896 evaluated with infinite-precision integer arithmetic. */
899 # define YYMAXDEPTH 10000
906 # if defined __GLIBC__ && defined _STRING_H
907 # define yystrlen strlen
909 /* Return the length of YYSTR. */
910 #if (defined __STDC__ || defined __C99__FUNC__ \
911 || defined __cplusplus || defined _MSC_VER)
913 yystrlen (const char *yystr)
921 for (yylen = 0; yystr[yylen]; yylen++)
929 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
930 # define yystpcpy stpcpy
932 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
934 #if (defined __STDC__ || defined __C99__FUNC__ \
935 || defined __cplusplus || defined _MSC_VER)
937 yystpcpy (char *yydest, const char *yysrc)
940 yystpcpy (yydest, yysrc)
946 const char *yys = yysrc;
948 while ((*yyd++ = *yys++) != '\0')
957 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
958 quotes and backslashes, so that it's suitable for yyerror. The
959 heuristic is that double-quoting is unnecessary unless the string
960 contains an apostrophe, a comma, or backslash (other than
961 backslash-backslash). YYSTR is taken from yytname. If YYRES is
962 null, do not copy; instead, return the length of what the result
965 yytnamerr (char *yyres, const char *yystr)
970 char const *yyp = yystr;
977 goto do_not_strip_quotes;
981 goto do_not_strip_quotes;
994 do_not_strip_quotes: ;
998 return yystrlen (yystr);
1000 return yystpcpy (yyres, yystr) - yyres;
1004 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1005 about the unexpected token YYTOKEN for the state stack whose top is
1008 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1009 not large enough to hold the message. In that case, also set
1010 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1011 required number of bytes is too large to store. */
1013 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1014 yytype_int16 *yyssp, int yytoken)
1016 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
1017 YYSIZE_T yysize = yysize0;
1019 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1020 /* Internationalized format string. */
1021 const char *yyformat = 0;
1022 /* Arguments of yyformat. */
1023 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1024 /* Number of reported tokens (one for the "unexpected", one per
1028 /* There are many possibilities here to consider:
1029 - Assume YYFAIL is not used. It's too flawed to consider. See
1030 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1031 for details. YYERROR is fine as it does not invoke this
1033 - If this state is a consistent state with a default action, then
1034 the only way this function was invoked is if the default action
1035 is an error action. In that case, don't check for expected
1036 tokens because there are none.
1037 - The only way there can be no lookahead present (in yychar) is if
1038 this state is a consistent state with a default action. Thus,
1039 detecting the absence of a lookahead is sufficient to determine
1040 that there is no unexpected or expected token to report. In that
1041 case, just report a simple "syntax error".
1042 - Don't assume there isn't a lookahead just because this state is a
1043 consistent state with a default action. There might have been a
1044 previous inconsistent state, consistent state with a non-default
1045 action, or user semantic action that manipulated yychar.
1046 - Of course, the expected token list depends on states to have
1047 correct lookahead information, and it depends on the parser not
1048 to perform extra reductions after fetching a lookahead from the
1049 scanner and before detecting a syntax error. Thus, state merging
1050 (from LALR or IELR) and default reductions corrupt the expected
1051 token list. However, the list is correct for canonical LR with
1052 one exception: it will still contain any token that will not be
1053 accepted due to an error action in a later state.
1055 if (yytoken != YYEMPTY)
1057 int yyn = yypact[*yyssp];
1058 yyarg[yycount++] = yytname[yytoken];
1059 if (!yypact_value_is_default (yyn))
1061 /* Start YYX at -YYN if negative to avoid negative indexes in
1062 YYCHECK. In other words, skip the first -YYN actions for
1063 this state because they are default actions. */
1064 int yyxbegin = yyn < 0 ? -yyn : 0;
1065 /* Stay within bounds of both yycheck and yytname. */
1066 int yychecklim = YYLAST - yyn + 1;
1067 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1070 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1071 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1072 && !yytable_value_is_error (yytable[yyx + yyn]))
1074 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1080 yyarg[yycount++] = yytname[yyx];
1081 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1082 if (! (yysize <= yysize1
1083 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1092 # define YYCASE_(N, S) \
1096 YYCASE_(0, YY_("syntax error"));
1097 YYCASE_(1, YY_("syntax error, unexpected %s"));
1098 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1099 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1100 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1101 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1105 yysize1 = yysize + yystrlen (yyformat);
1106 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1110 if (*yymsg_alloc < yysize)
1112 *yymsg_alloc = 2 * yysize;
1113 if (! (yysize <= *yymsg_alloc
1114 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1115 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1119 /* Avoid sprintf, as that infringes on the user's name space.
1120 Don't have undefined behavior even if the translation
1121 produced a string with the wrong number of "%s"s. */
1125 while ((*yyp = *yyformat) != '\0')
1126 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1128 yyp += yytnamerr (yyp, yyarg[yyi++]);
1139 #endif /* YYERROR_VERBOSE */
1141 /*-----------------------------------------------.
1142 | Release the memory associated to this symbol. |
1143 `-----------------------------------------------*/
1146 #if (defined __STDC__ || defined __C99__FUNC__ \
1147 || defined __cplusplus || defined _MSC_VER)
1149 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1152 yydestruct (yymsg, yytype, yyvaluep)
1162 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1173 /* Prevent warnings from -Wmissing-prototypes. */
1174 #ifdef YYPARSE_PARAM
1175 #if defined __STDC__ || defined __cplusplus
1176 int yyparse (void *YYPARSE_PARAM);
1180 #else /* ! YYPARSE_PARAM */
1181 #if defined __STDC__ || defined __cplusplus
1186 #endif /* ! YYPARSE_PARAM */
1189 /* The lookahead symbol. */
1192 /* The semantic value of the lookahead symbol. */
1195 /* Number of syntax errors so far. */
1203 #ifdef YYPARSE_PARAM
1204 #if (defined __STDC__ || defined __C99__FUNC__ \
1205 || defined __cplusplus || defined _MSC_VER)
1207 yyparse (void *YYPARSE_PARAM)
1210 yyparse (YYPARSE_PARAM)
1211 void *YYPARSE_PARAM;
1213 #else /* ! YYPARSE_PARAM */
1214 #if (defined __STDC__ || defined __C99__FUNC__ \
1215 || defined __cplusplus || defined _MSC_VER)
1226 /* Number of tokens to shift before error messages enabled. */
1229 /* The stacks and their tools:
1230 `yyss': related to states.
1231 `yyvs': related to semantic values.
1233 Refer to the stacks thru separate pointers, to allow yyoverflow
1234 to reallocate them elsewhere. */
1236 /* The state stack. */
1237 yytype_int16 yyssa[YYINITDEPTH];
1239 yytype_int16 *yyssp;
1241 /* The semantic value stack. */
1242 YYSTYPE yyvsa[YYINITDEPTH];
1246 YYSIZE_T yystacksize;
1250 /* Lookahead token as an internal (translated) token number. */
1252 /* The variables used to return semantic value and location from the
1257 /* Buffer for error messages, and its allocated size. */
1259 char *yymsg = yymsgbuf;
1260 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1263 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1265 /* The number of symbols on the RHS of the reduced rule.
1266 Keep to zero when no symbol should be popped. */
1272 yystacksize = YYINITDEPTH;
1274 YYDPRINTF ((stderr, "Starting parse\n"));
1279 yychar = YYEMPTY; /* Cause a token to be read. */
1281 /* Initialize stack pointers.
1282 Waste one element of value and location stack
1283 so that they stay on the same level as the state stack.
1284 The wasted elements are never initialized. */
1290 /*------------------------------------------------------------.
1291 | yynewstate -- Push a new state, which is found in yystate. |
1292 `------------------------------------------------------------*/
1294 /* In all cases, when you get here, the value and location stacks
1295 have just been pushed. So pushing a state here evens the stacks. */
1301 if (yyss + yystacksize - 1 <= yyssp)
1303 /* Get the current used size of the three stacks, in elements. */
1304 YYSIZE_T yysize = yyssp - yyss + 1;
1308 /* Give user a chance to reallocate the stack. Use copies of
1309 these so that the &'s don't force the real ones into
1311 YYSTYPE *yyvs1 = yyvs;
1312 yytype_int16 *yyss1 = yyss;
1314 /* Each stack pointer address is followed by the size of the
1315 data in use in that stack, in bytes. This used to be a
1316 conditional around just the two extra args, but that might
1317 be undefined if yyoverflow is a macro. */
1318 yyoverflow (YY_("memory exhausted"),
1319 &yyss1, yysize * sizeof (*yyssp),
1320 &yyvs1, yysize * sizeof (*yyvsp),
1326 #else /* no yyoverflow */
1327 # ifndef YYSTACK_RELOCATE
1328 goto yyexhaustedlab;
1330 /* Extend the stack our own way. */
1331 if (YYMAXDEPTH <= yystacksize)
1332 goto yyexhaustedlab;
1334 if (YYMAXDEPTH < yystacksize)
1335 yystacksize = YYMAXDEPTH;
1338 yytype_int16 *yyss1 = yyss;
1339 union yyalloc *yyptr =
1340 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1342 goto yyexhaustedlab;
1343 YYSTACK_RELOCATE (yyss_alloc, yyss);
1344 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1345 # undef YYSTACK_RELOCATE
1347 YYSTACK_FREE (yyss1);
1350 #endif /* no yyoverflow */
1352 yyssp = yyss + yysize - 1;
1353 yyvsp = yyvs + yysize - 1;
1355 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1356 (unsigned long int) yystacksize));
1358 if (yyss + yystacksize - 1 <= yyssp)
1362 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1364 if (yystate == YYFINAL)
1374 /* Do appropriate processing given the current state. Read a
1375 lookahead token if we need one and don't already have one. */
1377 /* First try to decide what to do without reference to lookahead token. */
1378 yyn = yypact[yystate];
1379 if (yypact_value_is_default (yyn))
1382 /* Not known => get a lookahead token if don't already have one. */
1384 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1385 if (yychar == YYEMPTY)
1387 YYDPRINTF ((stderr, "Reading a token: "));
1391 if (yychar <= YYEOF)
1393 yychar = yytoken = YYEOF;
1394 YYDPRINTF ((stderr, "Now at end of input.\n"));
1398 yytoken = YYTRANSLATE (yychar);
1399 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1402 /* If the proper action on seeing token YYTOKEN is to reduce or to
1403 detect an error, take that action. */
1405 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1410 if (yytable_value_is_error (yyn))
1416 /* Count tokens shifted since error; after three, turn off error
1421 /* Shift the lookahead token. */
1422 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1424 /* Discard the shifted token. */
1433 /*-----------------------------------------------------------.
1434 | yydefault -- do the default action for the current state. |
1435 `-----------------------------------------------------------*/
1437 yyn = yydefact[yystate];
1443 /*-----------------------------.
1444 | yyreduce -- Do a reduction. |
1445 `-----------------------------*/
1447 /* yyn is the number of a rule to reduce with. */
1450 /* If YYLEN is nonzero, implement the default value of the action:
1453 Otherwise, the following line sets YYVAL to garbage.
1454 This behavior is undocumented and Bison
1455 users should not rely upon it. Assigning to YYVAL
1456 unconditionally makes the parser a bit smaller, and it avoids a
1457 GCC warning that YYVAL may be used uninitialized. */
1458 yyval = yyvsp[1-yylen];
1461 YY_REDUCE_PRINT (yyn);
1466 /* Line 1806 of yacc.c */
1467 #line 73 "slmod_sparql_parser.y"
1469 ssp_result = talloc_asprintf(ssp_slq,
1470 "SELECT DISTINCT ?url WHERE "
1471 "{ ?obj nie:url ?url FILTER(regex(?url, '^file://%s/')) . %s}",
1472 ssp_slq->slq_vol->v_path, (yyvsp[(1) - (1)].sval));
1473 (yyval.sval) = ssp_result;
1479 /* Line 1806 of yacc.c */
1480 #line 83 "slmod_sparql_parser.y"
1482 if ((yyvsp[(1) - (1)].bval) == false)
1491 /* Line 1806 of yacc.c */
1492 #line 89 "slmod_sparql_parser.y"
1494 if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1495 (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1497 (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1503 /* Line 1806 of yacc.c */
1504 #line 95 "slmod_sparql_parser.y"
1505 {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;}
1510 /* Line 1806 of yacc.c */
1511 #line 96 "slmod_sparql_parser.y"
1512 {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
1517 /* Line 1806 of yacc.c */
1518 #line 97 "slmod_sparql_parser.y"
1519 {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));}
1524 /* Line 1806 of yacc.c */
1525 #line 98 "slmod_sparql_parser.y"
1526 {(yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));}
1531 /* Line 1806 of yacc.c */
1532 #line 99 "slmod_sparql_parser.y"
1534 if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1535 (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1537 (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1543 /* Line 1806 of yacc.c */
1544 #line 108 "slmod_sparql_parser.y"
1545 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
1550 /* Line 1806 of yacc.c */
1551 #line 109 "slmod_sparql_parser.y"
1552 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));}
1557 /* Line 1806 of yacc.c */
1558 #line 110 "slmod_sparql_parser.y"
1559 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));}
1564 /* Line 1806 of yacc.c */
1565 #line 111 "slmod_sparql_parser.y"
1566 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
1571 /* Line 1806 of yacc.c */
1572 #line 112 "slmod_sparql_parser.y"
1573 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));}
1578 /* Line 1806 of yacc.c */
1579 #line 113 "slmod_sparql_parser.y"
1580 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));}
1585 /* Line 1806 of yacc.c */
1586 #line 114 "slmod_sparql_parser.y"
1587 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));}
1592 /* Line 1806 of yacc.c */
1593 #line 115 "slmod_sparql_parser.y"
1594 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));}
1599 /* Line 1806 of yacc.c */
1600 #line 119 "slmod_sparql_parser.y"
1601 {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));}
1606 /* Line 1806 of yacc.c */
1607 #line 123 "slmod_sparql_parser.y"
1608 {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));}
1613 /* Line 1806 of yacc.c */
1614 #line 124 "slmod_sparql_parser.y"
1615 {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;}
1620 /* Line 1806 of yacc.c */
1621 #line 1622 "slmod_sparql_parser.c"
1624 /* User semantic actions sometimes alter yychar, and that requires
1625 that yytoken be updated with the new translation. We take the
1626 approach of translating immediately before every use of yytoken.
1627 One alternative is translating here after every semantic action,
1628 but that translation would be missed if the semantic action invokes
1629 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1630 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1631 incorrect destructor might then be invoked immediately. In the
1632 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1633 to an incorrect destructor call or verbose syntax error message
1634 before the lookahead is translated. */
1635 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1639 YY_STACK_PRINT (yyss, yyssp);
1643 /* Now `shift' the result of the reduction. Determine what state
1644 that goes to, based on the state we popped back to and the rule
1645 number reduced by. */
1649 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1650 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1651 yystate = yytable[yystate];
1653 yystate = yydefgoto[yyn - YYNTOKENS];
1658 /*------------------------------------.
1659 | yyerrlab -- here on detecting error |
1660 `------------------------------------*/
1662 /* Make sure we have latest lookahead translation. See comments at
1663 user semantic actions for why this is necessary. */
1664 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1666 /* If not already recovering from an error, report this error. */
1670 #if ! YYERROR_VERBOSE
1671 yyerror (YY_("syntax error"));
1673 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1676 char const *yymsgp = YY_("syntax error");
1677 int yysyntax_error_status;
1678 yysyntax_error_status = YYSYNTAX_ERROR;
1679 if (yysyntax_error_status == 0)
1681 else if (yysyntax_error_status == 1)
1683 if (yymsg != yymsgbuf)
1684 YYSTACK_FREE (yymsg);
1685 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1689 yymsg_alloc = sizeof yymsgbuf;
1690 yysyntax_error_status = 2;
1694 yysyntax_error_status = YYSYNTAX_ERROR;
1699 if (yysyntax_error_status == 2)
1700 goto yyexhaustedlab;
1702 # undef YYSYNTAX_ERROR
1708 if (yyerrstatus == 3)
1710 /* If just tried and failed to reuse lookahead token after an
1711 error, discard it. */
1713 if (yychar <= YYEOF)
1715 /* Return failure if at end of input. */
1716 if (yychar == YYEOF)
1721 yydestruct ("Error: discarding",
1727 /* Else will try to reuse lookahead token after shifting the error
1732 /*---------------------------------------------------.
1733 | yyerrorlab -- error raised explicitly by YYERROR. |
1734 `---------------------------------------------------*/
1737 /* Pacify compilers like GCC when the user code never invokes
1738 YYERROR and the label yyerrorlab therefore never appears in user
1740 if (/*CONSTCOND*/ 0)
1743 /* Do not reclaim the symbols of the rule which action triggered
1747 YY_STACK_PRINT (yyss, yyssp);
1752 /*-------------------------------------------------------------.
1753 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1754 `-------------------------------------------------------------*/
1756 yyerrstatus = 3; /* Each real token shifted decrements this. */
1760 yyn = yypact[yystate];
1761 if (!yypact_value_is_default (yyn))
1764 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1772 /* Pop the current state because it cannot handle the error token. */
1777 yydestruct ("Error: popping",
1778 yystos[yystate], yyvsp);
1781 YY_STACK_PRINT (yyss, yyssp);
1787 /* Shift the error token. */
1788 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1794 /*-------------------------------------.
1795 | yyacceptlab -- YYACCEPT comes here. |
1796 `-------------------------------------*/
1801 /*-----------------------------------.
1802 | yyabortlab -- YYABORT comes here. |
1803 `-----------------------------------*/
1808 #if !defined(yyoverflow) || YYERROR_VERBOSE
1809 /*-------------------------------------------------.
1810 | yyexhaustedlab -- memory exhaustion comes here. |
1811 `-------------------------------------------------*/
1813 yyerror (YY_("memory exhausted"));
1819 if (yychar != YYEMPTY)
1821 /* Make sure we have latest lookahead translation. See comments at
1822 user semantic actions for why this is necessary. */
1823 yytoken = YYTRANSLATE (yychar);
1824 yydestruct ("Cleanup: discarding lookahead",
1827 /* Do not reclaim the symbols of the rule which action triggered
1828 this YYABORT or YYACCEPT. */
1830 YY_STACK_PRINT (yyss, yyssp);
1831 while (yyssp != yyss)
1833 yydestruct ("Cleanup: popping",
1834 yystos[*yyssp], yyvsp);
1839 YYSTACK_FREE (yyss);
1842 if (yymsg != yymsgbuf)
1843 YYSTACK_FREE (yymsg);
1845 /* Make sure YYID is used. */
1846 return YYID (yyresult);
1851 /* Line 2067 of yacc.c */
1852 #line 127 "slmod_sparql_parser.y"
1855 static time_t isodate2unix(const char *s)
1859 if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL)
1864 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2)
1867 char *result = NULL;
1868 struct spotlight_sparql_map *p;
1870 char buf1[64], buf2[64];
1872 EC_NULL_LOG( tmp = localtime(&date1) );
1873 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1874 EC_NULL_LOG( tmp = localtime(&date2) );
1875 strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
1877 for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1878 if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) {
1879 result = talloc_asprintf(ssp_slq,
1880 "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')",
1898 static char *map_type_search(const char *attr, char op, const char *val)
1900 char *result = NULL;
1901 const char *sparqlAttr;
1903 for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) {
1904 if (strcmp(p->mdtm_value, val) == 0) {
1905 switch (p->mdtm_type) {
1907 sparqlAttr = "rdf:type";
1909 case kMDTypeMapMime:
1910 sparqlAttr = "nie:mimeType";
1915 result = talloc_asprintf(ssp_slq, "?obj %s '%s'",
1924 static const char *map_expr(const char *attr, char op, const char *val)
1927 char *result = NULL;
1928 struct spotlight_sparql_map *p;
1932 bstring q = NULL, search = NULL, replace = NULL;
1934 for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1935 if (strcmp(p->ssm_spotlight_attr, attr) == 0) {
1936 if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) {
1937 yyerror("unsupported Spotlight attribute");
1940 switch (p->ssm_type) {
1942 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1945 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')",
1950 op == '!' ? '=' : ' ', /* append '=' to '!' */
1955 q = bformat("^%s$", val);
1956 search = bfromcstr("*");
1957 replace = bfromcstr(".*");
1958 bfindreplace(q, search, replace, 0);
1959 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))",
1967 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1970 t = atoi(val) + SPRAW_TIME_OFFSET;
1971 EC_NULL( tmp = localtime(&t) );
1972 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1973 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')",
1982 result = map_type_search(attr, op, val);
2001 void yyerror(const char *str)
2004 printf("yyerror: %s\n", str);
2006 LOG(log_error, logtype_sl, "yyerror: %s", str);
2016 * Map a Spotlight RAW query string to a SPARQL query string
2018 * @param[in] slq Spotlight query handle
2019 * @param[out] sparql_result Mapped SPARQL query, string is allocated in
2020 * talloc context of slq
2021 * @return 0 on success, -1 on error
2023 int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result)
2026 YY_BUFFER_STATE s = NULL;
2030 s = yy_scan_string(slq->slq_qstring);
2033 EC_ZERO( yyparse() );
2037 yy_delete_buffer(s);
2039 *sparql_result = ssp_result;
2041 *sparql_result = NULL;
2046 int main(int argc, char **argv)
2052 printf("usage: %s QUERY\n", argv[0]);
2056 ssp_slq = talloc_zero(NULL, slq_t);
2057 struct vol *vol = talloc_zero(ssp_slq, struct vol);
2058 vol->v_path = "/Volumes/test";
2059 ssp_slq->slq_vol = vol;
2062 s = yy_scan_string(argv[1]);
2066 yy_delete_buffer(s);
2069 printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)");