Blob


1 /* A Bison parser, made by GNU Bison 3.7.6. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30706
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.6"
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
57 /* Pure parsers. */
58 #define YYPURE 0
60 /* Push parsers. */
61 #define YYPUSH 0
63 /* Pull parsers. */
64 #define YYPULL 1
69 /* First part of user prologue. */
70 #line 24 "parse.y"
73 #include <sys/queue.h>
75 #include <ctype.h>
76 #include <err.h>
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <stdarg.h>
80 #include <stdint.h>
81 #include <string.h>
82 #include <unistd.h>
84 #ifndef nitems
85 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
86 #endif
88 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
89 static struct file {
90 TAILQ_ENTRY(file) entry;
91 FILE *stream;
92 char *name;
93 size_t ungetpos;
94 size_t ungetsize;
95 u_char *ungetbuf;
96 int eof_reached;
97 int lineno;
98 int errors;
99 } *file, *topfile;
100 int parse(const char *);
101 struct file *pushfile(const char *, int);
102 int popfile(void);
103 int yyparse(void);
104 int yylex(void);
105 int yyerror(const char *, ...)
106 __attribute__((__format__ (printf, 1, 2)))
107 __attribute__((__nonnull__ (1)));
108 int kw_cmp(const void *, const void *);
109 int lookup(char *);
110 int igetc(void);
111 int lgetc(int);
112 void lungetc(int);
113 int findeol(void);
115 void dbg(void);
116 void printq(const char *);
118 extern int nodebug;
120 static int block;
121 static int in_define;
122 static int errors;
123 static char lerr[32];
125 typedef struct {
126 union {
127 char *string;
128 } v;
129 int lineno;
130 } YYSTYPE;
133 #line 134 "y.tab.c"
135 # ifndef YY_CAST
136 # ifdef __cplusplus
137 # define YY_CAST(Type, Val) static_cast<Type> (Val)
138 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
139 # else
140 # define YY_CAST(Type, Val) ((Type) (Val))
141 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
142 # endif
143 # endif
144 # ifndef YY_NULLPTR
145 # if defined __cplusplus
146 # if 201103L <= __cplusplus
147 # define YY_NULLPTR nullptr
148 # else
149 # define YY_NULLPTR 0
150 # endif
151 # else
152 # define YY_NULLPTR ((void*)0)
153 # endif
154 # endif
157 /* Debug traces. */
158 #ifndef YYDEBUG
159 # define YYDEBUG 0
160 #endif
161 #if YYDEBUG
162 extern int yydebug;
163 #endif
165 /* Token kinds. */
166 #ifndef YYTOKENTYPE
167 # define YYTOKENTYPE
168 enum yytokentype
170 YYEMPTY = -2,
171 YYEOF = 0, /* "end of file" */
172 YYerror = 256, /* error */
173 YYUNDEF = 257, /* "invalid token" */
174 DEFINE = 258, /* DEFINE */
175 ELSE = 259, /* ELSE */
176 END = 260, /* END */
177 ERROR = 261, /* ERROR */
178 FINALLY = 262, /* FINALLY */
179 IF = 263, /* IF */
180 INCLUDE = 264, /* INCLUDE */
181 RENDER = 265, /* RENDER */
182 TQFOREACH = 266, /* TQFOREACH */
183 STRING = 267 /* STRING */
184 };
185 typedef enum yytokentype yytoken_kind_t;
186 #endif
187 /* Token kinds. */
188 #define YYEMPTY -2
189 #define YYEOF 0
190 #define YYerror 256
191 #define YYUNDEF 257
192 #define DEFINE 258
193 #define ELSE 259
194 #define END 260
195 #define ERROR 261
196 #define FINALLY 262
197 #define IF 263
198 #define INCLUDE 264
199 #define RENDER 265
200 #define TQFOREACH 266
201 #define STRING 267
203 /* Value type. */
206 extern YYSTYPE yylval;
208 int yyparse (void);
211 /* Symbol kind. */
212 enum yysymbol_kind_t
214 YYSYMBOL_YYEMPTY = -2,
215 YYSYMBOL_YYEOF = 0, /* "end of file" */
216 YYSYMBOL_YYerror = 1, /* error */
217 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
218 YYSYMBOL_DEFINE = 3, /* DEFINE */
219 YYSYMBOL_ELSE = 4, /* ELSE */
220 YYSYMBOL_END = 5, /* END */
221 YYSYMBOL_ERROR = 6, /* ERROR */
222 YYSYMBOL_FINALLY = 7, /* FINALLY */
223 YYSYMBOL_IF = 8, /* IF */
224 YYSYMBOL_INCLUDE = 9, /* INCLUDE */
225 YYSYMBOL_RENDER = 10, /* RENDER */
226 YYSYMBOL_TQFOREACH = 11, /* TQFOREACH */
227 YYSYMBOL_STRING = 12, /* STRING */
228 YYSYMBOL_13_ = 13, /* '!' */
229 YYSYMBOL_14_ = 14, /* '{' */
230 YYSYMBOL_15_ = 15, /* '}' */
231 YYSYMBOL_YYACCEPT = 16, /* $accept */
232 YYSYMBOL_grammar = 17, /* grammar */
233 YYSYMBOL_include = 18, /* include */
234 YYSYMBOL_verbatim = 19, /* verbatim */
235 YYSYMBOL_verbatim1 = 20, /* verbatim1 */
236 YYSYMBOL_verbatims = 21, /* verbatims */
237 YYSYMBOL_raw = 22, /* raw */
238 YYSYMBOL_block = 23, /* block */
239 YYSYMBOL_define = 24, /* define */
240 YYSYMBOL_body = 25, /* body */
241 YYSYMBOL_special = 26, /* special */
242 YYSYMBOL_if = 27, /* if */
243 YYSYMBOL_endif = 28, /* endif */
244 YYSYMBOL_elsif = 29, /* elsif */
245 YYSYMBOL_else = 30, /* else */
246 YYSYMBOL_loop = 31, /* loop */
247 YYSYMBOL_32_1 = 32, /* $@1 */
248 YYSYMBOL_end = 33, /* end */
249 YYSYMBOL_finally = 34, /* finally */
250 YYSYMBOL_35_2 = 35, /* $@2 */
251 YYSYMBOL_string = 36 /* string */
252 };
253 typedef enum yysymbol_kind_t yysymbol_kind_t;
258 #ifdef short
259 # undef short
260 #endif
262 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
263 <limits.h> and (if available) <stdint.h> are included
264 so that the code can choose integer types of a good width. */
266 #ifndef __PTRDIFF_MAX__
267 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
268 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
269 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
270 # define YY_STDINT_H
271 # endif
272 #endif
274 /* Narrow types that promote to a signed type and that can represent a
275 signed or unsigned integer of at least N bits. In tables they can
276 save space and decrease cache pressure. Promoting to a signed type
277 helps avoid bugs in integer arithmetic. */
279 #ifdef __INT_LEAST8_MAX__
280 typedef __INT_LEAST8_TYPE__ yytype_int8;
281 #elif defined YY_STDINT_H
282 typedef int_least8_t yytype_int8;
283 #else
284 typedef signed char yytype_int8;
285 #endif
287 #ifdef __INT_LEAST16_MAX__
288 typedef __INT_LEAST16_TYPE__ yytype_int16;
289 #elif defined YY_STDINT_H
290 typedef int_least16_t yytype_int16;
291 #else
292 typedef short yytype_int16;
293 #endif
295 /* Work around bug in HP-UX 11.23, which defines these macros
296 incorrectly for preprocessor constants. This workaround can likely
297 be removed in 2023, as HPE has promised support for HP-UX 11.23
298 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
299 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
300 #ifdef __hpux
301 # undef UINT_LEAST8_MAX
302 # undef UINT_LEAST16_MAX
303 # define UINT_LEAST8_MAX 255
304 # define UINT_LEAST16_MAX 65535
305 #endif
307 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
308 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
309 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
310 && UINT_LEAST8_MAX <= INT_MAX)
311 typedef uint_least8_t yytype_uint8;
312 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
313 typedef unsigned char yytype_uint8;
314 #else
315 typedef short yytype_uint8;
316 #endif
318 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
319 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
320 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
321 && UINT_LEAST16_MAX <= INT_MAX)
322 typedef uint_least16_t yytype_uint16;
323 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
324 typedef unsigned short yytype_uint16;
325 #else
326 typedef int yytype_uint16;
327 #endif
329 #ifndef YYPTRDIFF_T
330 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
331 # define YYPTRDIFF_T __PTRDIFF_TYPE__
332 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
333 # elif defined PTRDIFF_MAX
334 # ifndef ptrdiff_t
335 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
336 # endif
337 # define YYPTRDIFF_T ptrdiff_t
338 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
339 # else
340 # define YYPTRDIFF_T long
341 # define YYPTRDIFF_MAXIMUM LONG_MAX
342 # endif
343 #endif
345 #ifndef YYSIZE_T
346 # ifdef __SIZE_TYPE__
347 # define YYSIZE_T __SIZE_TYPE__
348 # elif defined size_t
349 # define YYSIZE_T size_t
350 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
351 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
352 # define YYSIZE_T size_t
353 # else
354 # define YYSIZE_T unsigned
355 # endif
356 #endif
358 #define YYSIZE_MAXIMUM \
359 YY_CAST (YYPTRDIFF_T, \
360 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
361 ? YYPTRDIFF_MAXIMUM \
362 : YY_CAST (YYSIZE_T, -1)))
364 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
367 /* Stored state numbers (used for stacks). */
368 typedef yytype_int8 yy_state_t;
370 /* State numbers in computations. */
371 typedef int yy_state_fast_t;
373 #ifndef YY_
374 # if defined YYENABLE_NLS && YYENABLE_NLS
375 # if ENABLE_NLS
376 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
377 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
378 # endif
379 # endif
380 # ifndef YY_
381 # define YY_(Msgid) Msgid
382 # endif
383 #endif
386 #ifndef YY_ATTRIBUTE_PURE
387 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
388 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
389 # else
390 # define YY_ATTRIBUTE_PURE
391 # endif
392 #endif
394 #ifndef YY_ATTRIBUTE_UNUSED
395 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
396 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
397 # else
398 # define YY_ATTRIBUTE_UNUSED
399 # endif
400 #endif
402 /* Suppress unused-variable warnings by "using" E. */
403 #if ! defined lint || defined __GNUC__
404 # define YY_USE(E) ((void) (E))
405 #else
406 # define YY_USE(E) /* empty */
407 #endif
409 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
410 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
411 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
412 _Pragma ("GCC diagnostic push") \
413 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
414 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
415 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
416 _Pragma ("GCC diagnostic pop")
417 #else
418 # define YY_INITIAL_VALUE(Value) Value
419 #endif
420 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
421 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
422 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
423 #endif
424 #ifndef YY_INITIAL_VALUE
425 # define YY_INITIAL_VALUE(Value) /* Nothing. */
426 #endif
428 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
429 # define YY_IGNORE_USELESS_CAST_BEGIN \
430 _Pragma ("GCC diagnostic push") \
431 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
432 # define YY_IGNORE_USELESS_CAST_END \
433 _Pragma ("GCC diagnostic pop")
434 #endif
435 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
436 # define YY_IGNORE_USELESS_CAST_BEGIN
437 # define YY_IGNORE_USELESS_CAST_END
438 #endif
441 #define YY_ASSERT(E) ((void) (0 && (E)))
443 #if !defined yyoverflow
445 /* The parser invokes alloca or malloc; define the necessary symbols. */
447 # ifdef YYSTACK_USE_ALLOCA
448 # if YYSTACK_USE_ALLOCA
449 # ifdef __GNUC__
450 # define YYSTACK_ALLOC __builtin_alloca
451 # elif defined __BUILTIN_VA_ARG_INCR
452 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
453 # elif defined _AIX
454 # define YYSTACK_ALLOC __alloca
455 # elif defined _MSC_VER
456 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
457 # define alloca _alloca
458 # else
459 # define YYSTACK_ALLOC alloca
460 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
461 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
462 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
463 # ifndef EXIT_SUCCESS
464 # define EXIT_SUCCESS 0
465 # endif
466 # endif
467 # endif
468 # endif
469 # endif
471 # ifdef YYSTACK_ALLOC
472 /* Pacify GCC's 'empty if-body' warning. */
473 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
474 # ifndef YYSTACK_ALLOC_MAXIMUM
475 /* The OS might guarantee only one guard page at the bottom of the stack,
476 and a page size can be as small as 4096 bytes. So we cannot safely
477 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
478 to allow for a few compiler-allocated temporary stack slots. */
479 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
480 # endif
481 # else
482 # define YYSTACK_ALLOC YYMALLOC
483 # define YYSTACK_FREE YYFREE
484 # ifndef YYSTACK_ALLOC_MAXIMUM
485 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
486 # endif
487 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
488 && ! ((defined YYMALLOC || defined malloc) \
489 && (defined YYFREE || defined free)))
490 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
491 # ifndef EXIT_SUCCESS
492 # define EXIT_SUCCESS 0
493 # endif
494 # endif
495 # ifndef YYMALLOC
496 # define YYMALLOC malloc
497 # if ! defined malloc && ! defined EXIT_SUCCESS
498 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
499 # endif
500 # endif
501 # ifndef YYFREE
502 # define YYFREE free
503 # if ! defined free && ! defined EXIT_SUCCESS
504 void free (void *); /* INFRINGES ON USER NAME SPACE */
505 # endif
506 # endif
507 # endif
508 #endif /* !defined yyoverflow */
510 #if (! defined yyoverflow \
511 && (! defined __cplusplus \
512 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
514 /* A type that is properly aligned for any stack member. */
515 union yyalloc
517 yy_state_t yyss_alloc;
518 YYSTYPE yyvs_alloc;
519 };
521 /* The size of the maximum gap between one aligned stack and the next. */
522 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
524 /* The size of an array large to enough to hold all stacks, each with
525 N elements. */
526 # define YYSTACK_BYTES(N) \
527 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
528 + YYSTACK_GAP_MAXIMUM)
530 # define YYCOPY_NEEDED 1
532 /* Relocate STACK from its old location to the new one. The
533 local variables YYSIZE and YYSTACKSIZE give the old and new number of
534 elements in the stack, and YYPTR gives the new location of the
535 stack. Advance YYPTR to a properly aligned location for the next
536 stack. */
537 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
538 do \
539 { \
540 YYPTRDIFF_T yynewbytes; \
541 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
542 Stack = &yyptr->Stack_alloc; \
543 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
544 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
545 } \
546 while (0)
548 #endif
550 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
551 /* Copy COUNT objects from SRC to DST. The source and destination do
552 not overlap. */
553 # ifndef YYCOPY
554 # if defined __GNUC__ && 1 < __GNUC__
555 # define YYCOPY(Dst, Src, Count) \
556 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
557 # else
558 # define YYCOPY(Dst, Src, Count) \
559 do \
560 { \
561 YYPTRDIFF_T yyi; \
562 for (yyi = 0; yyi < (Count); yyi++) \
563 (Dst)[yyi] = (Src)[yyi]; \
564 } \
565 while (0)
566 # endif
567 # endif
568 #endif /* !YYCOPY_NEEDED */
570 /* YYFINAL -- State number of the termination state. */
571 #define YYFINAL 2
572 /* YYLAST -- Last index in YYTABLE. */
573 #define YYLAST 69
575 /* YYNTOKENS -- Number of terminals. */
576 #define YYNTOKENS 16
577 /* YYNNTS -- Number of nonterminals. */
578 #define YYNNTS 21
579 /* YYNRULES -- Number of rules. */
580 #define YYNRULES 37
581 /* YYNSTATES -- Number of states. */
582 #define YYNSTATES 71
584 /* YYMAXUTOK -- Last valid token kind. */
585 #define YYMAXUTOK 267
588 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
589 as returned by yylex, with out-of-bounds checking. */
590 #define YYTRANSLATE(YYX) \
591 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
592 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
593 : YYSYMBOL_YYUNDEF)
595 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
596 as returned by yylex. */
597 static const yytype_int8 yytranslate[] =
599 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
600 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
601 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
602 2, 2, 2, 13, 2, 2, 2, 2, 2, 2,
603 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
604 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
605 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
606 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
607 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
608 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
609 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
610 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
611 2, 2, 2, 14, 2, 15, 2, 2, 2, 2,
612 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
613 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
614 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
615 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
616 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
617 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
625 5, 6, 7, 8, 9, 10, 11, 12
626 };
628 #if YYDEBUG
629 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
630 static const yytype_uint8 yyrline[] =
632 0, 93, 93, 94, 95, 96, 97, 100, 115, 122,
633 123, 132, 133, 136, 146, 152, 159, 171, 172, 173,
634 174, 177, 187, 188, 189, 196, 203, 204, 205, 208,
635 215, 221, 221, 232, 235, 235, 241, 247
636 };
637 #endif
639 /** Accessing symbol of state STATE. */
640 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
642 #if YYDEBUG || 0
643 /* The user-facing name of the symbol whose (internal) number is
644 YYSYMBOL. No bounds checking. */
645 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
647 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
648 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
649 static const char *const yytname[] =
651 "\"end of file\"", "error", "\"invalid token\"", "DEFINE", "ELSE",
652 "END", "ERROR", "FINALLY", "IF", "INCLUDE", "RENDER", "TQFOREACH",
653 "STRING", "'!'", "'{'", "'}'", "$accept", "grammar", "include",
654 "verbatim", "verbatim1", "verbatims", "raw", "block", "define", "body",
655 "special", "if", "endif", "elsif", "else", "loop", "$@1", "end",
656 "finally", "$@2", "string", YY_NULLPTR
657 };
659 static const char *
660 yysymbol_name (yysymbol_kind_t yysymbol)
662 return yytname[yysymbol];
664 #endif
666 #ifdef YYPRINT
667 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
668 (internal) symbol number NUM (which must be that of a token). */
669 static const yytype_int16 yytoknum[] =
671 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
672 265, 266, 267, 33, 123, 125
673 };
674 #endif
676 #define YYPACT_NINF (-21)
678 #define yypact_value_is_default(Yyn) \
679 ((Yyn) == YYPACT_NINF)
681 #define YYTABLE_NINF (-1)
683 #define yytable_value_is_error(Yyn) \
686 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
687 STATE-NUM. */
688 static const yytype_int8 yypact[] =
690 -21, 5, -21, -21, 4, -21, 14, -21, -21, -21,
691 -21, -21, 0, 8, -3, -21, -21, 8, 6, -21,
692 29, -21, -21, -21, -21, -21, -21, 10, -21, -21,
693 15, 20, 8, 8, 26, 27, 41, 38, -21, -21,
694 -21, 31, 47, 49, -21, 21, -21, -21, -21, -21,
695 -21, -21, -21, 51, -7, 41, 46, 52, 53, 8,
696 -21, -21, 40, -21, -21, -21, 54, -21, -21, 46,
697 -21
698 };
700 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
701 Performed when YYTABLE does not specify something else to do. Zero
702 means the default is an error. */
703 static const yytype_int8 yydefact[] =
705 2, 0, 1, 6, 0, 9, 0, 3, 4, 5,
706 17, 7, 0, 0, 0, 10, 8, 37, 0, 13,
707 0, 18, 19, 20, 17, 23, 14, 0, 36, 16,
708 0, 0, 0, 0, 0, 0, 0, 0, 15, 33,
709 34, 0, 0, 0, 24, 0, 22, 17, 17, 26,
710 11, 25, 21, 0, 0, 0, 0, 35, 0, 0,
711 30, 28, 0, 27, 12, 31, 0, 17, 29, 0,
712 32
713 };
715 /* YYPGOTO[NTERM-NUM]. */
716 static const yytype_int8 yypgoto[] =
718 -21, -21, -21, -1, -21, -21, -21, -21, -21, -20,
719 -21, -21, 9, -21, -21, -21, -21, -12, -21, -21,
720 -10
721 };
723 /* YYDEFGOTO[NTERM-NUM]. */
724 static const yytype_int8 yydefgoto[] =
726 0, 1, 7, 21, 12, 57, 22, 9, 10, 14,
727 23, 24, 46, 47, 48, 25, 67, 49, 27, 50,
728 35
729 };
731 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
732 positive, shift that token. If negative, reduce the rule whose
733 number is the opposite. If YYTABLE_NINF, syntax error. */
734 static const yytype_int8 yytable[] =
736 8, 59, 26, 18, 36, 2, 3, 28, 60, 19,
737 5, 20, 15, 16, 4, 38, 11, 13, 5, 6,
738 17, 29, 41, 42, 37, 54, 30, 55, 56, 32,
739 39, 33, 34, 17, 30, 40, 31, 32, 43, 33,
740 34, 17, 44, 30, 63, 30, 51, 69, 32, 66,
741 33, 34, 17, 19, 5, 45, 64, 70, 19, 5,
742 62, 53, 52, 58, 61, 5, 0, 0, 65, 68
743 };
745 static const yytype_int8 yycheck[] =
747 1, 8, 14, 13, 24, 0, 1, 17, 15, 12,
748 13, 14, 12, 13, 9, 27, 12, 3, 13, 14,
749 12, 15, 32, 33, 14, 4, 5, 47, 48, 8,
750 15, 10, 11, 12, 5, 15, 7, 8, 12, 10,
751 11, 12, 15, 5, 56, 5, 15, 67, 8, 59,
752 10, 11, 12, 12, 13, 14, 57, 69, 12, 13,
753 14, 12, 15, 12, 55, 13, -1, -1, 15, 15
754 };
756 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
757 symbol of state STATE-NUM. */
758 static const yytype_int8 yystos[] =
760 0, 17, 0, 1, 9, 13, 14, 18, 19, 23,
761 24, 12, 20, 3, 25, 12, 13, 12, 36, 12,
762 14, 19, 22, 26, 27, 31, 33, 34, 36, 15,
763 5, 7, 8, 10, 11, 36, 25, 14, 33, 15,
764 15, 36, 36, 12, 15, 14, 28, 29, 30, 33,
765 35, 15, 15, 12, 4, 25, 25, 21, 12, 8,
766 15, 28, 14, 33, 19, 15, 36, 32, 15, 25,
767 33
768 };
770 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
771 static const yytype_int8 yyr1[] =
773 0, 16, 17, 17, 17, 17, 17, 18, 19, 20,
774 20, 21, 21, 22, 23, 23, 24, 25, 25, 25,
775 25, 26, 26, 26, 26, 27, 28, 28, 28, 29,
776 30, 32, 31, 33, 35, 34, 36, 36
777 };
779 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
780 static const yytype_int8 yyr2[] =
782 0, 2, 0, 2, 2, 2, 2, 2, 3, 0,
783 2, 0, 2, 1, 3, 4, 4, 0, 2, 2,
784 2, 4, 3, 1, 3, 4, 1, 3, 3, 5,
785 3, 0, 9, 3, 0, 5, 2, 1
786 };
789 enum { YYENOMEM = -2 };
791 #define yyerrok (yyerrstatus = 0)
792 #define yyclearin (yychar = YYEMPTY)
794 #define YYACCEPT goto yyacceptlab
795 #define YYABORT goto yyabortlab
796 #define YYERROR goto yyerrorlab
799 #define YYRECOVERING() (!!yyerrstatus)
801 #define YYBACKUP(Token, Value) \
802 do \
803 if (yychar == YYEMPTY) \
804 { \
805 yychar = (Token); \
806 yylval = (Value); \
807 YYPOPSTACK (yylen); \
808 yystate = *yyssp; \
809 goto yybackup; \
810 } \
811 else \
812 { \
813 yyerror (YY_("syntax error: cannot back up")); \
814 YYERROR; \
815 } \
816 while (0)
818 /* Backward compatibility with an undocumented macro.
819 Use YYerror or YYUNDEF. */
820 #define YYERRCODE YYUNDEF
823 /* Enable debugging if requested. */
824 #if YYDEBUG
826 # ifndef YYFPRINTF
827 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
828 # define YYFPRINTF fprintf
829 # endif
831 # define YYDPRINTF(Args) \
832 do { \
833 if (yydebug) \
834 YYFPRINTF Args; \
835 } while (0)
837 /* This macro is provided for backward compatibility. */
838 # ifndef YY_LOCATION_PRINT
839 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
840 # endif
843 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
844 do { \
845 if (yydebug) \
846 { \
847 YYFPRINTF (stderr, "%s ", Title); \
848 yy_symbol_print (stderr, \
849 Kind, Value); \
850 YYFPRINTF (stderr, "\n"); \
851 } \
852 } while (0)
855 /*-----------------------------------.
856 | Print this symbol's value on YYO. |
857 `-----------------------------------*/
859 static void
860 yy_symbol_value_print (FILE *yyo,
861 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
863 FILE *yyoutput = yyo;
864 YY_USE (yyoutput);
865 if (!yyvaluep)
866 return;
867 # ifdef YYPRINT
868 if (yykind < YYNTOKENS)
869 YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
870 # endif
871 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
872 YY_USE (yykind);
873 YY_IGNORE_MAYBE_UNINITIALIZED_END
877 /*---------------------------.
878 | Print this symbol on YYO. |
879 `---------------------------*/
881 static void
882 yy_symbol_print (FILE *yyo,
883 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
885 YYFPRINTF (yyo, "%s %s (",
886 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
888 yy_symbol_value_print (yyo, yykind, yyvaluep);
889 YYFPRINTF (yyo, ")");
892 /*------------------------------------------------------------------.
893 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
894 | TOP (included). |
895 `------------------------------------------------------------------*/
897 static void
898 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
900 YYFPRINTF (stderr, "Stack now");
901 for (; yybottom <= yytop; yybottom++)
903 int yybot = *yybottom;
904 YYFPRINTF (stderr, " %d", yybot);
906 YYFPRINTF (stderr, "\n");
909 # define YY_STACK_PRINT(Bottom, Top) \
910 do { \
911 if (yydebug) \
912 yy_stack_print ((Bottom), (Top)); \
913 } while (0)
916 /*------------------------------------------------.
917 | Report that the YYRULE is going to be reduced. |
918 `------------------------------------------------*/
920 static void
921 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
922 int yyrule)
924 int yylno = yyrline[yyrule];
925 int yynrhs = yyr2[yyrule];
926 int yyi;
927 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
928 yyrule - 1, yylno);
929 /* The symbols being reduced. */
930 for (yyi = 0; yyi < yynrhs; yyi++)
932 YYFPRINTF (stderr, " $%d = ", yyi + 1);
933 yy_symbol_print (stderr,
934 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
935 &yyvsp[(yyi + 1) - (yynrhs)]);
936 YYFPRINTF (stderr, "\n");
940 # define YY_REDUCE_PRINT(Rule) \
941 do { \
942 if (yydebug) \
943 yy_reduce_print (yyssp, yyvsp, Rule); \
944 } while (0)
946 /* Nonzero means print parse trace. It is left uninitialized so that
947 multiple parsers can coexist. */
948 int yydebug;
949 #else /* !YYDEBUG */
950 # define YYDPRINTF(Args) ((void) 0)
951 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
952 # define YY_STACK_PRINT(Bottom, Top)
953 # define YY_REDUCE_PRINT(Rule)
954 #endif /* !YYDEBUG */
957 /* YYINITDEPTH -- initial size of the parser's stacks. */
958 #ifndef YYINITDEPTH
959 # define YYINITDEPTH 200
960 #endif
962 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
963 if the built-in stack extension method is used).
965 Do not make this value too large; the results are undefined if
966 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
967 evaluated with infinite-precision integer arithmetic. */
969 #ifndef YYMAXDEPTH
970 # define YYMAXDEPTH 10000
971 #endif
978 /*-----------------------------------------------.
979 | Release the memory associated to this symbol. |
980 `-----------------------------------------------*/
982 static void
983 yydestruct (const char *yymsg,
984 yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
986 YY_USE (yyvaluep);
987 if (!yymsg)
988 yymsg = "Deleting";
989 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
991 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
992 YY_USE (yykind);
993 YY_IGNORE_MAYBE_UNINITIALIZED_END
997 /* Lookahead token kind. */
998 int yychar;
1000 /* The semantic value of the lookahead symbol. */
1001 YYSTYPE yylval;
1002 /* Number of syntax errors so far. */
1003 int yynerrs;
1008 /*----------.
1009 | yyparse. |
1010 `----------*/
1012 int
1013 yyparse (void)
1015 yy_state_fast_t yystate = 0;
1016 /* Number of tokens to shift before error messages enabled. */
1017 int yyerrstatus = 0;
1019 /* Refer to the stacks through separate pointers, to allow yyoverflow
1020 to reallocate them elsewhere. */
1022 /* Their size. */
1023 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1025 /* The state stack: array, bottom, top. */
1026 yy_state_t yyssa[YYINITDEPTH];
1027 yy_state_t *yyss = yyssa;
1028 yy_state_t *yyssp = yyss;
1030 /* The semantic value stack: array, bottom, top. */
1031 YYSTYPE yyvsa[YYINITDEPTH];
1032 YYSTYPE *yyvs = yyvsa;
1033 YYSTYPE *yyvsp = yyvs;
1035 int yyn;
1036 /* The return value of yyparse. */
1037 int yyresult;
1038 /* Lookahead symbol kind. */
1039 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1040 /* The variables used to return semantic value and location from the
1041 action routines. */
1042 YYSTYPE yyval;
1046 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1048 /* The number of symbols on the RHS of the reduced rule.
1049 Keep to zero when no symbol should be popped. */
1050 int yylen = 0;
1052 YYDPRINTF ((stderr, "Starting parse\n"));
1054 yychar = YYEMPTY; /* Cause a token to be read. */
1055 goto yysetstate;
1058 /*------------------------------------------------------------.
1059 | yynewstate -- push a new state, which is found in yystate. |
1060 `------------------------------------------------------------*/
1061 yynewstate:
1062 /* In all cases, when you get here, the value and location stacks
1063 have just been pushed. So pushing a state here evens the stacks. */
1064 yyssp++;
1067 /*--------------------------------------------------------------------.
1068 | yysetstate -- set current state (the top of the stack) to yystate. |
1069 `--------------------------------------------------------------------*/
1070 yysetstate:
1071 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1072 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1073 YY_IGNORE_USELESS_CAST_BEGIN
1074 *yyssp = YY_CAST (yy_state_t, yystate);
1075 YY_IGNORE_USELESS_CAST_END
1076 YY_STACK_PRINT (yyss, yyssp);
1078 if (yyss + yystacksize - 1 <= yyssp)
1079 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1080 goto yyexhaustedlab;
1081 #else
1083 /* Get the current used size of the three stacks, in elements. */
1084 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1086 # if defined yyoverflow
1088 /* Give user a chance to reallocate the stack. Use copies of
1089 these so that the &'s don't force the real ones into
1090 memory. */
1091 yy_state_t *yyss1 = yyss;
1092 YYSTYPE *yyvs1 = yyvs;
1094 /* Each stack pointer address is followed by the size of the
1095 data in use in that stack, in bytes. This used to be a
1096 conditional around just the two extra args, but that might
1097 be undefined if yyoverflow is a macro. */
1098 yyoverflow (YY_("memory exhausted"),
1099 &yyss1, yysize * YYSIZEOF (*yyssp),
1100 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1101 &yystacksize);
1102 yyss = yyss1;
1103 yyvs = yyvs1;
1105 # else /* defined YYSTACK_RELOCATE */
1106 /* Extend the stack our own way. */
1107 if (YYMAXDEPTH <= yystacksize)
1108 goto yyexhaustedlab;
1109 yystacksize *= 2;
1110 if (YYMAXDEPTH < yystacksize)
1111 yystacksize = YYMAXDEPTH;
1114 yy_state_t *yyss1 = yyss;
1115 union yyalloc *yyptr =
1116 YY_CAST (union yyalloc *,
1117 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1118 if (! yyptr)
1119 goto yyexhaustedlab;
1120 YYSTACK_RELOCATE (yyss_alloc, yyss);
1121 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1122 # undef YYSTACK_RELOCATE
1123 if (yyss1 != yyssa)
1124 YYSTACK_FREE (yyss1);
1126 # endif
1128 yyssp = yyss + yysize - 1;
1129 yyvsp = yyvs + yysize - 1;
1131 YY_IGNORE_USELESS_CAST_BEGIN
1132 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1133 YY_CAST (long, yystacksize)));
1134 YY_IGNORE_USELESS_CAST_END
1136 if (yyss + yystacksize - 1 <= yyssp)
1137 YYABORT;
1139 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1141 if (yystate == YYFINAL)
1142 YYACCEPT;
1144 goto yybackup;
1147 /*-----------.
1148 | yybackup. |
1149 `-----------*/
1150 yybackup:
1151 /* Do appropriate processing given the current state. Read a
1152 lookahead token if we need one and don't already have one. */
1154 /* First try to decide what to do without reference to lookahead token. */
1155 yyn = yypact[yystate];
1156 if (yypact_value_is_default (yyn))
1157 goto yydefault;
1159 /* Not known => get a lookahead token if don't already have one. */
1161 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1162 if (yychar == YYEMPTY)
1164 YYDPRINTF ((stderr, "Reading a token\n"));
1165 yychar = yylex ();
1168 if (yychar <= YYEOF)
1170 yychar = YYEOF;
1171 yytoken = YYSYMBOL_YYEOF;
1172 YYDPRINTF ((stderr, "Now at end of input.\n"));
1174 else if (yychar == YYerror)
1176 /* The scanner already issued an error message, process directly
1177 to error recovery. But do not keep the error token as
1178 lookahead, it is too special and may lead us to an endless
1179 loop in error recovery. */
1180 yychar = YYUNDEF;
1181 yytoken = YYSYMBOL_YYerror;
1182 goto yyerrlab1;
1184 else
1186 yytoken = YYTRANSLATE (yychar);
1187 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1190 /* If the proper action on seeing token YYTOKEN is to reduce or to
1191 detect an error, take that action. */
1192 yyn += yytoken;
1193 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1194 goto yydefault;
1195 yyn = yytable[yyn];
1196 if (yyn <= 0)
1198 if (yytable_value_is_error (yyn))
1199 goto yyerrlab;
1200 yyn = -yyn;
1201 goto yyreduce;
1204 /* Count tokens shifted since error; after three, turn off error
1205 status. */
1206 if (yyerrstatus)
1207 yyerrstatus--;
1209 /* Shift the lookahead token. */
1210 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1211 yystate = yyn;
1212 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1213 *++yyvsp = yylval;
1214 YY_IGNORE_MAYBE_UNINITIALIZED_END
1216 /* Discard the shifted token. */
1217 yychar = YYEMPTY;
1218 goto yynewstate;
1221 /*-----------------------------------------------------------.
1222 | yydefault -- do the default action for the current state. |
1223 `-----------------------------------------------------------*/
1224 yydefault:
1225 yyn = yydefact[yystate];
1226 if (yyn == 0)
1227 goto yyerrlab;
1228 goto yyreduce;
1231 /*-----------------------------.
1232 | yyreduce -- do a reduction. |
1233 `-----------------------------*/
1234 yyreduce:
1235 /* yyn is the number of a rule to reduce with. */
1236 yylen = yyr2[yyn];
1238 /* If YYLEN is nonzero, implement the default value of the action:
1239 '$$ = $1'.
1241 Otherwise, the following line sets YYVAL to garbage.
1242 This behavior is undocumented and Bison
1243 users should not rely upon it. Assigning to YYVAL
1244 unconditionally makes the parser a bit smaller, and it avoids a
1245 GCC warning that YYVAL may be used uninitialized. */
1246 yyval = yyvsp[1-yylen];
1249 YY_REDUCE_PRINT (yyn);
1250 switch (yyn)
1252 case 6: /* grammar: grammar error */
1253 #line 97 "parse.y"
1254 { file->errors++; }
1255 #line 1256 "y.tab.c"
1256 break;
1258 case 7: /* include: INCLUDE STRING */
1259 #line 100 "parse.y"
1261 struct file *nfile;
1263 if ((nfile = pushfile((yyvsp[0].v.string), 0)) == NULL) {
1264 yyerror("failed to include file %s", (yyvsp[0].v.string));
1265 free((yyvsp[0].v.string));
1266 YYERROR;
1268 free((yyvsp[0].v.string));
1270 file = nfile;
1271 lungetc('\n');
1273 #line 1274 "y.tab.c"
1274 break;
1276 case 8: /* verbatim: '!' verbatim1 '!' */
1277 #line 115 "parse.y"
1279 if (in_define) {
1280 /* TODO: check template status and exit in case */
1283 #line 1284 "y.tab.c"
1284 break;
1286 case 10: /* verbatim1: verbatim1 STRING */
1287 #line 123 "parse.y"
1289 if (*(yyvsp[0].v.string) != '\0') {
1290 dbg();
1291 puts((yyvsp[0].v.string));
1293 free((yyvsp[0].v.string));
1295 #line 1296 "y.tab.c"
1296 break;
1298 case 13: /* raw: STRING */
1299 #line 136 "parse.y"
1301 dbg();
1302 printf("if (tp->tp_puts(tp, ");
1303 printq((yyvsp[0].v.string));
1304 printf(") == -1) goto %s;\n", lerr);
1306 free((yyvsp[0].v.string));
1308 #line 1309 "y.tab.c"
1309 break;
1311 case 14: /* block: define body end */
1312 #line 146 "parse.y"
1314 printf("%s:\n", lerr);
1315 puts("return tp->tp_ret;");
1316 puts("}");
1317 in_define = 0;
1319 #line 1320 "y.tab.c"
1320 break;
1322 case 15: /* block: define body finally end */
1323 #line 152 "parse.y"
1325 puts("return tp->tp_ret;");
1326 puts("}");
1327 in_define = 0;
1329 #line 1330 "y.tab.c"
1330 break;
1332 case 16: /* define: '{' DEFINE string '}' */
1333 #line 159 "parse.y"
1335 in_define = 1;
1336 (void)snprintf(lerr, sizeof(lerr), "err%llu",
1337 (unsigned long long)arc4random());
1339 dbg();
1340 printf("int\n%s\n{\n", (yyvsp[-1].v.string));
1342 free((yyvsp[-1].v.string));
1344 #line 1345 "y.tab.c"
1345 break;
1347 case 21: /* special: '{' RENDER string '}' */
1348 #line 177 "parse.y"
1350 dbg();
1351 if (strrchr((yyvsp[-1].v.string), ')') != NULL)
1352 printf("if (%s == -1) goto %s;\n",
1353 (yyvsp[-1].v.string), lerr);
1354 else
1355 printf("if (%s != NULL && %s(tp) == -1) "
1356 "goto %s;\n", (yyvsp[-1].v.string), (yyvsp[-1].v.string), lerr);
1357 free((yyvsp[-1].v.string));
1359 #line 1360 "y.tab.c"
1360 break;
1362 case 22: /* special: if body endif */
1363 #line 187 "parse.y"
1364 { puts("}"); }
1365 #line 1366 "y.tab.c"
1366 break;
1368 case 24: /* special: '{' string '}' */
1369 #line 189 "parse.y"
1371 dbg();
1372 printf("if (tp->tp_escape(tp, %s) == -1) goto %s;\n",
1373 (yyvsp[-1].v.string), lerr);
1375 #line 1376 "y.tab.c"
1376 break;
1378 case 25: /* if: '{' IF string '}' */
1379 #line 196 "parse.y"
1381 dbg();
1382 printf("if (%s) {\n", (yyvsp[-1].v.string));
1383 free((yyvsp[-1].v.string));
1385 #line 1386 "y.tab.c"
1386 break;
1388 case 29: /* elsif: '{' ELSE IF string '}' */
1389 #line 208 "parse.y"
1391 dbg();
1392 printf("} else if (%s) {\n", (yyvsp[-1].v.string));
1393 free((yyvsp[-1].v.string));
1395 #line 1396 "y.tab.c"
1396 break;
1398 case 30: /* else: '{' ELSE '}' */
1399 #line 215 "parse.y"
1401 dbg();
1402 puts("} else {");
1404 #line 1405 "y.tab.c"
1405 break;
1407 case 31: /* $@1: %empty */
1408 #line 221 "parse.y"
1410 printf("TAILQ_FOREACH(%s, %s, %s) {\n",
1411 (yyvsp[-3].v.string), (yyvsp[-2].v.string), (yyvsp[-1].v.string));
1412 free((yyvsp[-3].v.string));
1413 free((yyvsp[-2].v.string));
1414 free((yyvsp[-1].v.string));
1416 #line 1417 "y.tab.c"
1417 break;
1419 case 32: /* loop: '{' TQFOREACH STRING STRING STRING '}' $@1 body end */
1420 #line 227 "parse.y"
1422 puts("}");
1424 #line 1425 "y.tab.c"
1425 break;
1427 case 34: /* $@2: %empty */
1428 #line 235 "parse.y"
1430 dbg();
1431 printf("%s:\n", lerr);
1433 #line 1434 "y.tab.c"
1434 break;
1436 case 36: /* string: STRING string */
1437 #line 241 "parse.y"
1439 if (asprintf(&(yyval.v.string), "%s %s", (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1)
1440 err(1, "asprintf");
1441 free((yyvsp[-1].v.string));
1442 free((yyvsp[0].v.string));
1444 #line 1445 "y.tab.c"
1445 break;
1448 #line 1449 "y.tab.c"
1450 default: break;
1452 /* User semantic actions sometimes alter yychar, and that requires
1453 that yytoken be updated with the new translation. We take the
1454 approach of translating immediately before every use of yytoken.
1455 One alternative is translating here after every semantic action,
1456 but that translation would be missed if the semantic action invokes
1457 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1458 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1459 incorrect destructor might then be invoked immediately. In the
1460 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1461 to an incorrect destructor call or verbose syntax error message
1462 before the lookahead is translated. */
1463 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1465 YYPOPSTACK (yylen);
1466 yylen = 0;
1468 *++yyvsp = yyval;
1470 /* Now 'shift' the result of the reduction. Determine what state
1471 that goes to, based on the state we popped back to and the rule
1472 number reduced by. */
1474 const int yylhs = yyr1[yyn] - YYNTOKENS;
1475 const int yyi = yypgoto[yylhs] + *yyssp;
1476 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1477 ? yytable[yyi]
1478 : yydefgoto[yylhs]);
1481 goto yynewstate;
1484 /*--------------------------------------.
1485 | yyerrlab -- here on detecting error. |
1486 `--------------------------------------*/
1487 yyerrlab:
1488 /* Make sure we have latest lookahead translation. See comments at
1489 user semantic actions for why this is necessary. */
1490 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1491 /* If not already recovering from an error, report this error. */
1492 if (!yyerrstatus)
1494 ++yynerrs;
1495 yyerror (YY_("syntax error"));
1498 if (yyerrstatus == 3)
1500 /* If just tried and failed to reuse lookahead token after an
1501 error, discard it. */
1503 if (yychar <= YYEOF)
1505 /* Return failure if at end of input. */
1506 if (yychar == YYEOF)
1507 YYABORT;
1509 else
1511 yydestruct ("Error: discarding",
1512 yytoken, &yylval);
1513 yychar = YYEMPTY;
1517 /* Else will try to reuse lookahead token after shifting the error
1518 token. */
1519 goto yyerrlab1;
1522 /*---------------------------------------------------.
1523 | yyerrorlab -- error raised explicitly by YYERROR. |
1524 `---------------------------------------------------*/
1525 yyerrorlab:
1526 /* Pacify compilers when the user code never invokes YYERROR and the
1527 label yyerrorlab therefore never appears in user code. */
1528 if (0)
1529 YYERROR;
1531 /* Do not reclaim the symbols of the rule whose action triggered
1532 this YYERROR. */
1533 YYPOPSTACK (yylen);
1534 yylen = 0;
1535 YY_STACK_PRINT (yyss, yyssp);
1536 yystate = *yyssp;
1537 goto yyerrlab1;
1540 /*-------------------------------------------------------------.
1541 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1542 `-------------------------------------------------------------*/
1543 yyerrlab1:
1544 yyerrstatus = 3; /* Each real token shifted decrements this. */
1546 /* Pop stack until we find a state that shifts the error token. */
1547 for (;;)
1549 yyn = yypact[yystate];
1550 if (!yypact_value_is_default (yyn))
1552 yyn += YYSYMBOL_YYerror;
1553 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1555 yyn = yytable[yyn];
1556 if (0 < yyn)
1557 break;
1561 /* Pop the current state because it cannot handle the error token. */
1562 if (yyssp == yyss)
1563 YYABORT;
1566 yydestruct ("Error: popping",
1567 YY_ACCESSING_SYMBOL (yystate), yyvsp);
1568 YYPOPSTACK (1);
1569 yystate = *yyssp;
1570 YY_STACK_PRINT (yyss, yyssp);
1573 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1574 *++yyvsp = yylval;
1575 YY_IGNORE_MAYBE_UNINITIALIZED_END
1578 /* Shift the error token. */
1579 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1581 yystate = yyn;
1582 goto yynewstate;
1585 /*-------------------------------------.
1586 | yyacceptlab -- YYACCEPT comes here. |
1587 `-------------------------------------*/
1588 yyacceptlab:
1589 yyresult = 0;
1590 goto yyreturn;
1593 /*-----------------------------------.
1594 | yyabortlab -- YYABORT comes here. |
1595 `-----------------------------------*/
1596 yyabortlab:
1597 yyresult = 1;
1598 goto yyreturn;
1601 #if !defined yyoverflow
1602 /*-------------------------------------------------.
1603 | yyexhaustedlab -- memory exhaustion comes here. |
1604 `-------------------------------------------------*/
1605 yyexhaustedlab:
1606 yyerror (YY_("memory exhausted"));
1607 yyresult = 2;
1608 goto yyreturn;
1609 #endif
1612 /*-------------------------------------------------------.
1613 | yyreturn -- parsing is finished, clean up and return. |
1614 `-------------------------------------------------------*/
1615 yyreturn:
1616 if (yychar != YYEMPTY)
1618 /* Make sure we have latest lookahead translation. See comments at
1619 user semantic actions for why this is necessary. */
1620 yytoken = YYTRANSLATE (yychar);
1621 yydestruct ("Cleanup: discarding lookahead",
1622 yytoken, &yylval);
1624 /* Do not reclaim the symbols of the rule whose action triggered
1625 this YYABORT or YYACCEPT. */
1626 YYPOPSTACK (yylen);
1627 YY_STACK_PRINT (yyss, yyssp);
1628 while (yyssp != yyss)
1630 yydestruct ("Cleanup: popping",
1631 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
1632 YYPOPSTACK (1);
1634 #ifndef yyoverflow
1635 if (yyss != yyssa)
1636 YYSTACK_FREE (yyss);
1637 #endif
1639 return yyresult;
1642 #line 250 "parse.y"
1645 struct keywords {
1646 const char *k_name;
1647 int k_val;
1650 int
1651 yyerror(const char *fmt, ...)
1653 va_list ap;
1654 char *msg;
1656 file->errors++;
1657 va_start(ap, fmt);
1658 if (vasprintf(&msg, fmt, ap) == -1)
1659 err(1, "yyerror vasprintf");
1660 va_end(ap);
1661 fprintf(stderr, "%s:%d: %s\n", file->name, yylval.lineno, msg);
1662 free(msg);
1663 return (0);
1666 int
1667 kw_cmp(const void *k, const void *e)
1669 return (strcmp(k, ((const struct keywords *)e)->k_name));
1672 int
1673 lookup(char *s)
1675 /* this has to be sorted always */
1676 static const struct keywords keywords[] = {
1677 { "define", DEFINE },
1678 { "else", ELSE },
1679 { "end", END },
1680 { "finally", FINALLY },
1681 { "if", IF },
1682 { "include", INCLUDE },
1683 { "render", RENDER },
1684 { "tailq-foreach", TQFOREACH },
1686 const struct keywords *p;
1688 p = bsearch(s, keywords, nitems(keywords), sizeof(keywords[0]),
1689 kw_cmp);
1691 if (p)
1692 return (p->k_val);
1693 else
1694 return (STRING);
1697 #define START_EXPAND 1
1698 #define DONE_EXPAND 2
1700 static int expanding;
1702 int
1703 igetc(void)
1705 int c;
1707 while (1) {
1708 if (file->ungetpos > 0)
1709 c = file->ungetbuf[--file->ungetpos];
1710 else
1711 c = getc(file->stream);
1713 if (c == START_EXPAND)
1714 expanding = 1;
1715 else if (c == DONE_EXPAND)
1716 expanding = 0;
1717 else
1718 break;
1720 return (c);
1723 int
1724 lgetc(int quotec)
1726 int c, next;
1728 if (quotec) {
1729 if ((c = igetc()) == EOF) {
1730 yyerror("reached end of filewhile parsing "
1731 "quoted string");
1732 if (file == topfile || popfile() == EOF)
1733 return (EOF);
1734 return (quotec);
1736 return (c);
1739 while ((c = igetc()) == '\\') {
1740 next = igetc();
1741 if (next != '\n') {
1742 c = next;
1743 break;
1745 yylval.lineno = file->lineno;
1746 file->lineno++;
1748 if (c == '\t' || c == ' ') {
1749 /* Compress blanks to a sigle space. */
1750 do {
1751 c = getc(file->stream);
1752 } while (c == '\t' || c == ' ');
1753 ungetc(c, file->stream);
1754 c = ' ';
1757 if (c == EOF) {
1759 * Fake EOL when hit EOF for the first time. This gets line
1760 * count rigchtif last line included file is syntactically
1761 * invalid and has no newline.
1763 if (file->eof_reached == 0) {
1764 file->eof_reached = 1;
1765 return ('\n');
1767 while (c == EOF) {
1768 if (file == topfile || popfile() == EOF)
1769 return (EOF);
1770 c = igetc();
1773 return (c);
1776 void
1777 lungetc(int c)
1779 if (c == EOF)
1780 return;
1782 if (file->ungetpos >= file->ungetsize) {
1783 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
1784 if (p == NULL)
1785 err(1, "reallocarray");
1786 file->ungetbuf = p;
1787 file->ungetsize *= 2;
1789 file->ungetbuf[file->ungetpos++] = c;
1792 int
1793 findeol(void)
1795 int c;
1797 /* skip to either EOF or the first real EOL */
1798 while (1) {
1799 c = lgetc(0);
1800 if (c == '\n') {
1801 file->lineno++;
1802 break;
1804 if (c == EOF)
1805 break;
1807 return (ERROR);
1810 int
1811 yylex(void)
1813 char buf[8096];
1814 char *p = buf;
1815 int c;
1816 int token;
1817 int starting = 0;
1818 int ending = 0;
1820 if (!in_define && block == 0) {
1821 while ((c = lgetc(0)) != '{' && c != EOF) {
1822 if (c == '\n')
1823 file->lineno++;
1826 if (c == EOF)
1827 return (0);
1829 newblock:
1830 c = lgetc(0);
1831 if (c == '{' || c == '!') {
1832 if (c == '{')
1833 block = '}';
1834 else
1835 block = c;
1836 return (c);
1838 if (c == '\n')
1839 file->lineno++;
1842 while ((c = lgetc(0)) == ' ' || c == '\t' || c == '\n') {
1843 if (c == '\n')
1844 file->lineno++;
1847 if (c == EOF) {
1848 yyerror("unterminated block");
1849 return (0);
1852 yylval.lineno = file->lineno;
1854 if (block != 0 && c == block) {
1855 if ((c = lgetc(0)) == '}') {
1856 if (block == '!') {
1857 block = 0;
1858 return ('!');
1860 block = 0;
1861 return ('}');
1863 lungetc(c);
1864 c = block;
1867 if (in_define && block == 0) {
1868 if (c == '{')
1869 goto newblock;
1871 do {
1872 if (starting) {
1873 if (c == '!' || c == '{') {
1874 lungetc('{');
1875 lungetc(c);
1876 break;
1878 starting = 0;
1879 lungetc(c);
1880 c = '{';
1881 } else if (c == '{') {
1882 starting = 1;
1883 continue;
1886 *p++ = c;
1887 if ((size_t)(p - buf) >= sizeof(buf)) {
1888 yyerror("string too long");
1889 return (findeol());
1891 } while ((c = lgetc(0)) != EOF && c != '\n');
1892 *p = '\0';
1893 if (c == EOF) {
1894 yyerror("unterminated block");
1895 return (0);
1897 if (c == '\n')
1898 file->lineno++;
1899 if ((yylval.v.string = strdup(buf)) == NULL)
1900 err(1, "strdup");
1901 return (STRING);
1904 if (block == '!') {
1905 do {
1906 if (ending) {
1907 if (c == '}') {
1908 lungetc(c);
1909 lungetc(block);
1910 break;
1912 ending = 0;
1913 lungetc(c);
1914 c = block;
1915 } else if (c == '!') {
1916 ending = 1;
1917 continue;
1920 *p++ = c;
1921 if ((size_t)(p - buf) >= sizeof(buf)) {
1922 yyerror("line too long");
1923 return (findeol());
1925 } while ((c = lgetc(0)) != EOF && c != '\n');
1926 *p = '\0';
1928 if (c == EOF) {
1929 yyerror("unterminated block");
1930 return (0);
1932 if (c == '\n')
1933 file->lineno++;
1935 if ((yylval.v.string = strdup(buf)) == NULL)
1936 err(1, "strdup");
1937 return (STRING);
1940 do {
1941 if (ending) {
1942 if (c == '}') {
1943 lungetc(c);
1944 lungetc('}');
1945 break;
1947 ending = 0;
1948 lungetc(c);
1949 c = block;
1950 } else if (c == '}') {
1951 ending = 1;
1952 continue;
1955 *p++ = c;
1956 if ((size_t)(p - buf) >= sizeof(buf)) {
1957 yyerror("string too long");
1958 return (findeol());
1960 } while ((c = lgetc(0)) != EOF && !isspace((unsigned char)c));
1961 *p = '\0';
1963 if (c == EOF) {
1964 yyerror("unterminated block");
1965 return (0);
1967 if (c == '\n')
1968 file->lineno++;
1969 if ((token = lookup(buf)) == STRING)
1970 if ((yylval.v.string = strdup(buf)) == NULL)
1971 err(1, "strdup");
1972 return (token);
1975 struct file *
1976 pushfile(const char *name, int secret)
1978 struct file *nfile;
1980 if ((nfile = calloc(1, sizeof(*nfile))) == NULL)
1981 err(1, "calloc");
1982 if ((nfile->name = strdup(name)) == NULL)
1983 err(1, "strdup");
1984 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
1985 warn("can't open %s", nfile->name);
1986 free(nfile->name);
1987 free(nfile);
1988 return (NULL);
1990 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
1991 nfile->ungetsize = 16;
1992 nfile->ungetbuf = malloc(nfile->ungetsize);
1993 if (nfile->ungetbuf == NULL)
1994 err(1, "malloc");
1995 TAILQ_INSERT_TAIL(&files, nfile, entry);
1996 return (nfile);
1999 int
2000 popfile(void)
2002 struct file *prev;
2004 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
2005 prev->errors += file->errors;
2007 TAILQ_REMOVE(&files, file, entry);
2008 fclose(file->stream);
2009 free(file->name);
2010 free(file->ungetbuf);
2011 free(file);
2012 file = prev;
2013 return (file ? 0 : EOF);
2016 int
2017 parse(const char *filename)
2019 if ((file = pushfile(filename, 0)) == 0)
2020 return (-1);
2021 topfile = file;
2023 yyparse();
2024 errors = file->errors;
2025 popfile();
2027 return (errors ? -1 : 0);
2030 void
2031 dbg(void)
2033 if (nodebug)
2034 return;
2036 printf("#line %d ", yylval.lineno);
2037 printq(file->name);
2038 putchar('\n');
2041 void
2042 printq(const char *str)
2044 putchar('"');
2045 for (; *str; ++str) {
2046 if (*str == '"')
2047 putchar('\\');
2048 putchar(*str);
2050 putchar('"');