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