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