yacc.c: store token numbers, not token strings

That allows users to cover more cases, such as easily filtering some
arguments they don't want to expose.  But they now have to call
yysymbol_name explicitly.

* data/skeletons/yacc.c (yysyntax_error_arguments, yysyntax_error):
Deal with symbol numbers instead of symbol names.
This commit is contained in:
Akim Demaille
2020-01-05 09:38:16 +01:00
parent cc6c647f00
commit 135d0336d5

View File

@@ -1058,7 +1058,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
static int static int
yysyntax_error_arguments (const yyparse_context_t *yyctx, yysyntax_error_arguments (const yyparse_context_t *yyctx,
const char *yyarg[], int yyargn) int yyarg[], int yyargn)
{ {
/* Actual size of YYARG. */ /* Actual size of YYARG. */
int yycount = 0; int yycount = 0;
@@ -1094,7 +1094,7 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx,
{ {
int yyn = yypact[+*yyctx->yyssp];]b4_lac_if([[ int yyn = yypact[+*yyctx->yyssp];]b4_lac_if([[
YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[ YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
yyarg[yycount++] = yytname[yyctx->yytoken]; yyarg[yycount++] = yyctx->yytoken;
if (!yypact_value_is_default (yyn)) if (!yypact_value_is_default (yyn))
{]b4_lac_if([[ {]b4_lac_if([[
int yyx; int yyx;
@@ -1126,7 +1126,7 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx,
yycount = 1; yycount = 1;
break; break;
} }
yyarg[yycount++] = yytname[yyx]; yyarg[yycount++] = yyx;
} }
}]b4_lac_if([[ }]b4_lac_if([[
else else
@@ -1244,7 +1244,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
const char *yyformat = YY_NULLPTR; const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat: reported tokens (one for the "unexpected", /* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */ one per "expected"). */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; int yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Actual size of YYARG. */ /* Actual size of YYARG. */
int yycount = 0; int yycount = 0;
/* Cumulated lengths of YYARG. */ /* Cumulated lengths of YYARG. */
@@ -1283,7 +1283,8 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
int yyi; int yyi;
for (yyi = 0; yyi < yycount; ++yyi) for (yyi = 0; yyi < yycount; ++yyi)
{ {
YYPTRDIFF_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yyarg[yyi]); YYPTRDIFF_T yysize1
= yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]);
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1; yysize = yysize1;
else else
@@ -1309,7 +1310,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
while ((*yyp = *yyformat) != '\0') while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{ {
yyp += yytnamerr (yyp, yyarg[yyi++]); yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);
yyformat += 2; yyformat += 2;
} }
else else