[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/12] yacc.c: store token numbers, not token strings
From: |
Akim Demaille |
Subject: |
[PATCH 02/12] yacc.c: store token numbers, not token strings |
Date: |
Thu, 16 Jan 2020 07:58:13 +0100 |
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.
---
data/skeletons/yacc.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index cc4e4bdf..4f088036 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1058,7 +1058,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
static int
yysyntax_error_arguments (const yyparse_context_t *yyctx,
- const char *yyarg[], int yyargn)
+ int yyarg[], int yyargn)
{
/* Actual size of YYARG. */
int yycount = 0;
@@ -1094,7 +1094,7 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx,
{
int yyn = yypact[+*yyctx->yyssp];]b4_lac_if([[
YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
- yyarg[yycount++] = yytname[yyctx->yytoken];
+ yyarg[yycount++] = yyctx->yytoken;
if (!yypact_value_is_default (yyn))
{]b4_lac_if([[
int yyx;
@@ -1126,7 +1126,7 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx,
yycount = 1;
break;
}
- yyarg[yycount++] = yytname[yyx];
+ yyarg[yycount++] = yyx;
}
}]b4_lac_if([[
else
@@ -1244,7 +1244,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Actual size of YYARG. */
int yycount = 0;
/* Cumulated lengths of YYARG. */
@@ -1283,7 +1283,8 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
int 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)
yysize = yysize1;
else
@@ -1309,7 +1310,7 @@ yysyntax_error (YYPTRDIFF_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
--
2.24.1
- RFC: custom error messages, Akim Demaille, 2020/01/03
- Re: RFC: custom error messages, Christian Schoenebeck, 2020/01/03
- Re: RFC: custom error messages, Akim Demaille, 2020/01/05
- Re: RFC: custom error messages, Christian Schoenebeck, 2020/01/09
- Re: RFC: custom error messages, Akim Demaille, 2020/01/10
- Re: RFC: custom error messages, Christian Schoenebeck, 2020/01/14
- Re: RFC: custom error messages, Akim Demaille, 2020/01/14
- [PATCH 00/12] RFC: yyreport_error_message, Akim Demaille, 2020/01/16
- Re: [PATCH 00/12] RFC: yyreport_error_message, Akim Demaille, 2020/01/18
- [PATCH 02/12] yacc.c: store token numbers, not token strings,
Akim Demaille <=
- [PATCH 03/12] yacc.c: style: avoid macros, Akim Demaille, 2020/01/16
- [PATCH 01/12] yacc.c: extract yyerror_message_arguments, Akim Demaille, 2020/01/16
- [PATCH 04/12] yacc.c: add custom error message generation, Akim Demaille, 2020/01/16
- [PATCH 06/12] tests: compute verbose error messages from the custom ones, Akim Demaille, 2020/01/16
- [PATCH 05/12] yacc.c: check custom error messages, Akim Demaille, 2020/01/16
- [PATCH 07/12] yacc.c: isolate yyexpected_tokens, Akim Demaille, 2020/01/16
- [PATCH 08/12] yacc.c: let custom error messages see the location, Akim Demaille, 2020/01/16
- [PATCH 09/12] yacc.c: check custom error messages with parse-params, Akim Demaille, 2020/01/16
- [PATCH 10/12] tests: a clearer test for parse-params, Akim Demaille, 2020/01/16
- [PATCH 12/12] yacc.c: portability to G++ 4.8, Akim Demaille, 2020/01/16