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