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