yacc.c: no longer support YYERROR_VERBOSE

Supporting YYERROR_VERBOSE via cpp is a nuisance: m4 is in charge of
handling alternatives.  When adding more options for %define
parse.error, supporting both CPP and M4 is too complex.  Anyway,
YYERROR_VERBOSE was deprecated long ago.

* data/skeletons/yacc.c: Use m4 only to handle verbose/simple error
messages.
This commit is contained in:
Akim Demaille
2020-01-03 12:03:37 +01:00
parent 69fe4b9eb6
commit 7122d747cf
2 changed files with 21 additions and 32 deletions

View File

@@ -348,14 +348,6 @@ m4_if(b4_api_prefix, [yy], [],
]b4_cast_define[ ]b4_cast_define[
]b4_null_define[ ]b4_null_define[
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
#endif
]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])], ]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])],
[m4_ifval(m4_quote(b4_spec_header_file), [m4_ifval(m4_quote(b4_spec_header_file),
[/* Use api.header.include to #include this header [/* Use api.header.include to #include this header
@@ -437,7 +429,7 @@ typedef int yy_state_fast_t;
]], ]],
[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ [[#define YY_ASSERT(E) ((void) (0 && (E)))]])[
#if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[ #if ]b4_lac_if([[1]], [b4_error_verbose_if([[1]], [[!defined yyoverflow]])])[
/* The parser invokes alloca or malloc; define the necessary symbols. */]dnl /* The parser invokes alloca or malloc; define the necessary symbols. */]dnl
b4_push_if([], [b4_lac_if([], [[ b4_push_if([], [b4_lac_if([], [[
@@ -504,8 +496,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif # endif
# endif]b4_lac_if([[ # endif]b4_lac_if([[
# define YYCOPY_NEEDED 1]])[ # define YYCOPY_NEEDED 1]])[
#endif]b4_lac_if([], [[ /* ! defined yyoverflow || YYERROR_VERBOSE */]])[ #endif]b4_lac_if([], [b4_error_verbose_if([], [[/* !defined yyoverflow */]])])[
#if (! defined yyoverflow \ #if (! defined yyoverflow \
&& (! defined __cplusplus \ && (! defined __cplusplus \
@@ -611,7 +602,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
#endif #endif
#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ #if ]b4_error_verbose_if([[1]], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag])[
/* 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[] =
@@ -1039,9 +1030,8 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
}]])[ }]])[
#if YYERROR_VERBOSE ]m4_case(b4_percent_define_get([parse.error]), [verbose],
[[# ifndef yystrlen
# ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H # if defined __GLIBC__ && defined _STRING_H
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
# else # else
@@ -1287,7 +1277,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
} }
return 0; return 0;
} }
#endif /* YYERROR_VERBOSE */ ]])[
]b4_yydestruct_define[ ]b4_yydestruct_define[
@@ -1428,12 +1418,11 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
YYSTYPE yyval;]b4_locations_if([[ YYSTYPE yyval;]b4_locations_if([[
YYLTYPE yyloc;]])[ YYLTYPE yyloc;]])[
#if YYERROR_VERBOSE ]m4_case(b4_percent_define_get([parse.error]), [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;
YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;]])[
#endif
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[) #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[)
@@ -1750,10 +1739,11 @@ yyerrlab:
if (!yyerrstatus) if (!yyerrstatus)
{ {
++yynerrs; ++yynerrs;
#if ! YYERROR_VERBOSE ]m4_case(b4_percent_define_get([parse.error]),
yyerror (]b4_yyerror_args[YY_("syntax error")); [simple],
#else [[ yyerror (]b4_yyerror_args[YY_("syntax error"));]],
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[ [verbose],
[[# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[
yyesa, &yyes, &yyes_capacity, \]])[ yyesa, &yyes, &yyes_capacity, \]])[
yyssp, yytoken) yyssp, yytoken)
{ {
@@ -1785,8 +1775,7 @@ yyerrlab:
if (yysyntax_error_status == 2) if (yysyntax_error_status == 2)
goto yyexhaustedlab; goto yyexhaustedlab;
} }
# undef YYSYNTAX_ERROR # undef YYSYNTAX_ERROR]])[
#endif
} }
]b4_locations_if([[ yyerror_range[1] = yylloc;]])[ ]b4_locations_if([[ yyerror_range[1] = yylloc;]])[
@@ -1902,7 +1891,7 @@ yyabortlab:
goto yyreturn; goto yyreturn;
#if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[ #if ]b4_lac_if([[1]], [b4_error_verbose_if([[1]], [[!defined yyoverflow]])])[
/*-------------------------------------------------. /*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. | | yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/ `-------------------------------------------------*/
@@ -1948,10 +1937,9 @@ yyreturn:
| yypushreturn -- ask for the next token. | | yypushreturn -- ask for the next token. |
`-----------------------------------------*/ `-----------------------------------------*/
yypushreturn:]])[ yypushreturn:]])[
#if YYERROR_VERBOSE ]m4_case(b4_percent_define_get([parse.error]), [verbose],
if (yymsg != yymsgbuf) [[ if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg); YYSTACK_FREE (yymsg);]])[
#endif
return yyresult; return yyresult;
} }
]b4_epilogue[]dnl ]b4_epilogue[]dnl

View File

@@ -309,7 +309,6 @@ AT_DATA_GRAMMAR([input.y],
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define YYERROR_VERBOSE 1
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
/* The current argument. */ /* The current argument. */
static const char *input; static const char *input;
@@ -324,6 +323,8 @@ yylex (void)
%} %}
%define parse.error verbose
%nonassoc '<' '>' %nonassoc '<' '>'
%% %%