1 /* A Bison parser, made by GNU Bison 2.7. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2012 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.7"
50 #define YYSKELETON_NAME "yacc.c"
64 /* Copy the first part of user declarations. */
65 /* Line 371 of yacc.c */
66 #line 1 "slmod_sparql_parser.y"
68 #include <atalk/standards.h>
77 #include <atalk/talloc.h>
78 #include <atalk/logger.h>
79 #include <atalk/errchk.h>
80 #include <atalk/spotlight.h>
82 #include "slmod_sparql_map.h"
84 struct yy_buffer_state;
85 typedef struct yy_buffer_state *YY_BUFFER_STATE;
86 extern int yylex (void);
87 extern void yyerror (char const *);
88 extern void *yyterminate(void);
89 extern YY_BUFFER_STATE yy_scan_string( const char *str);
90 extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
92 /* forward declarations */
93 static const char *map_expr(const char *attr, char op, const char *val);
94 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2);
95 static time_t isodate2unix(const char *s);
97 /* global vars, eg needed by the lexer */
101 static gchar *ssp_result;
102 static char sparqlvar;
103 static char *result_limit;
105 /* Line 371 of yacc.c */
106 #line 107 "slmod_sparql_parser.c"
109 # if defined __cplusplus && 201103L <= __cplusplus
110 # define YY_NULL nullptr
116 /* Enabling verbose error messages. */
117 #ifdef YYERROR_VERBOSE
118 # undef YYERROR_VERBOSE
119 # define YYERROR_VERBOSE 1
121 # define YYERROR_VERBOSE 1
124 /* In a future release of Bison, this section will be replaced
125 by #include "y.tab.h". */
126 #ifndef YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED
127 # define YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED
128 /* Enabling traces. */
139 /* Put the tokens into the symbol table, so that GDB and other debuggers
161 #define FUNC_INRANGE 260
176 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
177 typedef union YYSTYPE
179 /* Line 387 of yacc.c */
180 #line 46 "slmod_sparql_parser.y"
188 /* Line 387 of yacc.c */
189 #line 190 "slmod_sparql_parser.c"
191 # define YYSTYPE_IS_TRIVIAL 1
192 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
193 # define YYSTYPE_IS_DECLARED 1
196 extern YYSTYPE yylval;
199 #if defined __STDC__ || defined __cplusplus
200 int yyparse (void *YYPARSE_PARAM);
204 #else /* ! YYPARSE_PARAM */
205 #if defined __STDC__ || defined __cplusplus
210 #endif /* ! YYPARSE_PARAM */
211 /* "%code provides" blocks. */
212 /* Line 387 of yacc.c */
213 #line 40 "slmod_sparql_parser.y"
215 #define SPRAW_TIME_OFFSET 978307200
216 extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
217 extern slq_t *ssp_slq;
220 /* Line 387 of yacc.c */
221 #line 222 "slmod_sparql_parser.c"
223 #endif /* !YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED */
225 /* Copy the second part of user declarations. */
227 /* Line 390 of yacc.c */
228 #line 229 "slmod_sparql_parser.c"
235 typedef YYTYPE_UINT8 yytype_uint8;
237 typedef unsigned char yytype_uint8;
241 typedef YYTYPE_INT8 yytype_int8;
242 #elif (defined __STDC__ || defined __C99__FUNC__ \
243 || defined __cplusplus || defined _MSC_VER)
244 typedef signed char yytype_int8;
246 typedef short int yytype_int8;
250 typedef YYTYPE_UINT16 yytype_uint16;
252 typedef unsigned short int yytype_uint16;
256 typedef YYTYPE_INT16 yytype_int16;
258 typedef short int yytype_int16;
262 # ifdef __SIZE_TYPE__
263 # define YYSIZE_T __SIZE_TYPE__
264 # elif defined size_t
265 # define YYSIZE_T size_t
266 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
267 || defined __cplusplus || defined _MSC_VER)
268 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
269 # define YYSIZE_T size_t
271 # define YYSIZE_T unsigned int
275 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
278 # if defined YYENABLE_NLS && YYENABLE_NLS
280 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
281 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
285 # define YY_(Msgid) Msgid
289 /* Suppress unused-variable warnings by "using" E. */
290 #if ! defined lint || defined __GNUC__
291 # define YYUSE(E) ((void) (E))
293 # define YYUSE(E) /* empty */
296 /* Identity function, used to suppress warnings about constant conditions. */
300 #if (defined __STDC__ || defined __C99__FUNC__ \
301 || defined __cplusplus || defined _MSC_VER)
314 #if ! defined yyoverflow || YYERROR_VERBOSE
316 /* The parser invokes alloca or malloc; define the necessary symbols. */
318 # ifdef YYSTACK_USE_ALLOCA
319 # if YYSTACK_USE_ALLOCA
321 # define YYSTACK_ALLOC __builtin_alloca
322 # elif defined __BUILTIN_VA_ARG_INCR
323 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
325 # define YYSTACK_ALLOC __alloca
326 # elif defined _MSC_VER
327 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
328 # define alloca _alloca
330 # define YYSTACK_ALLOC alloca
331 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
332 || defined __cplusplus || defined _MSC_VER)
333 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
334 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
335 # ifndef EXIT_SUCCESS
336 # define EXIT_SUCCESS 0
343 # ifdef YYSTACK_ALLOC
344 /* Pacify GCC's `empty if-body' warning. */
345 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
346 # ifndef YYSTACK_ALLOC_MAXIMUM
347 /* The OS might guarantee only one guard page at the bottom of the stack,
348 and a page size can be as small as 4096 bytes. So we cannot safely
349 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
350 to allow for a few compiler-allocated temporary stack slots. */
351 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
354 # define YYSTACK_ALLOC YYMALLOC
355 # define YYSTACK_FREE YYFREE
356 # ifndef YYSTACK_ALLOC_MAXIMUM
357 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
359 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
360 && ! ((defined YYMALLOC || defined malloc) \
361 && (defined YYFREE || defined free)))
362 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
363 # ifndef EXIT_SUCCESS
364 # define EXIT_SUCCESS 0
368 # define YYMALLOC malloc
369 # if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
370 || defined __cplusplus || defined _MSC_VER)
371 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
376 # if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
377 || defined __cplusplus || defined _MSC_VER)
378 void free (void *); /* INFRINGES ON USER NAME SPACE */
382 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
385 #if (! defined yyoverflow \
386 && (! defined __cplusplus \
387 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
389 /* A type that is properly aligned for any stack member. */
392 yytype_int16 yyss_alloc;
396 /* The size of the maximum gap between one aligned stack and the next. */
397 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
399 /* The size of an array large to enough to hold all stacks, each with
401 # define YYSTACK_BYTES(N) \
402 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
403 + YYSTACK_GAP_MAXIMUM)
405 # define YYCOPY_NEEDED 1
407 /* Relocate STACK from its old location to the new one. The
408 local variables YYSIZE and YYSTACKSIZE give the old and new number of
409 elements in the stack, and YYPTR gives the new location of the
410 stack. Advance YYPTR to a properly aligned location for the next
412 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
415 YYSIZE_T yynewbytes; \
416 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
417 Stack = &yyptr->Stack_alloc; \
418 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
419 yyptr += yynewbytes / sizeof (*yyptr); \
425 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
426 /* Copy COUNT objects from SRC to DST. The source and destination do
429 # if defined __GNUC__ && 1 < __GNUC__
430 # define YYCOPY(Dst, Src, Count) \
431 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
433 # define YYCOPY(Dst, Src, Count) \
437 for (yyi = 0; yyi < (Count); yyi++) \
438 (Dst)[yyi] = (Src)[yyi]; \
443 #endif /* !YYCOPY_NEEDED */
445 /* YYFINAL -- State number of the termination state. */
447 /* YYLAST -- Last index in YYTABLE. */
450 /* YYNTOKENS -- Number of terminals. */
452 /* YYNNTS -- Number of nonterminals. */
454 /* YYNRULES -- Number of rules. */
456 /* YYNRULES -- Number of states. */
459 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
461 #define YYMAXUTOK 271
463 #define YYTRANSLATE(YYX) \
464 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
466 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
467 static const yytype_uint8 yytranslate[] =
469 0, 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, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
488 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
489 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
494 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
495 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
500 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
502 static const yytype_uint8 yyprhs[] =
504 0, 0, 3, 4, 7, 9, 11, 15, 17, 19,
505 23, 27, 31, 37, 43, 49, 55, 62, 69, 76,
509 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
510 static const yytype_int8 yyrhs[] =
512 18, 0, -1, -1, 18, 19, -1, 20, -1, 4,
513 -1, 21, 16, 21, -1, 21, -1, 22, -1, 7,
514 20, 8, -1, 20, 15, 20, -1, 20, 16, 20,
515 -1, 3, 9, 14, 3, 14, -1, 3, 10, 14,
516 3, 14, -1, 3, 12, 14, 3, 14, -1, 3,
517 11, 14, 3, 14, -1, 3, 9, 14, 3, 14,
518 3, -1, 3, 10, 14, 3, 14, 3, -1, 3,
519 12, 14, 3, 14, 3, -1, 3, 11, 14, 3,
520 14, 3, -1, 5, 7, 3, 13, 23, 13, 23,
521 8, -1, 6, 7, 3, 8, -1, 3, -1
524 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
525 static const yytype_uint8 yyrline[] =
527 0, 68, 68, 70, 74, 88, 94, 104, 105, 106,
528 107, 112, 121, 122, 123, 124, 125, 126, 127, 128,
533 #if YYDEBUG || YYERROR_VERBOSE || 1
534 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
535 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
536 static const char *const yytname[] =
538 "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE",
539 "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
540 "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
541 "function", "date", YY_NULL
546 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
548 static const yytype_uint16 yytoknum[] =
550 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
551 265, 266, 267, 268, 269, 270, 271
555 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
556 static const yytype_uint8 yyr1[] =
558 0, 17, 18, 18, 19, 20, 20, 20, 20, 20,
559 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
563 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
564 static const yytype_uint8 yyr2[] =
566 0, 2, 0, 2, 1, 1, 3, 1, 1, 3,
567 3, 3, 5, 5, 5, 5, 6, 6, 6, 6,
571 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
572 Performed when YYTABLE doesn't specify something else to do. Zero
573 means the default is an error. */
574 static const yytype_uint8 yydefact[] =
576 2, 0, 1, 0, 5, 0, 0, 3, 4, 7,
577 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
578 0, 0, 0, 0, 0, 9, 10, 11, 6, 0,
579 0, 0, 0, 0, 12, 13, 15, 14, 22, 0,
580 0, 16, 17, 19, 18, 0, 0, 0, 0, 21,
584 /* YYDEFGOTO[NTERM-NUM]. */
585 static const yytype_int8 yydefgoto[] =
587 -1, 1, 7, 8, 9, 10, 40
590 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
592 #define YYPACT_NINF -10
593 static const yytype_int8 yypact[] =
595 -10, 10, -10, 9, -10, -2, -1, -10, 8, -9,
596 -10, 2, 12, 13, 14, 26, -7, -1, -1, 27,
597 28, 29, 30, 31, 22, -10, 20, -10, -10, 23,
598 24, 25, 32, 19, 37, 38, 39, 40, -10, 41,
599 34, -10, -10, -10, -10, 42, 19, 36, 43, -10,
603 /* YYPGOTO[NTERM-NUM]. */
604 static const yytype_int8 yypgoto[] =
606 -10, -10, -10, -6, 33, -10, 3
609 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
610 positive, shift that token. If negative, reduce the rule which
611 number is the opposite. If YYTABLE_NINF, syntax error. */
612 #define YYTABLE_NINF -1
613 static const yytype_uint8 yytable[] =
615 16, 25, 3, 4, 5, 15, 6, 19, 17, 18,
616 2, 26, 27, 3, 4, 5, 20, 6, 11, 12,
617 13, 14, 38, 17, 18, 39, 21, 22, 23, 24,
618 3, 29, 30, 31, 32, 33, 18, 34, 35, 36,
619 41, 42, 43, 44, 49, 47, 37, 46, 45, 48,
623 #define yypact_value_is_default(Yystate) \
624 (!!((Yystate) == (-10)))
626 #define yytable_value_is_error(Yytable_value) \
629 static const yytype_int8 yycheck[] =
631 6, 8, 3, 4, 5, 7, 7, 16, 15, 16,
632 0, 17, 18, 3, 4, 5, 14, 7, 9, 10,
633 11, 12, 3, 15, 16, 6, 14, 14, 14, 3,
634 3, 3, 3, 3, 3, 13, 16, 14, 14, 14,
635 3, 3, 3, 3, 8, 3, 14, 13, 7, 46,
639 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
640 symbol of state STATE-NUM. */
641 static const yytype_uint8 yystos[] =
643 0, 18, 0, 3, 4, 5, 7, 19, 20, 21,
644 22, 9, 10, 11, 12, 7, 20, 15, 16, 16,
645 14, 14, 14, 14, 3, 8, 20, 20, 21, 3,
646 3, 3, 3, 13, 14, 14, 14, 14, 3, 6,
647 23, 3, 3, 3, 3, 7, 13, 3, 23, 8,
651 #define yyerrok (yyerrstatus = 0)
652 #define yyclearin (yychar = YYEMPTY)
656 #define YYACCEPT goto yyacceptlab
657 #define YYABORT goto yyabortlab
658 #define YYERROR goto yyerrorlab
661 /* Like YYERROR except do call yyerror. This remains here temporarily
662 to ease the transition to the new meaning of YYERROR, for GCC.
663 Once GCC version 2 has supplanted version 1, this can go. However,
664 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
665 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
668 #define YYFAIL goto yyerrlab
670 /* This is here to suppress warnings from the GCC cpp's
671 -Wunused-macros. Normally we don't worry about that warning, but
672 some users do, and we want to make it easy for users to remove
673 YYFAIL uses, which will produce warnings from Bison 2.5. */
676 #define YYRECOVERING() (!!yyerrstatus)
678 #define YYBACKUP(Token, Value) \
680 if (yychar == YYEMPTY) \
684 YYPOPSTACK (yylen); \
690 yyerror (YY_("syntax error: cannot back up")); \
695 /* Error token number */
697 #define YYERRCODE 256
700 /* This macro is provided for backward compatibility. */
701 #ifndef YY_LOCATION_PRINT
702 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
706 /* YYLEX -- calling `yylex' with the right arguments. */
708 # define YYLEX yylex (YYLEX_PARAM)
710 # define YYLEX yylex ()
713 /* Enable debugging if requested. */
717 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
718 # define YYFPRINTF fprintf
721 # define YYDPRINTF(Args) \
727 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
731 YYFPRINTF (stderr, "%s ", Title); \
732 yy_symbol_print (stderr, \
734 YYFPRINTF (stderr, "\n"); \
739 /*--------------------------------.
740 | Print this symbol on YYOUTPUT. |
741 `--------------------------------*/
744 #if (defined __STDC__ || defined __C99__FUNC__ \
745 || defined __cplusplus || defined _MSC_VER)
747 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
750 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
753 YYSTYPE const * const yyvaluep;
756 FILE *yyo = yyoutput;
761 if (yytype < YYNTOKENS)
762 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
774 /*--------------------------------.
775 | Print this symbol on YYOUTPUT. |
776 `--------------------------------*/
778 #if (defined __STDC__ || defined __C99__FUNC__ \
779 || defined __cplusplus || defined _MSC_VER)
781 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
784 yy_symbol_print (yyoutput, yytype, yyvaluep)
787 YYSTYPE const * const yyvaluep;
790 if (yytype < YYNTOKENS)
791 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
793 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
795 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
796 YYFPRINTF (yyoutput, ")");
799 /*------------------------------------------------------------------.
800 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
802 `------------------------------------------------------------------*/
804 #if (defined __STDC__ || defined __C99__FUNC__ \
805 || defined __cplusplus || defined _MSC_VER)
807 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
810 yy_stack_print (yybottom, yytop)
811 yytype_int16 *yybottom;
815 YYFPRINTF (stderr, "Stack now");
816 for (; yybottom <= yytop; yybottom++)
818 int yybot = *yybottom;
819 YYFPRINTF (stderr, " %d", yybot);
821 YYFPRINTF (stderr, "\n");
824 # define YY_STACK_PRINT(Bottom, Top) \
827 yy_stack_print ((Bottom), (Top)); \
831 /*------------------------------------------------.
832 | Report that the YYRULE is going to be reduced. |
833 `------------------------------------------------*/
835 #if (defined __STDC__ || defined __C99__FUNC__ \
836 || defined __cplusplus || defined _MSC_VER)
838 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
841 yy_reduce_print (yyvsp, yyrule)
846 int yynrhs = yyr2[yyrule];
848 unsigned long int yylno = yyrline[yyrule];
849 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
851 /* The symbols being reduced. */
852 for (yyi = 0; yyi < yynrhs; yyi++)
854 YYFPRINTF (stderr, " $%d = ", yyi + 1);
855 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
856 &(yyvsp[(yyi + 1) - (yynrhs)])
858 YYFPRINTF (stderr, "\n");
862 # define YY_REDUCE_PRINT(Rule) \
865 yy_reduce_print (yyvsp, Rule); \
868 /* Nonzero means print parse trace. It is left uninitialized so that
869 multiple parsers can coexist. */
872 # define YYDPRINTF(Args)
873 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
874 # define YY_STACK_PRINT(Bottom, Top)
875 # define YY_REDUCE_PRINT(Rule)
876 #endif /* !YYDEBUG */
879 /* YYINITDEPTH -- initial size of the parser's stacks. */
881 # define YYINITDEPTH 200
884 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
885 if the built-in stack extension method is used).
887 Do not make this value too large; the results are undefined if
888 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
889 evaluated with infinite-precision integer arithmetic. */
892 # define YYMAXDEPTH 10000
899 # if defined __GLIBC__ && defined _STRING_H
900 # define yystrlen strlen
902 /* Return the length of YYSTR. */
903 #if (defined __STDC__ || defined __C99__FUNC__ \
904 || defined __cplusplus || defined _MSC_VER)
906 yystrlen (const char *yystr)
914 for (yylen = 0; yystr[yylen]; yylen++)
922 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
923 # define yystpcpy stpcpy
925 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
927 #if (defined __STDC__ || defined __C99__FUNC__ \
928 || defined __cplusplus || defined _MSC_VER)
930 yystpcpy (char *yydest, const char *yysrc)
933 yystpcpy (yydest, yysrc)
939 const char *yys = yysrc;
941 while ((*yyd++ = *yys++) != '\0')
950 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
951 quotes and backslashes, so that it's suitable for yyerror. The
952 heuristic is that double-quoting is unnecessary unless the string
953 contains an apostrophe, a comma, or backslash (other than
954 backslash-backslash). YYSTR is taken from yytname. If YYRES is
955 null, do not copy; instead, return the length of what the result
958 yytnamerr (char *yyres, const char *yystr)
963 char const *yyp = yystr;
970 goto do_not_strip_quotes;
974 goto do_not_strip_quotes;
987 do_not_strip_quotes: ;
991 return yystrlen (yystr);
993 return yystpcpy (yyres, yystr) - yyres;
997 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
998 about the unexpected token YYTOKEN for the state stack whose top is
1001 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1002 not large enough to hold the message. In that case, also set
1003 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1004 required number of bytes is too large to store. */
1006 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1007 yytype_int16 *yyssp, int yytoken)
1009 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1010 YYSIZE_T yysize = yysize0;
1011 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1012 /* Internationalized format string. */
1013 const char *yyformat = YY_NULL;
1014 /* Arguments of yyformat. */
1015 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1016 /* Number of reported tokens (one for the "unexpected", one per
1020 /* There are many possibilities here to consider:
1021 - Assume YYFAIL is not used. It's too flawed to consider. See
1022 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1023 for details. YYERROR is fine as it does not invoke this
1025 - If this state is a consistent state with a default action, then
1026 the only way this function was invoked is if the default action
1027 is an error action. In that case, don't check for expected
1028 tokens because there are none.
1029 - The only way there can be no lookahead present (in yychar) is if
1030 this state is a consistent state with a default action. Thus,
1031 detecting the absence of a lookahead is sufficient to determine
1032 that there is no unexpected or expected token to report. In that
1033 case, just report a simple "syntax error".
1034 - Don't assume there isn't a lookahead just because this state is a
1035 consistent state with a default action. There might have been a
1036 previous inconsistent state, consistent state with a non-default
1037 action, or user semantic action that manipulated yychar.
1038 - Of course, the expected token list depends on states to have
1039 correct lookahead information, and it depends on the parser not
1040 to perform extra reductions after fetching a lookahead from the
1041 scanner and before detecting a syntax error. Thus, state merging
1042 (from LALR or IELR) and default reductions corrupt the expected
1043 token list. However, the list is correct for canonical LR with
1044 one exception: it will still contain any token that will not be
1045 accepted due to an error action in a later state.
1047 if (yytoken != YYEMPTY)
1049 int yyn = yypact[*yyssp];
1050 yyarg[yycount++] = yytname[yytoken];
1051 if (!yypact_value_is_default (yyn))
1053 /* Start YYX at -YYN if negative to avoid negative indexes in
1054 YYCHECK. In other words, skip the first -YYN actions for
1055 this state because they are default actions. */
1056 int yyxbegin = yyn < 0 ? -yyn : 0;
1057 /* Stay within bounds of both yycheck and yytname. */
1058 int yychecklim = YYLAST - yyn + 1;
1059 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1062 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1063 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1064 && !yytable_value_is_error (yytable[yyx + yyn]))
1066 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1072 yyarg[yycount++] = yytname[yyx];
1074 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1075 if (! (yysize <= yysize1
1076 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1086 # define YYCASE_(N, S) \
1090 YYCASE_(0, YY_("syntax error"));
1091 YYCASE_(1, YY_("syntax error, unexpected %s"));
1092 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1093 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1094 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1095 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1100 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1101 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1106 if (*yymsg_alloc < yysize)
1108 *yymsg_alloc = 2 * yysize;
1109 if (! (yysize <= *yymsg_alloc
1110 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1111 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1115 /* Avoid sprintf, as that infringes on the user's name space.
1116 Don't have undefined behavior even if the translation
1117 produced a string with the wrong number of "%s"s. */
1121 while ((*yyp = *yyformat) != '\0')
1122 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1124 yyp += yytnamerr (yyp, yyarg[yyi++]);
1135 #endif /* YYERROR_VERBOSE */
1137 /*-----------------------------------------------.
1138 | Release the memory associated to this symbol. |
1139 `-----------------------------------------------*/
1142 #if (defined __STDC__ || defined __C99__FUNC__ \
1143 || defined __cplusplus || defined _MSC_VER)
1145 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1148 yydestruct (yymsg, yytype, yyvaluep)
1158 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1171 /* The lookahead symbol. */
1175 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1176 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1177 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
1179 #ifndef YY_INITIAL_VALUE
1180 # define YY_INITIAL_VALUE(Value) /* Nothing. */
1183 /* The semantic value of the lookahead symbol. */
1184 YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
1186 /* Number of syntax errors so far. */
1194 #ifdef YYPARSE_PARAM
1195 #if (defined __STDC__ || defined __C99__FUNC__ \
1196 || defined __cplusplus || defined _MSC_VER)
1198 yyparse (void *YYPARSE_PARAM)
1201 yyparse (YYPARSE_PARAM)
1202 void *YYPARSE_PARAM;
1204 #else /* ! YYPARSE_PARAM */
1205 #if (defined __STDC__ || defined __C99__FUNC__ \
1206 || defined __cplusplus || defined _MSC_VER)
1217 /* Number of tokens to shift before error messages enabled. */
1220 /* The stacks and their tools:
1221 `yyss': related to states.
1222 `yyvs': related to semantic values.
1224 Refer to the stacks through separate pointers, to allow yyoverflow
1225 to reallocate them elsewhere. */
1227 /* The state stack. */
1228 yytype_int16 yyssa[YYINITDEPTH];
1230 yytype_int16 *yyssp;
1232 /* The semantic value stack. */
1233 YYSTYPE yyvsa[YYINITDEPTH];
1237 YYSIZE_T yystacksize;
1241 /* Lookahead token as an internal (translated) token number. */
1243 /* The variables used to return semantic value and location from the
1248 /* Buffer for error messages, and its allocated size. */
1250 char *yymsg = yymsgbuf;
1251 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1254 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1256 /* The number of symbols on the RHS of the reduced rule.
1257 Keep to zero when no symbol should be popped. */
1260 yyssp = yyss = yyssa;
1261 yyvsp = yyvs = yyvsa;
1262 yystacksize = YYINITDEPTH;
1264 YYDPRINTF ((stderr, "Starting parse\n"));
1269 yychar = YYEMPTY; /* Cause a token to be read. */
1272 /*------------------------------------------------------------.
1273 | yynewstate -- Push a new state, which is found in yystate. |
1274 `------------------------------------------------------------*/
1276 /* In all cases, when you get here, the value and location stacks
1277 have just been pushed. So pushing a state here evens the stacks. */
1283 if (yyss + yystacksize - 1 <= yyssp)
1285 /* Get the current used size of the three stacks, in elements. */
1286 YYSIZE_T yysize = yyssp - yyss + 1;
1290 /* Give user a chance to reallocate the stack. Use copies of
1291 these so that the &'s don't force the real ones into
1293 YYSTYPE *yyvs1 = yyvs;
1294 yytype_int16 *yyss1 = yyss;
1296 /* Each stack pointer address is followed by the size of the
1297 data in use in that stack, in bytes. This used to be a
1298 conditional around just the two extra args, but that might
1299 be undefined if yyoverflow is a macro. */
1300 yyoverflow (YY_("memory exhausted"),
1301 &yyss1, yysize * sizeof (*yyssp),
1302 &yyvs1, yysize * sizeof (*yyvsp),
1308 #else /* no yyoverflow */
1309 # ifndef YYSTACK_RELOCATE
1310 goto yyexhaustedlab;
1312 /* Extend the stack our own way. */
1313 if (YYMAXDEPTH <= yystacksize)
1314 goto yyexhaustedlab;
1316 if (YYMAXDEPTH < yystacksize)
1317 yystacksize = YYMAXDEPTH;
1320 yytype_int16 *yyss1 = yyss;
1321 union yyalloc *yyptr =
1322 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1324 goto yyexhaustedlab;
1325 YYSTACK_RELOCATE (yyss_alloc, yyss);
1326 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1327 # undef YYSTACK_RELOCATE
1329 YYSTACK_FREE (yyss1);
1332 #endif /* no yyoverflow */
1334 yyssp = yyss + yysize - 1;
1335 yyvsp = yyvs + yysize - 1;
1337 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1338 (unsigned long int) yystacksize));
1340 if (yyss + yystacksize - 1 <= yyssp)
1344 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1346 if (yystate == YYFINAL)
1356 /* Do appropriate processing given the current state. Read a
1357 lookahead token if we need one and don't already have one. */
1359 /* First try to decide what to do without reference to lookahead token. */
1360 yyn = yypact[yystate];
1361 if (yypact_value_is_default (yyn))
1364 /* Not known => get a lookahead token if don't already have one. */
1366 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1367 if (yychar == YYEMPTY)
1369 YYDPRINTF ((stderr, "Reading a token: "));
1373 if (yychar <= YYEOF)
1375 yychar = yytoken = YYEOF;
1376 YYDPRINTF ((stderr, "Now at end of input.\n"));
1380 yytoken = YYTRANSLATE (yychar);
1381 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1384 /* If the proper action on seeing token YYTOKEN is to reduce or to
1385 detect an error, take that action. */
1387 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1392 if (yytable_value_is_error (yyn))
1398 /* Count tokens shifted since error; after three, turn off error
1403 /* Shift the lookahead token. */
1404 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1406 /* Discard the shifted token. */
1410 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1412 YY_IGNORE_MAYBE_UNINITIALIZED_END
1417 /*-----------------------------------------------------------.
1418 | yydefault -- do the default action for the current state. |
1419 `-----------------------------------------------------------*/
1421 yyn = yydefact[yystate];
1427 /*-----------------------------.
1428 | yyreduce -- Do a reduction. |
1429 `-----------------------------*/
1431 /* yyn is the number of a rule to reduce with. */
1434 /* If YYLEN is nonzero, implement the default value of the action:
1437 Otherwise, the following line sets YYVAL to garbage.
1438 This behavior is undocumented and Bison
1439 users should not rely upon it. Assigning to YYVAL
1440 unconditionally makes the parser a bit smaller, and it avoids a
1441 GCC warning that YYVAL may be used uninitialized. */
1442 yyval = yyvsp[1-yylen];
1445 YY_REDUCE_PRINT (yyn);
1449 /* Line 1792 of yacc.c */
1450 #line 74 "slmod_sparql_parser.y"
1452 if (ssp_slq->slq_result_limit)
1453 result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit);
1456 ssp_result = talloc_asprintf(ssp_slq,
1457 "SELECT ?url WHERE "
1458 "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s",
1459 (yyvsp[(1) - (1)].sval), ssp_slq->slq_vol->v_path, result_limit);
1460 (yyval.sval) = ssp_result;
1465 /* Line 1792 of yacc.c */
1466 #line 88 "slmod_sparql_parser.y"
1468 if ((yyvsp[(1) - (1)].bval) == false)
1476 /* Line 1792 of yacc.c */
1477 #line 94 "slmod_sparql_parser.y"
1479 if (!ssp_slq->slq_allow_expr)
1481 if ((yyvsp[(1) - (3)].sval) == NULL || (yyvsp[(3) - (3)].sval) == NULL)
1483 if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1484 (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1486 (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1491 /* Line 1792 of yacc.c */
1492 #line 104 "slmod_sparql_parser.y"
1493 {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;}
1497 /* Line 1792 of yacc.c */
1498 #line 105 "slmod_sparql_parser.y"
1499 {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
1503 /* Line 1792 of yacc.c */
1504 #line 106 "slmod_sparql_parser.y"
1505 {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));}
1509 /* Line 1792 of yacc.c */
1510 #line 107 "slmod_sparql_parser.y"
1512 if (!ssp_slq->slq_allow_expr)
1514 (yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1519 /* Line 1792 of yacc.c */
1520 #line 112 "slmod_sparql_parser.y"
1522 if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1523 (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1525 (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1530 /* Line 1792 of yacc.c */
1531 #line 121 "slmod_sparql_parser.y"
1532 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
1536 /* Line 1792 of yacc.c */
1537 #line 122 "slmod_sparql_parser.y"
1538 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));}
1542 /* Line 1792 of yacc.c */
1543 #line 123 "slmod_sparql_parser.y"
1544 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));}
1548 /* Line 1792 of yacc.c */
1549 #line 124 "slmod_sparql_parser.y"
1550 {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
1554 /* Line 1792 of yacc.c */
1555 #line 125 "slmod_sparql_parser.y"
1556 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));}
1560 /* Line 1792 of yacc.c */
1561 #line 126 "slmod_sparql_parser.y"
1562 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));}
1566 /* Line 1792 of yacc.c */
1567 #line 127 "slmod_sparql_parser.y"
1568 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));}
1572 /* Line 1792 of yacc.c */
1573 #line 128 "slmod_sparql_parser.y"
1574 {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));}
1578 /* Line 1792 of yacc.c */
1579 #line 132 "slmod_sparql_parser.y"
1580 {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));}
1584 /* Line 1792 of yacc.c */
1585 #line 136 "slmod_sparql_parser.y"
1586 {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));}
1590 /* Line 1792 of yacc.c */
1591 #line 137 "slmod_sparql_parser.y"
1592 {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;}
1596 /* Line 1792 of yacc.c */
1597 #line 1598 "slmod_sparql_parser.c"
1600 /* User semantic actions sometimes alter yychar, and that requires
1601 that yytoken be updated with the new translation. We take the
1602 approach of translating immediately before every use of yytoken.
1603 One alternative is translating here after every semantic action,
1604 but that translation would be missed if the semantic action invokes
1605 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1606 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1607 incorrect destructor might then be invoked immediately. In the
1608 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1609 to an incorrect destructor call or verbose syntax error message
1610 before the lookahead is translated. */
1611 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1615 YY_STACK_PRINT (yyss, yyssp);
1619 /* Now `shift' the result of the reduction. Determine what state
1620 that goes to, based on the state we popped back to and the rule
1621 number reduced by. */
1625 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1626 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1627 yystate = yytable[yystate];
1629 yystate = yydefgoto[yyn - YYNTOKENS];
1634 /*------------------------------------.
1635 | yyerrlab -- here on detecting error |
1636 `------------------------------------*/
1638 /* Make sure we have latest lookahead translation. See comments at
1639 user semantic actions for why this is necessary. */
1640 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1642 /* If not already recovering from an error, report this error. */
1646 #if ! YYERROR_VERBOSE
1647 yyerror (YY_("syntax error"));
1649 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1652 char const *yymsgp = YY_("syntax error");
1653 int yysyntax_error_status;
1654 yysyntax_error_status = YYSYNTAX_ERROR;
1655 if (yysyntax_error_status == 0)
1657 else if (yysyntax_error_status == 1)
1659 if (yymsg != yymsgbuf)
1660 YYSTACK_FREE (yymsg);
1661 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1665 yymsg_alloc = sizeof yymsgbuf;
1666 yysyntax_error_status = 2;
1670 yysyntax_error_status = YYSYNTAX_ERROR;
1675 if (yysyntax_error_status == 2)
1676 goto yyexhaustedlab;
1678 # undef YYSYNTAX_ERROR
1684 if (yyerrstatus == 3)
1686 /* If just tried and failed to reuse lookahead token after an
1687 error, discard it. */
1689 if (yychar <= YYEOF)
1691 /* Return failure if at end of input. */
1692 if (yychar == YYEOF)
1697 yydestruct ("Error: discarding",
1703 /* Else will try to reuse lookahead token after shifting the error
1708 /*---------------------------------------------------.
1709 | yyerrorlab -- error raised explicitly by YYERROR. |
1710 `---------------------------------------------------*/
1713 /* Pacify compilers like GCC when the user code never invokes
1714 YYERROR and the label yyerrorlab therefore never appears in user
1716 if (/*CONSTCOND*/ 0)
1719 /* Do not reclaim the symbols of the rule which action triggered
1723 YY_STACK_PRINT (yyss, yyssp);
1728 /*-------------------------------------------------------------.
1729 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1730 `-------------------------------------------------------------*/
1732 yyerrstatus = 3; /* Each real token shifted decrements this. */
1736 yyn = yypact[yystate];
1737 if (!yypact_value_is_default (yyn))
1740 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1748 /* Pop the current state because it cannot handle the error token. */
1753 yydestruct ("Error: popping",
1754 yystos[yystate], yyvsp);
1757 YY_STACK_PRINT (yyss, yyssp);
1760 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1762 YY_IGNORE_MAYBE_UNINITIALIZED_END
1765 /* Shift the error token. */
1766 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1772 /*-------------------------------------.
1773 | yyacceptlab -- YYACCEPT comes here. |
1774 `-------------------------------------*/
1779 /*-----------------------------------.
1780 | yyabortlab -- YYABORT comes here. |
1781 `-----------------------------------*/
1786 #if !defined yyoverflow || YYERROR_VERBOSE
1787 /*-------------------------------------------------.
1788 | yyexhaustedlab -- memory exhaustion comes here. |
1789 `-------------------------------------------------*/
1791 yyerror (YY_("memory exhausted"));
1797 if (yychar != YYEMPTY)
1799 /* Make sure we have latest lookahead translation. See comments at
1800 user semantic actions for why this is necessary. */
1801 yytoken = YYTRANSLATE (yychar);
1802 yydestruct ("Cleanup: discarding lookahead",
1805 /* Do not reclaim the symbols of the rule which action triggered
1806 this YYABORT or YYACCEPT. */
1808 YY_STACK_PRINT (yyss, yyssp);
1809 while (yyssp != yyss)
1811 yydestruct ("Cleanup: popping",
1812 yystos[*yyssp], yyvsp);
1817 YYSTACK_FREE (yyss);
1820 if (yymsg != yymsgbuf)
1821 YYSTACK_FREE (yymsg);
1823 /* Make sure YYID is used. */
1824 return YYID (yyresult);
1828 /* Line 2055 of yacc.c */
1829 #line 140 "slmod_sparql_parser.y"
1832 static time_t isodate2unix(const char *s)
1836 if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL)
1841 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2)
1844 char *result = NULL;
1845 struct spotlight_sparql_map *p;
1847 char buf1[64], buf2[64];
1849 EC_NULL_LOG( tmp = localtime(&date1) );
1850 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1851 EC_NULL_LOG( tmp = localtime(&date2) );
1852 strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
1854 for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1855 if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) {
1856 result = talloc_asprintf(ssp_slq,
1857 "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')",
1875 static char *map_type_search(const char *attr, char op, const char *val)
1877 char *result = NULL;
1878 const char *sparqlAttr;
1880 for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) {
1881 if (strcmp(p->mdtm_value, val) == 0) {
1882 switch (p->mdtm_type) {
1884 sparqlAttr = "rdf:type";
1886 case kMDTypeMapMime:
1887 sparqlAttr = "nie:mimeType";
1892 result = talloc_asprintf(ssp_slq, "?obj %s '%s'",
1901 static const char *map_expr(const char *attr, char op, const char *val)
1904 char *result = NULL;
1905 struct spotlight_sparql_map *p;
1909 bstring q = NULL, search = NULL, replace = NULL;
1911 for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1912 if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) {
1913 if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) {
1914 yyerror("unsupported Spotlight attribute");
1917 switch (p->ssm_type) {
1919 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1922 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')",
1927 op == '!' ? '=' : ' ', /* append '=' to '!' */
1932 q = bformat("^%s$", val);
1933 search = bfromcstr("*");
1934 replace = bfromcstr(".*");
1935 bfindreplace(q, search, replace, 0);
1936 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))",
1944 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1947 t = atoi(val) + SPRAW_TIME_OFFSET;
1948 EC_NULL( tmp = localtime(&t) );
1949 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1950 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')",
1959 result = map_type_search(attr, op, val);
1978 void yyerror(const char *str)
1981 printf("yyerror: %s\n", str);
1983 LOG(log_error, logtype_sl, "yyerror: %s", str);
1993 * Map a Spotlight RAW query string to a SPARQL query string
1995 * @param[in] slq Spotlight query handle
1996 * @param[out] sparql_result Mapped SPARQL query, string is allocated in
1997 * talloc context of slq
1998 * @return 0 on success, -1 on error
2000 int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result)
2003 YY_BUFFER_STATE s = NULL;
2007 s = yy_scan_string(slq->slq_qstring);
2010 EC_ZERO( yyparse() );
2014 yy_delete_buffer(s);
2016 *sparql_result = ssp_result;
2018 *sparql_result = NULL;
2023 int main(int argc, char **argv)
2029 printf("usage: %s QUERY\n", argv[0]);
2033 ssp_slq = talloc_zero(NULL, slq_t);
2034 struct vol *vol = talloc_zero(ssp_slq, struct vol);
2035 vol->v_path = "/Volumes/test";
2036 ssp_slq->slq_vol = vol;
2037 ssp_slq->slq_allow_expr = true;
2040 s = yy_scan_string(argv[1]);
2044 yy_delete_buffer(s);
2047 printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)");