From bc74b4b15af819271b2ffe7aefc6be8208f8591e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 10 Feb 2020 07:23:03 +0100 Subject: [PATCH] skeletons: avoid b4_error_verbose_if, which is confusing parse.error has more than two possible values. * data/skeletons/bison.m4 (b4_error_verbose_if, b4_error_verbose_flag): Remove. (b4_parse_error_case, b4_parse_error_bmatch): New. Adjust dependencies. --- data/skeletons/bison.m4 | 24 ++++++++++++++---------- data/skeletons/glr.c | 5 ++--- data/skeletons/lalr1.cc | 13 ++++++------- data/skeletons/lalr1.d | 2 +- data/skeletons/yacc.c | 8 ++++---- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4 index 993346e1..37a64f1c 100644 --- a/data/skeletons/bison.m4 +++ b/data/skeletons/bison.m4 @@ -1016,20 +1016,24 @@ m4_define([b4_bison_locations_if], [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) -# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) + +# %define parse.error "(custom|detailed|simple|verbose)" # ------------------------------------------------------ -# Map %define parse.error "(custom|detailed|simple|verbose)" to -# b4_error_verbose_if and b4_error_verbose_flag. b4_percent_define_default([[parse.error]], [[simple]]) b4_percent_define_check_values([[[[parse.error]], [[custom]], [[detailed]], [[simple]], [[verbose]]]]) -m4_define([b4_error_verbose_flag], - [m4_case(b4_percent_define_get([[parse.error]]), - [custom], [[1]], - [detailed], [[1]], - [simple], [[0]], - [verbose], [[1]])]) -b4_define_flag_if([error_verbose]) + +# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE) +# ---------------------------------------------------------- +m4_define([b4_parse_error_case], +[m4_case(b4_percent_define_get([[parse.error]]), $@)]) + +# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE) +# ------------------------------------------------------------------ +m4_define([b4_parse_error_bmatch], +[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)]) + + # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) # ---------------------------------------------- diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c index bd506bea..39b56a65 100644 --- a/data/skeletons/glr.c +++ b/data/skeletons/glr.c @@ -607,13 +607,12 @@ yyMemoryExhausted (yyGLRStack* yystackp) YYLONGJMP (yystackp->yyexception_buffer, 2); } -#if ]b4_error_verbose_if([[1]], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag])[ +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ /* The user-facing name of the symbol whose (internal) number is YYSYMBOL. No bounds checking. */ static const char *yysymbol_name (yySymbol yysymbol) YY_ATTRIBUTE_UNUSED; -]m4_bmatch(b4_percent_define_get([[parse.error]]), - [simple\|verbose], +]b4_parse_error_bmatch([simple\|verbose], [[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index 9b1a5124..8570f845 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -284,8 +284,7 @@ m4_define([b4_shared_declarations], // Tables. ]b4_parser_tables_declare[ -]m4_case(b4_percent_define_get([[parse.error]]), - [verbose], [[ +]b4_parse_error_case([verbose], [[ /// Convert the symbol name \a n to a form suitable for a diagnostic. static std::string yytnamerr_ (const char *n); @@ -560,7 +559,7 @@ m4_if(b4_prefix, [yy], [], #define YYERROR goto yyerrorlab #define YYRECOVERING() (!!yyerrstatus_) -]b4_namespace_open[]b4_error_verbose_if([[ +]b4_namespace_open[]b4_parse_error_case([verbose], [[ /* Return YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is @@ -1311,10 +1310,10 @@ b4_dollar_popdef])[]dnl // Generate an error message. std::string - ]b4_parser_class[::yysyntax_error_ (]dnl -b4_error_verbose_if([state_type yystate, const symbol_type& yyla], - [state_type, const symbol_type&])[) const - {]b4_error_verbose_if([[ +]b4_parser_class[::yysyntax_error_ (]b4_parse_error_case([verbose], + [state_type yystate, const symbol_type& yyla], + [state_type, const symbol_type&])[) const + {]b4_parse_error_case([verbose], [[ // Number of reported tokens (one for the "unexpected", one per // "expected"). std::ptrdiff_t yycount = 0; diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d index cb1dc4ca..75fd252b 100644 --- a/data/skeletons/lalr1.d +++ b/data/skeletons/lalr1.d @@ -679,7 +679,7 @@ m4_popdef([b4_at_dollar])])dnl // Generate an error message. private final string yysyntax_error (int yystate, int tok) - {]b4_error_verbose_if([[ + {]b4_parse_error_case([verbose], [[ /* There are many possibilities here to consider: - Assume YYFAIL is not used. It's too flawed to consider. See diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index a7c39165..0662def4 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -429,7 +429,7 @@ typedef int yy_state_fast_t; ]], [[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ -#if ]b4_lac_if([[1]], [b4_error_verbose_if([[1]], [[!defined yyoverflow]])])[ +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ /* The parser invokes alloca or malloc; define the necessary symbols. */]dnl b4_push_if([], [b4_lac_if([], [[ @@ -496,7 +496,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif]b4_lac_if([[ # define YYCOPY_NEEDED 1]])[ -#endif]b4_lac_if([], [b4_error_verbose_if([], [[/* !defined yyoverflow */]])])[ +#endif]b4_lac_if([], [b4_parse_error_case([simple], [[/* !defined yyoverflow */]])])[ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -602,7 +602,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ #endif -#if ]b4_error_verbose_if([[1]], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag])[ +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ /* The user-facing name of the symbol whose (internal) number is YYSYMBOL. No bounds checking. */ static const char *yysymbol_name (int yysymbol) YY_ATTRIBUTE_UNUSED; @@ -2010,7 +2010,7 @@ yyabortlab: goto yyreturn; -#if ]b4_lac_if([[1]], [b4_error_verbose_if([[1]], [[!defined yyoverflow]])])[ +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/