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,
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. */
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.6"
55 #define YYSKELETON_NAME "yacc.c"
69 /* First part of user prologue. */
73 #include <sys/queue.h>
85 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
88 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
90 TAILQ_ENTRY(file) entry;
100 int parse(const char *);
101 struct file *pushfile(const char *, int);
105 int yyerror(const char *, ...)
106 __attribute__((__format__ (printf, 1, 2)))
107 __attribute__((__nonnull__ (1)));
108 int kw_cmp(const void *, const void *);
116 void printq(const char *);
121 static int in_define;
123 static char lerr[32];
137 # define YY_CAST(Type, Val) static_cast<Type> (Val)
138 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
140 # define YY_CAST(Type, Val) ((Type) (Val))
141 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
145 # if defined __cplusplus
146 # if 201103L <= __cplusplus
147 # define YY_NULLPTR nullptr
149 # define YY_NULLPTR 0
152 # define YY_NULLPTR ((void*)0)
171 YYEOF = 0, /* "end of file" */
172 YYerror = 256, /* error */
173 YYUNDEF = 257, /* "invalid token" */
174 DEFINE = 258, /* DEFINE */
175 ELSE = 259, /* ELSE */
177 ERROR = 261, /* ERROR */
178 FINALLY = 262, /* FINALLY */
180 INCLUDE = 264, /* INCLUDE */
181 RENDER = 265, /* RENDER */
182 TQFOREACH = 266, /* TQFOREACH */
183 STRING = 267 /* STRING */
185 typedef enum yytokentype yytoken_kind_t;
200 #define TQFOREACH 266
206 extern YYSTYPE yylval;
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 */
253 typedef enum yysymbol_kind_t yysymbol_kind_t;
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 */
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;
284 typedef signed char yytype_int8;
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;
292 typedef short yytype_int16;
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>. */
301 # undef UINT_LEAST8_MAX
302 # undef UINT_LEAST16_MAX
303 # define UINT_LEAST8_MAX 255
304 # define UINT_LEAST16_MAX 65535
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;
315 typedef short yytype_uint8;
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;
326 typedef int yytype_uint16;
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
335 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
337 # define YYPTRDIFF_T ptrdiff_t
338 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
340 # define YYPTRDIFF_T long
341 # define YYPTRDIFF_MAXIMUM LONG_MAX
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
354 # define YYSIZE_T unsigned
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;
374 # if defined YYENABLE_NLS && YYENABLE_NLS
376 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
377 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
381 # define YY_(Msgid) Msgid
386 #ifndef YY_ATTRIBUTE_PURE
387 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
388 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
390 # define YY_ATTRIBUTE_PURE
394 #ifndef YY_ATTRIBUTE_UNUSED
395 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
396 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
398 # define YY_ATTRIBUTE_UNUSED
402 /* Suppress unused-variable warnings by "using" E. */
403 #if ! defined lint || defined __GNUC__
404 # define YY_USE(E) ((void) (E))
406 # define YY_USE(E) /* empty */
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")
418 # define YY_INITIAL_VALUE(Value) Value
420 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
421 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
422 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
424 #ifndef YY_INITIAL_VALUE
425 # define YY_INITIAL_VALUE(Value) /* Nothing. */
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")
435 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
436 # define YY_IGNORE_USELESS_CAST_BEGIN
437 # define YY_IGNORE_USELESS_CAST_END
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
450 # define YYSTACK_ALLOC __builtin_alloca
451 # elif defined __BUILTIN_VA_ARG_INCR
452 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
454 # define YYSTACK_ALLOC __alloca
455 # elif defined _MSC_VER
456 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
457 # define alloca _alloca
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
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 */
482 # define YYSTACK_ALLOC YYMALLOC
483 # define YYSTACK_FREE YYFREE
484 # ifndef YYSTACK_ALLOC_MAXIMUM
485 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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
496 # define YYMALLOC malloc
497 # if ! defined malloc && ! defined EXIT_SUCCESS
498 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
503 # if ! defined free && ! defined EXIT_SUCCESS
504 void free (void *); /* INFRINGES ON USER NAME SPACE */
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. */
517 yy_state_t yyss_alloc;
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
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
537 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
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); \
550 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
551 /* Copy COUNT objects from SRC to DST. The source and destination do
554 # if defined __GNUC__ && 1 < __GNUC__
555 # define YYCOPY(Dst, Src, Count) \
556 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
558 # define YYCOPY(Dst, Src, Count) \
562 for (yyi = 0; yyi < (Count); yyi++) \
563 (Dst)[yyi] = (Src)[yyi]; \
568 #endif /* !YYCOPY_NEEDED */
570 /* YYFINAL -- State number of the termination state. */
572 /* YYLAST -- Last index in YYTABLE. */
575 /* YYNTOKENS -- Number of terminals. */
577 /* YYNNTS -- Number of nonterminals. */
579 /* YYNRULES -- Number of rules. */
581 /* YYNSTATES -- Number of states. */
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]) \
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
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
639 /** Accessing symbol of state STATE. */
640 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
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
660 yysymbol_name (yysymbol_kind_t yysymbol)
662 return yytname[yysymbol];
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
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
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,
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,
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,
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,
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
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
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,
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
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
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) \
803 if (yychar == YYEMPTY) \
807 YYPOPSTACK (yylen); \
813 yyerror (YY_("syntax error: cannot back up")); \
818 /* Backward compatibility with an undocumented macro.
819 Use YYerror or YYUNDEF. */
820 #define YYERRCODE YYUNDEF
823 /* Enable debugging if requested. */
827 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
828 # define YYFPRINTF fprintf
831 # define YYDPRINTF(Args) \
837 /* This macro is provided for backward compatibility. */
838 # ifndef YY_LOCATION_PRINT
839 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
843 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
847 YYFPRINTF (stderr, "%s ", Title); \
848 yy_symbol_print (stderr, \
850 YYFPRINTF (stderr, "\n"); \
855 /*-----------------------------------.
856 | Print this symbol's value on YYO. |
857 `-----------------------------------*/
860 yy_symbol_value_print (FILE *yyo,
861 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
863 FILE *yyoutput = yyo;
868 if (yykind < YYNTOKENS)
869 YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
871 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
873 YY_IGNORE_MAYBE_UNINITIALIZED_END
877 /*---------------------------.
878 | Print this symbol on YYO. |
879 `---------------------------*/
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 |
895 `------------------------------------------------------------------*/
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) \
912 yy_stack_print ((Bottom), (Top)); \
916 /*------------------------------------------------.
917 | Report that the YYRULE is going to be reduced. |
918 `------------------------------------------------*/
921 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
924 int yylno = yyrline[yyrule];
925 int yynrhs = yyr2[yyrule];
927 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
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) \
943 yy_reduce_print (yyssp, yyvsp, Rule); \
946 /* Nonzero means print parse trace. It is left uninitialized so that
947 multiple parsers can coexist. */
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. */
959 # define YYINITDEPTH 200
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. */
970 # define YYMAXDEPTH 10000
978 /*-----------------------------------------------.
979 | Release the memory associated to this symbol. |
980 `-----------------------------------------------*/
983 yydestruct (const char *yymsg,
984 yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
989 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
991 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
993 YY_IGNORE_MAYBE_UNINITIALIZED_END
997 /* Lookahead token kind. */
1000 /* The semantic value of the lookahead symbol. */
1002 /* Number of syntax errors so far. */
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. */
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;
1036 /* The return value of yyparse. */
1038 /* Lookahead symbol kind. */
1039 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1040 /* The variables used to return semantic value and location from the
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. */
1052 YYDPRINTF ((stderr, "Starting parse\n"));
1054 yychar = YYEMPTY; /* Cause a token to be read. */
1058 /*------------------------------------------------------------.
1059 | yynewstate -- push a new state, which is found in yystate. |
1060 `------------------------------------------------------------*/
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. */
1067 /*--------------------------------------------------------------------.
1068 | yysetstate -- set current state (the top of the stack) to yystate. |
1069 `--------------------------------------------------------------------*/
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;
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
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),
1105 # else /* defined YYSTACK_RELOCATE */
1106 /* Extend the stack our own way. */
1107 if (YYMAXDEPTH <= yystacksize)
1108 goto yyexhaustedlab;
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))));
1119 goto yyexhaustedlab;
1120 YYSTACK_RELOCATE (yyss_alloc, yyss);
1121 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1122 # undef YYSTACK_RELOCATE
1124 YYSTACK_FREE (yyss1);
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)
1139 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1141 if (yystate == YYFINAL)
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))
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"));
1168 if (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. */
1181 yytoken = YYSYMBOL_YYerror;
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. */
1193 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1198 if (yytable_value_is_error (yyn))
1204 /* Count tokens shifted since error; after three, turn off error
1209 /* Shift the lookahead token. */
1210 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1212 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1214 YY_IGNORE_MAYBE_UNINITIALIZED_END
1216 /* Discard the shifted token. */
1221 /*-----------------------------------------------------------.
1222 | yydefault -- do the default action for the current state. |
1223 `-----------------------------------------------------------*/
1225 yyn = yydefact[yystate];
1231 /*-----------------------------.
1232 | yyreduce -- do a reduction. |
1233 `-----------------------------*/
1235 /* yyn is the number of a rule to reduce with. */
1238 /* If YYLEN is nonzero, implement the default value of the action:
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);
1252 case 6: /* grammar: grammar error */
1255 #line 1256 "y.tab.c"
1258 case 7: /* include: INCLUDE STRING */
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));
1268 free((yyvsp[0].v.string));
1273 #line 1274 "y.tab.c"
1276 case 8: /* verbatim: '!' verbatim1 '!' */
1280 /* TODO: check template status and exit in case */
1283 #line 1284 "y.tab.c"
1286 case 10: /* verbatim1: verbatim1 STRING */
1289 if (*(yyvsp[0].v.string) != '\0') {
1291 puts((yyvsp[0].v.string));
1293 free((yyvsp[0].v.string));
1295 #line 1296 "y.tab.c"
1298 case 13: /* raw: STRING */
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"
1311 case 14: /* block: define body end */
1314 printf("%s:\n", lerr);
1315 puts("return tp->tp_ret;");
1319 #line 1320 "y.tab.c"
1322 case 15: /* block: define body finally end */
1325 puts("return tp->tp_ret;");
1329 #line 1330 "y.tab.c"
1332 case 16: /* define: '{' DEFINE string '}' */
1336 (void)snprintf(lerr, sizeof(lerr), "err%llu",
1337 (unsigned long long)arc4random());
1340 printf("int\n%s\n{\n", (yyvsp[-1].v.string));
1342 free((yyvsp[-1].v.string));
1344 #line 1345 "y.tab.c"
1347 case 21: /* special: '{' RENDER string '}' */
1351 if (strrchr((yyvsp[-1].v.string), ')') != NULL)
1352 printf("if (%s == -1) goto %s;\n",
1353 (yyvsp[-1].v.string), lerr);
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"
1362 case 22: /* special: if body endif */
1365 #line 1366 "y.tab.c"
1368 case 24: /* special: '{' string '}' */
1372 printf("if (tp->tp_escape(tp, %s) == -1) goto %s;\n",
1373 (yyvsp[-1].v.string), lerr);
1375 #line 1376 "y.tab.c"
1378 case 25: /* if: '{' IF string '}' */
1382 printf("if (%s) {\n", (yyvsp[-1].v.string));
1383 free((yyvsp[-1].v.string));
1385 #line 1386 "y.tab.c"
1388 case 29: /* elsif: '{' ELSE IF string '}' */
1392 printf("} else if (%s) {\n", (yyvsp[-1].v.string));
1393 free((yyvsp[-1].v.string));
1395 #line 1396 "y.tab.c"
1398 case 30: /* else: '{' ELSE '}' */
1404 #line 1405 "y.tab.c"
1407 case 31: /* $@1: %empty */
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"
1419 case 32: /* loop: '{' TQFOREACH STRING STRING STRING '}' $@1 body end */
1424 #line 1425 "y.tab.c"
1427 case 34: /* $@2: %empty */
1431 printf("%s:\n", lerr);
1433 #line 1434 "y.tab.c"
1436 case 36: /* string: STRING string */
1439 if (asprintf(&(yyval.v.string), "%s %s", (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1)
1441 free((yyvsp[-1].v.string));
1442 free((yyvsp[0].v.string));
1444 #line 1445 "y.tab.c"
1448 #line 1449 "y.tab.c"
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);
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
1478 : yydefgoto[yylhs]);
1484 /*--------------------------------------.
1485 | yyerrlab -- here on detecting error. |
1486 `--------------------------------------*/
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. */
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)
1511 yydestruct ("Error: discarding",
1517 /* Else will try to reuse lookahead token after shifting the error
1522 /*---------------------------------------------------.
1523 | yyerrorlab -- error raised explicitly by YYERROR. |
1524 `---------------------------------------------------*/
1526 /* Pacify compilers when the user code never invokes YYERROR and the
1527 label yyerrorlab therefore never appears in user code. */
1531 /* Do not reclaim the symbols of the rule whose action triggered
1535 YY_STACK_PRINT (yyss, yyssp);
1540 /*-------------------------------------------------------------.
1541 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1542 `-------------------------------------------------------------*/
1544 yyerrstatus = 3; /* Each real token shifted decrements this. */
1546 /* Pop stack until we find a state that shifts the error token. */
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)
1561 /* Pop the current state because it cannot handle the error token. */
1566 yydestruct ("Error: popping",
1567 YY_ACCESSING_SYMBOL (yystate), yyvsp);
1570 YY_STACK_PRINT (yyss, yyssp);
1573 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1575 YY_IGNORE_MAYBE_UNINITIALIZED_END
1578 /* Shift the error token. */
1579 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1585 /*-------------------------------------.
1586 | yyacceptlab -- YYACCEPT comes here. |
1587 `-------------------------------------*/
1593 /*-----------------------------------.
1594 | yyabortlab -- YYABORT comes here. |
1595 `-----------------------------------*/
1601 #if !defined yyoverflow
1602 /*-------------------------------------------------.
1603 | yyexhaustedlab -- memory exhaustion comes here. |
1604 `-------------------------------------------------*/
1606 yyerror (YY_("memory exhausted"));
1612 /*-------------------------------------------------------.
1613 | yyreturn -- parsing is finished, clean up and return. |
1614 `-------------------------------------------------------*/
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",
1624 /* Do not reclaim the symbols of the rule whose action triggered
1625 this YYABORT or YYACCEPT. */
1627 YY_STACK_PRINT (yyss, yyssp);
1628 while (yyssp != yyss)
1630 yydestruct ("Cleanup: popping",
1631 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
1636 YYSTACK_FREE (yyss);
1651 yyerror(const char *fmt, ...)
1658 if (vasprintf(&msg, fmt, ap) == -1)
1659 err(1, "yyerror vasprintf");
1661 fprintf(stderr, "%s:%d: %s\n", file->name, yylval.lineno, msg);
1667 kw_cmp(const void *k, const void *e)
1669 return (strcmp(k, ((const struct keywords *)e)->k_name));
1675 /* this has to be sorted always */
1676 static const struct keywords keywords[] = {
1677 { "define", DEFINE },
1680 { "finally", FINALLY },
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]),
1697 #define START_EXPAND 1
1698 #define DONE_EXPAND 2
1700 static int expanding;
1708 if (file->ungetpos > 0)
1709 c = file->ungetbuf[--file->ungetpos];
1711 c = getc(file->stream);
1713 if (c == START_EXPAND)
1715 else if (c == DONE_EXPAND)
1729 if ((c = igetc()) == EOF) {
1730 yyerror("reached end of filewhile parsing "
1732 if (file == topfile || popfile() == EOF)
1739 while ((c = igetc()) == '\\') {
1745 yylval.lineno = file->lineno;
1748 if (c == '\t' || c == ' ') {
1749 /* Compress blanks to a sigle space. */
1751 c = getc(file->stream);
1752 } while (c == '\t' || c == ' ');
1753 ungetc(c, file->stream);
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;
1768 if (file == topfile || popfile() == EOF)
1782 if (file->ungetpos >= file->ungetsize) {
1783 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
1785 err(1, "reallocarray");
1787 file->ungetsize *= 2;
1789 file->ungetbuf[file->ungetpos++] = c;
1797 /* skip to either EOF or the first real EOL */
1820 if (!in_define && block == 0) {
1821 while ((c = lgetc(0)) != '{' && c != EOF) {
1831 if (c == '{' || c == '!') {
1842 while ((c = lgetc(0)) == ' ' || c == '\t' || c == '\n') {
1848 yyerror("unterminated block");
1852 yylval.lineno = file->lineno;
1854 if (block != 0 && c == block) {
1855 if ((c = lgetc(0)) == '}') {
1867 if (in_define && block == 0) {
1873 if (c == '!' || c == '{') {
1881 } else if (c == '{') {
1887 if ((size_t)(p - buf) >= sizeof(buf)) {
1888 yyerror("string too long");
1891 } while ((c = lgetc(0)) != EOF && c != '\n');
1894 yyerror("unterminated block");
1899 if ((yylval.v.string = strdup(buf)) == NULL)
1915 } else if (c == '!') {
1921 if ((size_t)(p - buf) >= sizeof(buf)) {
1922 yyerror("line too long");
1925 } while ((c = lgetc(0)) != EOF && c != '\n');
1929 yyerror("unterminated block");
1935 if ((yylval.v.string = strdup(buf)) == NULL)
1950 } else if (c == '}') {
1956 if ((size_t)(p - buf) >= sizeof(buf)) {
1957 yyerror("string too long");
1960 } while ((c = lgetc(0)) != EOF && !isspace((unsigned char)c));
1964 yyerror("unterminated block");
1969 if ((token = lookup(buf)) == STRING)
1970 if ((yylval.v.string = strdup(buf)) == NULL)
1976 pushfile(const char *name, int secret)
1980 if ((nfile = calloc(1, sizeof(*nfile))) == NULL)
1982 if ((nfile->name = strdup(name)) == NULL)
1984 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
1985 warn("can't open %s", nfile->name);
1990 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
1991 nfile->ungetsize = 16;
1992 nfile->ungetbuf = malloc(nfile->ungetsize);
1993 if (nfile->ungetbuf == NULL)
1995 TAILQ_INSERT_TAIL(&files, nfile, entry);
2004 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
2005 prev->errors += file->errors;
2007 TAILQ_REMOVE(&files, file, entry);
2008 fclose(file->stream);
2010 free(file->ungetbuf);
2013 return (file ? 0 : EOF);
2017 parse(const char *filename)
2019 if ((file = pushfile(filename, 0)) == 0)
2024 errors = file->errors;
2027 return (errors ? -1 : 0);
2036 printf("#line %d ", yylval.lineno);
2042 printq(const char *str)
2045 for (; *str; ++str) {