From 29e68de71731fd78d4d82fd1d00a9844f61ebf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Mon, 14 Sep 2026 13:21:30 +0200 Subject: [PATCH] M #-: Improve error msg from template parser (#4500) * Fix line and column number in the error message --- src/parsers/template_parser.cc | 263 ++++---- src/parsers/template_parser.h | 8 +- src/parsers/template_parser.l | 38 +- src/parsers/template_syntax.cc | 1055 +++++++++++++++++--------------- src/parsers/template_syntax.h | 48 +- src/parsers/template_syntax.y | 30 +- 6 files changed, 760 insertions(+), 682 deletions(-) diff --git a/src/parsers/template_parser.cc b/src/parsers/template_parser.cc index 86a27e0f56..28f7503916 100644 --- a/src/parsers/template_parser.cc +++ b/src/parsers/template_parser.cc @@ -1,6 +1,6 @@ -#line 1 "template_parser.cc" +#line 2 "template_parser.cc" -#line 3 "template_parser.cc" +#line 4 "template_parser.cc" #define YY_INT_ALIGNED short int @@ -398,27 +398,8 @@ typedef size_t yy_size_t; #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE yylex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -586,15 +567,14 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static const flex_int16_t yy_accept[69] = +static const flex_int16_t yy_accept[61] = { 0, 0, 0, 0, 0, 13, 12, 2, 2, 12, 6, - 3, 4, 7, 11, 12, 11, 12, 8, 12, 2, - 2, 0, 6, 4, 7, 0, 1, 6, 3, 4, - 5, 7, 11, 0, 0, 0, 8, 11, 0, 0, - 10, 11, 0, 8, 8, 0, 10, 0, 10, 0, - 10, 0, 9, 10, 10, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 0 + 3, 4, 7, 11, 12, 11, 8, 12, 2, 2, + 0, 0, 1, 3, 4, 5, 11, 0, 0, 11, + 0, 0, 10, 11, 0, 8, 8, 0, 10, 0, + 10, 0, 10, 0, 9, 10, 10, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 0 } ; static const YY_CHAR yy_ec[256] = @@ -635,89 +615,72 @@ static const YY_CHAR yy_meta[13] = 1, 1 } ; -static const flex_int16_t yy_base[77] = +static const flex_int16_t yy_base[67] = { 0, - 0, 0, 12, 0, 70, 196, 23, 34, 65, 0, - 60, 45, 0, 48, 59, 71, 54, 82, 53, 0, - 0, 61, 0, 0, 0, 60, 196, 0, 55, 0, - 196, 0, 0, 39, 33, 93, 0, 0, 105, 113, - 0, 40, 31, 0, 0, 116, 30, 37, 196, 125, - 0, 128, 27, 0, 137, 146, 26, 22, 156, 21, - 28, 18, 160, 0, 164, 15, 0, 196, 176, 178, - 180, 183, 185, 187, 190, 192 + 0, 0, 12, 0, 83, 156, 23, 0, 79, 156, + 74, 27, 156, 30, 42, 53, 64, 68, 0, 0, + 74, 72, 156, 66, 0, 156, 0, 0, 60, 0, + 67, 75, 0, 66, 57, 85, 0, 80, 0, 48, + 156, 89, 0, 92, 38, 0, 101, 110, 36, 35, + 120, 33, 40, 21, 124, 0, 128, 15, 0, 156, + 139, 142, 145, 147, 150, 152 } ; -static const flex_int16_t yy_def[77] = +static const flex_int16_t yy_def[67] = { 0, - 68, 1, 68, 3, 68, 68, 68, 68, 69, 70, - 68, 68, 71, 68, 72, 68, 72, 72, 72, 7, - 8, 69, 70, 12, 71, 69, 68, 70, 68, 12, - 68, 71, 14, 72, 72, 72, 18, 16, 16, 73, - 14, 16, 39, 18, 74, 72, 72, 39, 68, 73, - 16, 39, 75, 39, 73, 76, 75, 75, 76, 75, - 59, 59, 75, 59, 59, 75, 59, 0, 68, 68, - 68, 68, 68, 68, 68, 68 + 60, 1, 60, 3, 60, 60, 60, 61, 62, 60, + 60, 60, 60, 60, 14, 60, 15, 15, 7, 61, + 62, 62, 60, 60, 12, 60, 14, 15, 15, 16, + 16, 63, 14, 16, 31, 15, 64, 15, 15, 31, + 60, 63, 16, 31, 65, 31, 63, 66, 65, 65, + 66, 65, 51, 51, 65, 51, 51, 65, 51, 0, + 60, 60, 60, 60, 60, 60 } ; -static const flex_int16_t yy_nxt[209] = +static const flex_int16_t yy_nxt[169] = { 0, 6, 7, 8, 6, 9, 10, 11, 12, 6, 6, - 6, 13, 14, 15, 6, 16, 17, 17, 14, 17, - 14, 18, 14, 19, 20, 21, 58, 22, 23, 65, - 24, 64, 58, 63, 25, 21, 21, 58, 58, 23, - 54, 35, 52, 51, 46, 25, 30, 31, 33, 34, - 35, 33, 34, 34, 33, 34, 33, 34, 33, 35, - 36, 29, 27, 27, 46, 35, 29, 27, 37, 68, - 35, 38, 39, 40, 41, 39, 39, 38, 39, 38, - 39, 42, 43, 44, 45, 68, 68, 68, 68, 68, - 68, 68, 68, 35, 36, 68, 68, 68, 68, 68, + 6, 13, 14, 15, 6, 16, 15, 15, 14, 15, + 14, 17, 14, 18, 19, 20, 50, 21, 25, 26, + 27, 28, 57, 27, 28, 28, 27, 28, 27, 28, + 27, 29, 28, 56, 50, 28, 55, 50, 28, 50, + 28, 46, 28, 30, 31, 32, 33, 31, 31, 30, + 31, 30, 31, 34, 35, 36, 37, 31, 44, 43, + 39, 38, 24, 31, 23, 31, 23, 40, 41, 38, + 24, 23, 60, 60, 60, 42, 36, 37, 45, 60, + 60, 38, 47, 60, 60, 60, 60, 60, 60, 42, - 68, 68, 37, 68, 35, 39, 68, 68, 47, 68, - 68, 39, 68, 39, 68, 48, 49, 68, 68, 68, - 68, 68, 68, 50, 53, 68, 68, 46, 55, 68, - 68, 68, 68, 68, 68, 50, 56, 68, 68, 52, - 49, 68, 68, 68, 68, 68, 68, 50, 40, 60, - 68, 68, 68, 68, 68, 68, 61, 62, 40, 60, - 68, 68, 68, 68, 68, 68, 61, 62, 66, 68, - 68, 63, 67, 68, 68, 65, 26, 26, 26, 28, - 28, 32, 32, 34, 34, 40, 40, 40, 45, 45, - 57, 57, 59, 59, 59, 5, 68, 68, 68, 68, - - 68, 68, 68, 68, 68, 68, 68, 68 + 48, 60, 60, 44, 41, 60, 60, 60, 60, 60, + 60, 42, 32, 52, 60, 60, 60, 60, 60, 60, + 53, 54, 32, 52, 60, 60, 60, 60, 60, 60, + 53, 54, 58, 60, 60, 55, 59, 60, 60, 57, + 20, 20, 22, 22, 22, 32, 32, 32, 37, 37, + 49, 49, 51, 51, 51, 5, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60 } ; -static const flex_int16_t yy_chk[209] = +static const flex_int16_t yy_chk[169] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 7, 7, 66, 7, 7, 62, - 7, 61, 60, 58, 7, 8, 8, 57, 53, 8, - 48, 47, 43, 42, 35, 8, 12, 12, 14, 14, - 34, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 15, 29, 26, 22, 19, 17, 11, 9, 15, 5, - 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 18, 18, 0, 0, 0, 0, 0, - 0, 0, 0, 18, 36, 0, 0, 0, 0, 0, + 3, 3, 3, 3, 7, 7, 58, 7, 12, 12, + 14, 14, 54, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 15, 53, 52, 15, 50, 49, 15, 45, + 15, 40, 15, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 17, 17, 31, 35, 34, + 31, 29, 24, 31, 22, 31, 21, 31, 32, 18, + 11, 9, 5, 0, 0, 32, 36, 36, 38, 0, + 0, 38, 42, 0, 0, 0, 0, 0, 0, 42, - 0, 0, 36, 0, 36, 39, 0, 0, 39, 0, - 0, 39, 0, 39, 0, 39, 40, 0, 0, 0, - 0, 0, 0, 40, 46, 0, 0, 46, 50, 0, - 0, 0, 0, 0, 0, 50, 52, 0, 0, 52, - 55, 0, 0, 0, 0, 0, 0, 55, 56, 56, - 0, 0, 0, 0, 0, 0, 56, 56, 59, 59, - 0, 0, 0, 0, 0, 0, 59, 59, 63, 0, - 0, 63, 65, 0, 0, 65, 69, 69, 69, 70, - 70, 71, 71, 72, 72, 73, 73, 73, 74, 74, - 75, 75, 76, 76, 76, 68, 68, 68, 68, 68, - - 68, 68, 68, 68, 68, 68, 68, 68 + 44, 0, 0, 44, 47, 0, 0, 0, 0, 0, + 0, 47, 48, 48, 0, 0, 0, 0, 0, 0, + 48, 48, 51, 51, 0, 0, 0, 0, 0, 0, + 51, 51, 55, 0, 0, 55, 57, 0, 0, 57, + 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, + 65, 65, 66, 66, 66, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60 } ; -/* Table of booleans, true if rule could match eol. */ -static const flex_int32_t yy_rule_can_match_eol[13] = - { 0, -1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, }; - /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -754,12 +717,27 @@ static const flex_int32_t yy_rule_can_match_eol[13] = #define YY_DECL int template_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ mem_collector *mc, yyscan_t yyscanner) -#define YY_USER_ACTION llocp->first_line = yylineno; \ - llocp->first_column = llocp->last_column; \ - llocp->last_column += yyleng; -#line 761 "template_parser.cc" +/* Track locations from Bison's initialized, one-based location. Flex's line + * counter is not initialized for string buffers. The end is exclusive. + */ +#define YY_USER_ACTION \ + llocp->first_line = llocp->last_line; \ + llocp->first_column = llocp->last_column; \ + for (int i = 0; i < yyleng; ++i) \ + { \ + if (yytext[i] == '\n') \ + { \ + ++llocp->last_line; \ + llocp->last_column = 1; \ + } \ + else \ + { \ + ++llocp->last_column; \ + } \ + } +#line 739 "template_parser.cc" -#line 763 "template_parser.cc" +#line 741 "template_parser.cc" #define INITIAL 0 #define VALUE 1 @@ -1032,14 +1010,14 @@ YY_DECL } { -#line 49 "template_parser.l" +#line 62 "template_parser.l" -#line 52 "template_parser.l" +#line 65 "template_parser.l" /* ------------------------------------------------------------------------- */ /* Comments (lines with an starting #), and empty lines */ /* ------------------------------------------------------------------------- */ -#line 1043 "template_parser.cc" +#line 1021 "template_parser.cc" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1066,13 +1044,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 69 ) + if ( yy_current_state >= 61 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 196 ); + while ( yy_base[yy_current_state] != 156 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -1085,18 +1063,6 @@ yy_find_action: YY_DO_BEFORE_ACTION; - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - int yyl; - for ( yyl = 0; yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - } - do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) @@ -1111,21 +1077,21 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 55 "template_parser.l" +#line 68 "template_parser.l" ; YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 56 "template_parser.l" +#line 69 "template_parser.l" ; YY_BREAK /* ------------------------------------------------------------------------- */ -/* Variable: Alpha numeric charatcers and '_' */ +/* Variable: Alpha numeric characters and '_' */ /* ------------------------------------------------------------------------- */ case 3: YY_RULE_SETUP -#line 61 "template_parser.l" +#line 74 "template_parser.l" { yylval_param->val_str = mem_collector_strdup(mc,yytext); return VARIABLE; } YY_BREAK @@ -1136,31 +1102,29 @@ YY_RULE_SETUP /* ------------------------------------------------------------------------ */ case 4: YY_RULE_SETUP -#line 69 "template_parser.l" +#line 82 "template_parser.l" { BEGIN VALUE; return EQUAL;} YY_BREAK case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 71 "template_parser.l" +#line 84 "template_parser.l" { return EQUAL_EMPTY;} YY_BREAK case 6: -/* rule 6 can match eol */ YY_RULE_SETUP -#line 73 "template_parser.l" +#line 86 "template_parser.l" { return COMMA;} YY_BREAK case 7: -/* rule 7 can match eol */ YY_RULE_SETUP -#line 75 "template_parser.l" +#line 88 "template_parser.l" { return CBRACKET;} YY_BREAK case 8: /* rule 8 can match eol */ YY_RULE_SETUP -#line 77 "template_parser.l" +#line 90 "template_parser.l" { BEGIN(INITIAL); return OBRACKET;} YY_BREAK /* ------------------------------------------------------------------------ */ @@ -1170,7 +1134,7 @@ YY_RULE_SETUP /* ------------------------------------------------------------------------ */ case 9: YY_RULE_SETUP -#line 85 "template_parser.l" +#line 98 "template_parser.l" { BEGIN(INITIAL); return CCDATA; @@ -1179,7 +1143,7 @@ YY_RULE_SETUP case 10: /* rule 10 can match eol */ YY_RULE_SETUP -#line 90 "template_parser.l" +#line 103 "template_parser.l" { yylval_param->val_str = mem_collector_strdup(mc,yytext+1); yylval_param->val_str[yyleng-2] = '\0'; @@ -1189,22 +1153,28 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 97 "template_parser.l" +#line 110 "template_parser.l" { yylval_param->val_str = mem_collector_strdup(mc,yytext); BEGIN(INITIAL); return STRING; } YY_BREAK -case 12: -YY_RULE_SETUP -#line 103 "template_parser.l" -ECHO; - YY_BREAK -#line 1205 "template_parser.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(VALUE): - yyterminate(); +#line 116 "template_parser.l" +{ + llocp->first_line = llocp->last_line; + llocp->first_column = llocp->last_column; + return 0; +} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 122 "template_parser.l" +ECHO; + YY_BREAK +#line 1178 "template_parser.cc" case YY_END_OF_BUFFER: { @@ -1501,7 +1471,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 69 ) + if ( yy_current_state >= 61 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; @@ -1530,11 +1500,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 69 ) + if ( yy_current_state >= 61 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 68); + yy_is_jam = (yy_current_state == 60); (void)yyg; return yy_is_jam ? 0 : yy_current_state; @@ -1615,13 +1585,6 @@ static int yy_get_next_buffer (yyscan_t yyscanner) *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ yyg->yy_hold_char = *++yyg->yy_c_buf_p; - if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - return c; } #endif /* ifndef YY_NO_INPUT */ @@ -2352,7 +2315,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 103 "template_parser.l" +#line 122 "template_parser.l" int template_wrap(yyscan_t scanner) diff --git a/src/parsers/template_parser.h b/src/parsers/template_parser.h index 652c368757..2df2197315 100644 --- a/src/parsers/template_parser.h +++ b/src/parsers/template_parser.h @@ -2,9 +2,9 @@ #define template_HEADER_H 1 #define template_IN_HEADER 1 -#line 5 "template_parser.h" +#line 6 "template_parser.h" -#line 7 "template_parser.h" +#line 8 "template_parser.h" #define YY_INT_ALIGNED short int @@ -710,9 +710,9 @@ extern int yylex \ #undef yyTABLES_NAME #endif -#line 103 "template_parser.l" +#line 122 "template_parser.l" -#line 716 "template_parser.h" +#line 717 "template_parser.h" #undef template_IN_HEADER #endif /* template_HEADER_H */ diff --git a/src/parsers/template_parser.l b/src/parsers/template_parser.l index c952117bc5..2e8756db4a 100644 --- a/src/parsers/template_parser.l +++ b/src/parsers/template_parser.l @@ -27,9 +27,24 @@ #define YY_DECL int template_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ mem_collector *mc, yyscan_t yyscanner) -#define YY_USER_ACTION llocp->first_line = yylineno; \ - llocp->first_column = llocp->last_column; \ - llocp->last_column += yyleng; +/* Track locations from Bison's initialized, one-based location. Flex's line + * counter is not initialized for string buffers. The end is exclusive. + */ +#define YY_USER_ACTION \ + llocp->first_line = llocp->last_line; \ + llocp->first_column = llocp->last_column; \ + for (int i = 0; i < yyleng; ++i) \ + { \ + if (yytext[i] == '\n') \ + { \ + ++llocp->last_line; \ + llocp->last_column = 1; \ + } \ + else \ + { \ + ++llocp->last_column; \ + } \ + } %} %option nounput @@ -37,7 +52,6 @@ %option outfile="template_parser.cc" %option header-file="template_parser.h" %option bison-bridge -%option yylineno %option reentrant %x VALUE @@ -64,15 +78,15 @@ CDATA "\]\]\>" /* Single attribute (VARIABLE = VALUE, also empty VAIABLE=) */ /* Vector attributes (VARIABLE = [ ATTR1 = VAL1, ATTR2 = VAL2 ]) */ /* ------------------------------------------------------------------------ */ -[[:blank:]]*=[[:blank:]]* { BEGIN VALUE; return EQUAL;} +"="[[:blank:]]* { BEGIN VALUE; return EQUAL;} -[[:blank:]]*=[[:blank:]]*\n { return EQUAL_EMPTY;} +"="[[:blank:]]*\n { return EQUAL_EMPTY;} -[[:blank:]\n]*,[[:blank:]\n]* { return COMMA;} +"," { return COMMA;} -[[:blank:]\n]*\][[:blank:]\n]* { return CBRACKET;} +"]" { return CBRACKET;} -[[:blank:]]*\[[[:blank:]\n]* { BEGIN(INITIAL); return OBRACKET;} +"["[[:blank:]\n]* { BEGIN(INITIAL); return OBRACKET;} /* ------------------------------------------------------------------------ */ /* Attribute values */ @@ -98,6 +112,12 @@ CDATA "\]\]\>" return STRING; } +<*><> { + llocp->first_line = llocp->last_line; + llocp->first_column = llocp->last_column; + return 0; +} + %% int template_wrap(yyscan_t scanner) diff --git a/src/parsers/template_syntax.cc b/src/parsers/template_syntax.cc index f23cae5689..8307afec7f 100644 --- a/src/parsers/template_syntax.cc +++ b/src/parsers/template_syntax.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.4.1. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -34,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -41,14 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.4.1" +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -70,7 +71,6 @@ #define yydebug template_debug #define yynerrs template_nerrs - /* First part of user prologue. */ #line 17 "template_syntax.y" @@ -78,7 +78,7 @@ #include "template_parser.h" #include "NebulaUtil.h" -#define YYERROR_VERBOSE +#include void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner, const char * str); @@ -104,6 +104,15 @@ static string& unescape (string &str); #line 106 "template_syntax.cc" +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif # ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -116,99 +125,30 @@ static string& unescape (string &str); # endif # endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Use api.header.include to #include this header - instead of duplicating it here. */ -#ifndef YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED -# define YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int template_debug; -#endif -/* "%code requires" blocks. */ -#line 47 "template_syntax.y" - -#include -#include -#include -#include - -#include -#include -#include - -#include "mem_collector.h" - -#include "Template.h" - -typedef void * yyscan_t; - -int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); - -#line 159 "template_syntax.cc" - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - EQUAL = 258, - COMMA = 259, - OBRACKET = 260, - CBRACKET = 261, - EQUAL_EMPTY = 262, - CCDATA = 263, - STRING = 264, - VARIABLE = 265 - }; -#endif - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -union YYSTYPE +#include "template_syntax.h" +/* Symbol kind. */ +enum yysymbol_kind_t { -#line 74 "template_syntax.y" - - char * val_str; - void * val_attr; - -#line 186 "template_syntax.cc" - + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_EQUAL = 3, /* "'='" */ + YYSYMBOL_COMMA = 4, /* "','" */ + YYSYMBOL_OBRACKET = 5, /* "'['" */ + YYSYMBOL_CBRACKET = 6, /* "']'" */ + YYSYMBOL_EQUAL_EMPTY = 7, /* "'=' followed by a newline" */ + YYSYMBOL_CCDATA = 8, /* "']]>'" */ + YYSYMBOL_STRING = 9, /* "attribute value" */ + YYSYMBOL_VARIABLE = 10, /* "attribute name" */ + YYSYMBOL_YYACCEPT = 11, /* $accept */ + YYSYMBOL_template_file = 12, /* template_file */ + YYSYMBOL_template = 13, /* template */ + YYSYMBOL_attribute = 14, /* attribute */ + YYSYMBOL_array_val = 15 /* array_val */ }; -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif +typedef enum yysymbol_kind_t yysymbol_kind_t; -/* Location type. */ -#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED -typedef struct YYLTYPE YYLTYPE; -struct YYLTYPE -{ - int first_line; - int first_column; - int last_line; - int last_column; -}; -# define YYLTYPE_IS_DECLARED 1 -# define YYLTYPE_IS_TRIVIAL 1 -#endif - - - -int template_parse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner); - -#endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ @@ -216,36 +156,95 @@ int template_parse (mem_collector * mc, Template * tmpl, char ** error_msg, yysc # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else typedef short yytype_int16; #endif +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -253,7 +252,20 @@ typedef short yytype_int16; # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -267,38 +279,43 @@ typedef short yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YY_USE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -311,10 +328,22 @@ typedef short yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + #define YY_ASSERT(E) ((void) (0 && (E))) -#if ! defined yyoverflow || YYERROR_VERBOSE +#if 1 /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -379,8 +408,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* 1 */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -390,18 +418,19 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; YYLTYPE yyls_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -414,11 +443,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -430,12 +459,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -458,17 +487,20 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 22 -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 265 + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ -static const yytype_uint8 yytranslate[] = +static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -500,47 +532,51 @@ static const yytype_uint8 yytranslate[] = }; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 94, 94, 95, 98, 99, 102, 112, 125, 134, - 144, 150, 163 + 0, 98, 98, 99, 102, 103, 106, 116, 129, 138, + 148, 154, 167 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if 1 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "EQUAL", "COMMA", "OBRACKET", "CBRACKET", - "EQUAL_EMPTY", "CCDATA", "STRING", "VARIABLE", "$accept", - "template_file", "template", "attribute", "array_val", YY_NULLPTR + "\"end of file\"", "error", "\"invalid token\"", "\"'='\"", "\"','\"", + "\"'['\"", "\"']'\"", "\"'=' followed by a newline\"", "\"']]>'\"", + "\"attribute value\"", "\"attribute name\"", "$accept", "template_file", + "template", "attribute", "array_val", YY_NULLPTR }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -# ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265 -}; -# endif +#define YYPACT_NINF (-6) -#define YYPACT_NINF -6 +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-6))) +#define YYTABLE_NINF (-1) -#define YYTABLE_NINF -1 - -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(Yyn) \ 0 - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int8 yypact[] = { 0, -2, 8, 0, -6, -5, -6, -6, -6, -4, @@ -548,75 +584,76 @@ static const yytype_int8 yypact[] = 6, -6 }; - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_int8 yydefact[] = { 2, 0, 0, 3, 4, 0, 9, 1, 5, 0, 10, 6, 8, 0, 0, 0, 0, 7, 11, 0, 0, 12 }; - /* YYPGOTO[NTERM-NUM]. */ +/* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { -6, -6, -6, 13, -6 }; - /* YYDEFGOTO[NTERM-NUM]. */ +/* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 2, 3, 4, 14 + 0, 2, 3, 4, 14 }; - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_uint8 yytable[] = +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int8 yytable[] = { 9, 5, 12, 10, 11, 6, 13, 16, 7, 17, 1, 18, 15, 20, 19, 21, 8 }; -static const yytype_uint8 yycheck[] = +static const yytype_int8 yycheck[] = { 5, 3, 6, 8, 9, 7, 10, 4, 0, 6, 10, 9, 3, 3, 10, 9, 3 }; - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_int8 yystos[] = { 0, 10, 12, 13, 14, 3, 7, 0, 14, 5, 8, 9, 6, 10, 15, 3, 4, 6, 9, 10, 3, 9 }; - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr1[] = { 0, 11, 12, 12, 13, 13, 14, 14, 14, 14, 14, 15, 15 }; - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = { 0, 2, 0, 1, 1, 2, 3, 5, 4, 2, 3, 3, 5 }; +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) @@ -638,10 +675,9 @@ static const yytype_uint8 yyr2[] = } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends @@ -685,12 +721,19 @@ do { \ } while (0) -/* YY_LOCATION_PRINT -- Print the location on the stream. +/* YYLOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ -#ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# ifndef YYLOCATION_PRINT + +# if defined YY_LOCATION_PRINT + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) + +# elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ @@ -718,24 +761,32 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) res += YYFPRINTF (yyo, "-%d", end_col); } return res; - } +} -# define YY_LOCATION_PRINT(File, Loc) \ - yy_location_print_ (File, &(Loc)) +# define YYLOCATION_PRINT yy_location_print_ -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) + +# else + +# define YYLOCATION_PRINT(File, Loc) ((void) 0) + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT YYLOCATION_PRINT + +# endif +# endif /* !defined YYLOCATION_PRINT */ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, tmpl, error_msg, scanner); \ + Kind, Value, Location, mc, tmpl, error_msg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -746,22 +797,21 @@ do { \ `-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { FILE *yyoutput = yyo; - YYUSE (yyoutput); - YYUSE (yylocationp); - YYUSE (mc); - YYUSE (tmpl); - YYUSE (error_msg); - YYUSE (scanner); + YY_USE (yyoutput); + YY_USE (yylocationp); + YY_USE (mc); + YY_USE (tmpl); + YY_USE (error_msg); + YY_USE (scanner); if (!yyvaluep) return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyo, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -770,14 +820,15 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YY `---------------------------*/ static void -yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { YYFPRINTF (yyo, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - YY_LOCATION_PRINT (yyo, *yylocationp); + YYLOCATION_PRINT (yyo, yylocationp); YYFPRINTF (yyo, ": "); - yy_symbol_value_print (yyo, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg, scanner); + yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, mc, tmpl, error_msg, scanner); YYFPRINTF (yyo, ")"); } @@ -787,7 +838,7 @@ yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -810,21 +861,22 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, + int yyrule, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { - unsigned long yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &yyvsp[(yyi + 1) - (yynrhs)] - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, tmpl, error_msg, scanner); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)], + &(yylsp[(yyi + 1) - (yynrhs)]), mc, tmpl, error_msg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -839,8 +891,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -863,28 +915,77 @@ int yydebug; #endif -#if YYERROR_VERBOSE +/* Context of a parse error. */ +typedef struct +{ + yy_state_t *yyssp; + yysymbol_kind_t yytoken; + YYLTYPE *yylloc; +} yypcontext_t; -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +/* Put in YYARG at most YYARGN of the expected tokens given the + current YYCTX, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). Return YYENOMEM on memory exhaustion. + Return 0 if there are more than YYARGN expected tokens, yet fill + YYARG up to YYARGN. */ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + /* Actual size of YYARG. */ + int yycount = 0; + int yyn = yypact[+*yyctx->yyssp]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + } + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = YYSYMBOL_YYEMPTY; + return yycount; +} + + + + +#ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else /* Return the length of YYSTR. */ -static YYSIZE_T +static YYPTRDIFF_T yystrlen (const char *yystr) { - YYSIZE_T yylen; + YYPTRDIFF_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif # endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * @@ -898,10 +999,10 @@ yystpcpy (char *yydest, const char *yysrc) return yyd - 1; } -# endif # endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -909,14 +1010,13 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T +static YYPTRDIFF_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { - YYSIZE_T yyn = 0; + YYPTRDIFF_T yyn = 0; char const *yyp = yystr; - for (;;) switch (*++yyp) { @@ -945,36 +1045,20 @@ yytnamerr (char *yyres, const char *yystr) do_not_strip_quotes: ; } - if (! yyres) + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else return yystrlen (yystr); - - return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } -# endif +#endif -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +yy_syntax_error_arguments (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ + /* Actual size of YYARG. */ int yycount = 0; - /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then the only way this function was invoked is if the default action @@ -998,49 +1082,54 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, one exception: it will still contain any token that will not be accepted due to an error action in a later state. */ - if (yytoken != YYEMPTY) + if (yyctx->yytoken != YYSYMBOL_YYEMPTY) { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - } + int yyn; + if (yyarg) + yyarg[yycount] = yyctx->yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yyctx, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM; + else + yycount += yyn; } + return yycount; +} + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return -1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return YYENOMEM if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + const yypcontext_t *yyctx) +{ + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + return YYENOMEM; switch (yycount) { -# define YYCASE_(N, S) \ +#define YYCASE_(N, S) \ case N: \ yyformat = S; \ - break + break default: /* Avoid compiler warnings. */ YYCASE_(0, YY_("syntax error")); YYCASE_(1, YY_("syntax error, unexpected %s")); @@ -1048,15 +1137,23 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ +#undef YYCASE_ } + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]); + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return YYENOMEM; + } } if (*yymsg_alloc < yysize) @@ -1065,7 +1162,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, if (! (yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; + return -1; } /* Avoid sprintf, as that infringes on the user's name space. @@ -1077,44 +1174,47 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) { - yyp += yytnamerr (yyp, yyarg[yyi++]); + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]); yyformat += 2; } else { - yyp++; - yyformat++; + ++yyp; + ++yyformat; } } return 0; } -#endif /* YYERROR_VERBOSE */ + /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { - YYUSE (yyvaluep); - YYUSE (yylocationp); - YYUSE (mc); - YYUSE (tmpl); - YYUSE (error_msg); - YYUSE (scanner); + YY_USE (yyvaluep); + YY_USE (yylocationp); + YY_USE (mc); + YY_USE (tmpl); + YY_USE (error_msg); + YY_USE (scanner); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } + + /*----------. | yyparse. | `----------*/ @@ -1122,7 +1222,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio int yyparse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { -/* The lookahead symbol. */ +/* Lookahead token kind. */ int yychar; @@ -1141,55 +1241,50 @@ static YYLTYPE yyloc_default YYLTYPE yylloc = yyloc_default; /* Number of syntax errors so far. */ - int yynerrs; + int yynerrs = 0; - int yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - 'yyls': related to locations. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; - /* The semantic value stack. */ + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; - /* The location stack. */ + /* The location stack: array, bottom, top. */ YYLTYPE yylsa[YYINITDEPTH]; - YYLTYPE *yyls; - YYLTYPE *yylsp; - - /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[3]; - - YYSIZE_T yystacksize; + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp = yyls; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; YYLTYPE yyloc; -#if YYERROR_VERBOSE + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; + /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) @@ -1197,17 +1292,10 @@ YYLTYPE yylloc = yyloc_default; Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yylsp = yyls = yylsa; - yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ + yylsp[0] = yylloc; goto yysetstate; @@ -1222,28 +1310,31 @@ yynewstate: /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: YYDPRINTF ((stderr, "Entering state %d\n", yystate)); YY_ASSERT (0 <= yystate && yystate < YYNSTATES); - *yyssp = (yytype_int16) yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; + YYNOMEM; #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ + yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; YYLTYPE *yyls1 = yyls; /* Each stack pointer address is followed by the size of the @@ -1251,9 +1342,9 @@ yysetstate: conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yyls1, yysize * sizeof (*yylsp), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yyls1, yysize * YYSIZEOF (*yylsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; @@ -1262,21 +1353,22 @@ yysetstate: # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) - goto yyexhaustedlab; + YYNOMEM; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); YYSTACK_RELOCATE (yyls_alloc, yyls); -# undef YYSTACK_RELOCATE +# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } @@ -1286,14 +1378,17 @@ yysetstate: yyvsp = yyvs + yysize - 1; yylsp = yyls + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + if (yystate == YYFINAL) YYACCEPT; @@ -1314,18 +1409,30 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token: ")); + YYDPRINTF ((stderr, "Reading a token\n")); yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) { - yychar = yytoken = YYEOF; + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + yyerror_range[1] = yylloc; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -1353,15 +1460,14 @@ yybackup: /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; + + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; @@ -1398,9 +1504,9 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 6: -#line 103 "template_syntax.y" - { + case 6: /* attribute: "attribute name" "'='" "attribute value" */ +#line 107 "template_syntax.y" + { Attribute * pattr; string name((yyvsp[-2].val_str)); string value((yyvsp[0].val_str)); @@ -1409,12 +1515,12 @@ yyreduce: tmpl->set(pattr); } -#line 1413 "template_syntax.cc" +#line 1519 "template_syntax.cc" break; - case 7: -#line 113 "template_syntax.y" - { + case 7: /* attribute: "attribute name" "'='" "'['" array_val "']'" */ +#line 117 "template_syntax.y" + { Attribute * pattr; string name((yyvsp[-4].val_str)); map * amap; @@ -1426,12 +1532,12 @@ yyreduce: delete amap; } -#line 1430 "template_syntax.cc" +#line 1536 "template_syntax.cc" break; - case 8: -#line 126 "template_syntax.y" - { + case 8: /* attribute: "attribute name" "'='" "'['" "']'" */ +#line 130 "template_syntax.y" + { Attribute * pattr; string name((yyvsp[-3].val_str)); @@ -1439,12 +1545,12 @@ yyreduce: tmpl->set(pattr); } -#line 1443 "template_syntax.cc" +#line 1549 "template_syntax.cc" break; - case 9: -#line 135 "template_syntax.y" - { + case 9: /* attribute: "attribute name" "'=' followed by a newline" */ +#line 139 "template_syntax.y" + { Attribute * pattr; string name((yyvsp[-1].val_str)); string value; @@ -1453,20 +1559,20 @@ yyreduce: tmpl->set(pattr); } -#line 1457 "template_syntax.cc" +#line 1563 "template_syntax.cc" break; - case 10: -#line 145 "template_syntax.y" - { + case 10: /* attribute: "attribute name" "'='" "']]>'" */ +#line 149 "template_syntax.y" + { YYABORT; } -#line 1465 "template_syntax.cc" +#line 1571 "template_syntax.cc" break; - case 11: -#line 151 "template_syntax.y" - { + case 11: /* array_val: "attribute name" "'='" "attribute value" */ +#line 155 "template_syntax.y" + { map* vattr; string name((yyvsp[-2].val_str)); string value((yyvsp[0].val_str)); @@ -1478,12 +1584,12 @@ yyreduce: (yyval.val_attr) = static_cast(vattr); } -#line 1482 "template_syntax.cc" +#line 1588 "template_syntax.cc" break; - case 12: -#line 164 "template_syntax.y" - { + case 12: /* array_val: array_val "','" "attribute name" "'='" "attribute value" */ +#line 168 "template_syntax.y" + { string name((yyvsp[-2].val_str)); string value((yyvsp[0].val_str)); map * attrmap; @@ -1495,11 +1601,11 @@ yyreduce: attrmap->insert(make_pair(name,unescape(value))); (yyval.val_attr) = (yyvsp[-4].val_attr); } -#line 1499 "template_syntax.cc" +#line 1605 "template_syntax.cc" break; -#line 1503 "template_syntax.cc" +#line 1609 "template_syntax.cc" default: break; } @@ -1514,11 +1620,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; *++yylsp = yyloc; @@ -1543,50 +1648,45 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, tmpl, error_msg, scanner, YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) { + yypcontext_t yyctx + = {yyssp, yytoken, &yylloc}; char const *yymsgp = YY_("syntax error"); int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; + yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); if (yysyntax_error_status == 0) yymsgp = yymsg; - else if (yysyntax_error_status == 1) + else if (yysyntax_error_status == -1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) + yymsg = YY_CAST (char *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (yymsg) { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; + yysyntax_error_status + = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + yymsgp = yymsg; } else { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = YYENOMEM; } } yyerror (&yylloc, mc, tmpl, error_msg, scanner, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + if (yysyntax_error_status == YYENOMEM) + YYNOMEM; } -# undef YYSYNTAX_ERROR -#endif } yyerror_range[1] = yylloc; - if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -1619,6 +1719,7 @@ yyerrorlab: label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; + ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -1635,13 +1736,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -1655,7 +1757,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, tmpl, error_msg, scanner); + YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp, mc, tmpl, error_msg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1666,13 +1768,11 @@ yyerrlab1: YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; - /* Using YYLLOC is tempting, but would change the location of - the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, yyerror_range, 2); - *++yylsp = yyloc; + ++yylsp; + YYLLOC_DEFAULT (*yylsp, yyerror_range, 2); /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1683,7 +1783,7 @@ yyerrlab1: `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturn; + goto yyreturnlab; /*-----------------------------------. @@ -1691,24 +1791,22 @@ yyacceptlab: `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturn; + goto yyreturnlab; -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ yyexhaustedlab: yyerror (&yylloc, mc, tmpl, error_msg, scanner, YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ -#endif + goto yyreturnlab; -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ -yyreturn: +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at @@ -1724,20 +1822,19 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, tmpl, error_msg, scanner); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp, mc, tmpl, error_msg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif -#if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); -#endif return yyresult; } -#line 177 "template_syntax.y" + +#line 181 "template_syntax.y" string& unescape (string &str) @@ -1760,20 +1857,14 @@ void template_error( yyscan_t scanner, const char * str) { - int length; + ostringstream oss; + string message(str); - length = strlen(str)+ 64; + // Bison keeps double quotes around aliases containing single quotes. + message.erase(remove(message.begin(), message.end(), '"'), message.end()); - *error_msg = (char *) malloc(sizeof(char)*length); + oss << message << " at line " << llocp->first_line + << ", column " << llocp->first_column; - if (*error_msg != 0) - { - snprintf(*error_msg, - length, - "%s at line %i, columns %i:%i", - str, - llocp->first_line, - llocp->first_column, - llocp->last_column); - } + *error_msg = strdup(oss.str().c_str()); } diff --git a/src/parsers/template_syntax.h b/src/parsers/template_syntax.h index 717876314d..f9eec7d7c9 100644 --- a/src/parsers/template_syntax.h +++ b/src/parsers/template_syntax.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.4.1. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -31,11 +31,12 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ -#ifndef YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED -# define YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED +#ifndef YY_TEMPLATE_TEMPLATE_SYNTAX_H_INCLUDED +# define YY_TEMPLATE_TEMPLATE_SYNTAX_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -65,34 +66,39 @@ typedef void * yyscan_t; int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); -#line 67 "template_syntax.hh" +#line 70 "template_syntax.h" -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - EQUAL = 258, - COMMA = 259, - OBRACKET = 260, - CBRACKET = 261, - EQUAL_EMPTY = 262, - CCDATA = 263, - STRING = 264, - VARIABLE = 265 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + EQUAL = 258, /* "'='" */ + COMMA = 259, /* "','" */ + OBRACKET = 260, /* "'['" */ + CBRACKET = 261, /* "']'" */ + EQUAL_EMPTY = 262, /* "'=' followed by a newline" */ + CCDATA = 263, /* "']]>'" */ + STRING = 264, /* "attribute value" */ + VARIABLE = 265 /* "attribute name" */ }; + typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED union YYSTYPE { -#line 74 "template_syntax.y" +#line 76 "template_syntax.y" char * val_str; void * val_attr; -#line 94 "template_syntax.hh" +#line 102 "template_syntax.h" }; typedef union YYSTYPE YYSTYPE; @@ -116,6 +122,8 @@ struct YYLTYPE + int template_parse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner); -#endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ + +#endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_H_INCLUDED */ diff --git a/src/parsers/template_syntax.y b/src/parsers/template_syntax.y index 7e42d63655..820f2079c5 100644 --- a/src/parsers/template_syntax.y +++ b/src/parsers/template_syntax.y @@ -19,7 +19,7 @@ #include "template_parser.h" #include "NebulaUtil.h" -#define YYERROR_VERBOSE +#include void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner, const char * str); @@ -80,13 +80,15 @@ int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); %defines %locations +%define parse.error verbose %pure-parser %name-prefix "template_" %output "template_syntax.cc" -%token EQUAL COMMA OBRACKET CBRACKET EQUAL_EMPTY CCDATA -%token STRING -%token VARIABLE +%token EQUAL "'='" COMMA "','" OBRACKET "'['" CBRACKET "']'" +%token EQUAL_EMPTY "'=' followed by a newline" CCDATA "']]>'" +%token STRING "attribute value" +%token VARIABLE "attribute name" %type array_val %type attribute %type template @@ -198,20 +200,14 @@ void template_error( yyscan_t scanner, const char * str) { - int length; + ostringstream oss; + string message(str); - length = strlen(str)+ 64; + // Bison keeps double quotes around aliases containing single quotes. + message.erase(remove(message.begin(), message.end(), '"'), message.end()); - *error_msg = (char *) malloc(sizeof(char)*length); + oss << message << " at line " << llocp->first_line + << ", column " << llocp->first_column; - if (*error_msg != 0) - { - snprintf(*error_msg, - length, - "%s at line %i, columns %i:%i", - str, - llocp->first_line, - llocp->first_column, - llocp->last_column); - } + *error_msg = strdup(oss.str().c_str()); }