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