skeletons: prefer b4_parse_error_{case,bmatch} over manual solution

Prefer b4_parse_error_case over the adhoc solution
`m4_case + b4_percent_define_get`. Same for b4_parse_error_bmatch.

* data/skeletons/glr.c: here
* data/skeletons/yacc.c: here
This commit is contained in:
Adrian Vogelsgesang
2020-02-13 10:22:21 +01:00
committed by Akim Demaille
parent 368fcf0af5
commit d4fcd5c3d0
3 changed files with 21 additions and 22 deletions

View File

@@ -700,14 +700,14 @@ static void yypdumpstack (yyGLRStack* yystackp)
#endif /* !]b4_api_PREFIX[DEBUG */ #endif /* !]b4_api_PREFIX[DEBUG */
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[simple], [simple],
[[]], [[]],
[[#ifndef yystrlen [[#ifndef yystrlen
# define yystrlen(S) (YY_CAST (ptrdiff_t, strlen (S))) # define yystrlen(S) (YY_CAST (ptrdiff_t, strlen (S)))
#endif #endif
]m4_bmatch(b4_percent_define_get([[parse.error]]), ]b4_parse_error_bmatch(
[detailed\|verbose], [detailed\|verbose],
[[#ifndef yystpcpy [[#ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
@@ -729,7 +729,7 @@ yystpcpy (char *yydest, const char *yysrc)
# endif # endif
#endif]])[ #endif]])[
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[verbose], [verbose],
[[#ifndef yytnamerr [[#ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
@@ -2089,7 +2089,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
return yyok; return yyok;
} }
]m4_if(b4_percent_define_get([[parse.error]]), [simple], [], ]b4_parse_error_case([simple], [],
[[/* Put in YYARG at most YYARGN of the expected tokens given the [[/* Put in YYARG at most YYARGN of the expected tokens given the
current YYSTACKP, and return the number of tokens stored in YYARG. If current YYSTACKP, and return the number of tokens stored in YYARG. If
YYARG is null, return the number of expected tokens (guaranteed to YYARG is null, return the number of expected tokens (guaranteed to
@@ -2175,7 +2175,7 @@ yysyntax_error_arguments (const yyGLRStack* yystackp,
} }
]])[ ]])[
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[custom], [custom],
[[/* User defined function to report a syntax error. */ [[/* User defined function to report a syntax error. */
typedef yyGLRStack yyparse_context_t; typedef yyGLRStack yyparse_context_t;
@@ -2199,7 +2199,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
{ {
if (yystackp->yyerrState != 0) if (yystackp->yyerrState != 0)
return; return;
]m4_case(b4_percent_define_get([parse.error]), ]b4_parse_error_case(
[custom], [custom],
[[ if (yyreport_syntax_error (yystackp]b4_user_args[)) [[ if (yyreport_syntax_error (yystackp]b4_user_args[))
yyMemoryExhausted (yystackp);]], yyMemoryExhausted (yystackp);]],
@@ -2247,7 +2247,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
for (yyi = 0; yyi < yycount; ++yyi) for (yyi = 0; yyi < yycount; ++yyi)
{ {
ptrdiff_t yysz ptrdiff_t yysz
= ]m4_case(b4_percent_define_get([[parse.error]]), = ]b4_parse_error_case(
[verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]],
[[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[
if (YYSIZEMAX - yysize < yysz) if (YYSIZEMAX - yysize < yysz)
@@ -2267,7 +2267,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
while ((*yyp = *yyformat)) while ((*yyp = *yyformat))
{ {
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{]m4_case(b4_percent_define_get([[parse.error]]), [verbose], [[ {]b4_parse_error_case([verbose], [[
yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[
yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[
yyformat += 2; yyformat += 2;

View File

@@ -93,7 +93,7 @@ import java.text.MessageFormat;
{ {
]b4_identification[ ]b4_identification[
][ ][
]m4_bmatch(b4_percent_define_get([[parse.error]]), ]b4_parse_error_bmatch(
[detailed\|verbose], [[ [detailed\|verbose], [[
/** /**
* True if verbose error messages are enabled. * True if verbose error messages are enabled.
@@ -217,7 +217,7 @@ import java.text.MessageFormat;
*/ */
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg); void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);
]m4_bmatch(b4_percent_define_get([[parse.error]]), ]b4_parse_error_bmatch(
[custom], [[ [custom], [[
void yyreportSyntaxError (][Context yyctx); void yyreportSyntaxError (][Context yyctx);
]])[ ]])[
@@ -958,7 +958,7 @@ b4_dollar_popdef[]dnl
* Report a syntax error. * Report a syntax error.
*/ */
private void yyreportSyntaxError (Context yyctx) private void yyreportSyntaxError (Context yyctx)
{]m4_bmatch(b4_percent_define_get([parse.error]), {]b4_parse_error_bmatch(
[custom], [[ [custom], [[
yylexer.yyreportSyntaxError (yyctx);]], yylexer.yyreportSyntaxError (yyctx);]],
[detailed\|verbose], [[ [detailed\|verbose], [[
@@ -1013,7 +1013,7 @@ b4_dollar_popdef[]dnl
]b4_parser_tables_define[ ]b4_parser_tables_define[
]m4_bmatch(b4_percent_define_get([[parse.error]]), ]b4_parse_error_bmatch(
[simple\|verbose], [simple\|verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and [[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is backslashes, so that it's suitable for yyerror. The heuristic is

View File

@@ -607,8 +607,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
YYSYMBOL. No bounds checking. */ YYSYMBOL. No bounds checking. */
static const char *yysymbol_name (int yysymbol) YY_ATTRIBUTE_UNUSED; static const char *yysymbol_name (int yysymbol) YY_ATTRIBUTE_UNUSED;
]m4_bmatch(b4_percent_define_get([[parse.error]]), ]b4_parse_error_bmatch([simple\|verbose],
[simple\|verbose],
[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. [[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] = static const char *const yytname[] =
@@ -1067,7 +1066,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
} }
}]])[ }]])[
]m4_if(b4_percent_define_get([[parse.error]]), [simple], [], ]b4_parse_error_case([simple], [],
[[typedef struct [[typedef struct
{ {
yy_state_t *yyssp; yy_state_t *yyssp;
@@ -1185,7 +1184,7 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx,
} }
]])[ ]])[
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[custom], [custom],
[b4_locations_if([[/* The location of this context. */ [b4_locations_if([[/* The location of this context. */
static YYLTYPE * static YYLTYPE *
@@ -1239,7 +1238,7 @@ yyparse_context_location (const yyparse_context_t *yyctx)
# endif # endif
#endif #endif
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[verbose], [verbose],
[[#ifndef yytnamerr [[#ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
@@ -1345,7 +1344,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
for (yyi = 0; yyi < yycount; ++yyi) for (yyi = 0; yyi < yycount; ++yyi)
{ {
YYPTRDIFF_T yysize1 YYPTRDIFF_T yysize1
= yysize + ]m4_case(b4_percent_define_get([[parse.error]]), = yysize + ]b4_parse_error_case(
[verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]],
[[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
@@ -1372,7 +1371,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
int yyi = 0; int yyi = 0;
while ((*yyp = *yyformat) != '\0') while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{]m4_case(b4_percent_define_get([[parse.error]]), [verbose], [[ {]b4_parse_error_case([verbose], [[
yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[
yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[
yyformat += 2; yyformat += 2;
@@ -1528,7 +1527,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
YYSTYPE yyval;]b4_locations_if([[ YYSTYPE yyval;]b4_locations_if([[
YYLTYPE yyloc;]])[ YYLTYPE yyloc;]])[
]m4_bmatch(b4_percent_define_get([[parse.error]]), [detailed\|verbose], ]b4_parse_error_bmatch([detailed\|verbose],
[[ /* Buffer for error messages, and its allocated size. */ [[ /* Buffer for error messages, and its allocated size. */
char yymsgbuf[128]; char yymsgbuf[128];
char *yymsg = yymsgbuf; char *yymsg = yymsgbuf;
@@ -1849,7 +1848,7 @@ yyerrlab:
if (!yyerrstatus) if (!yyerrstatus)
{ {
++yynerrs; ++yynerrs;
]m4_case(b4_percent_define_get([[parse.error]]), ]b4_parse_error_case(
[custom], [custom],
[[ { [[ {
yyparse_context_t yyctx yyparse_context_t yyctx
@@ -2056,7 +2055,7 @@ yyreturn:
| yypushreturn -- ask for the next token. | | yypushreturn -- ask for the next token. |
`-----------------------------------------*/ `-----------------------------------------*/
yypushreturn:]])[ yypushreturn:]])[
]m4_bmatch(b4_percent_define_get([[parse.error]]), [detailed\|verbose], ]b4_parse_error_bmatch([detailed\|verbose],
[[ if (yymsg != yymsgbuf) [[ if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);]])[ YYSTACK_FREE (yymsg);]])[
return yyresult; return yyresult;