diff --git a/.prev-version b/.prev-version index d70c8f8d..9575d51b 100644 --- a/.prev-version +++ b/.prev-version @@ -1 +1 @@ -3.6 +3.6.1 diff --git a/NEWS b/NEWS index 21937f12..6420a763 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,20 @@ GNU Bison NEWS * Noteworthy changes in release ?.? (????-??-??) [?] +* Noteworthy changes in release 3.6.1 (2020-05-10) [stable] + +** Bug fixes + + Restored ANSI-C compliance in yacc.c. + + GNU readline portability issues. + + In C++, yy::parser::symbol_name is now a public member, as was intended. + +** New features + + In C++, yy::parser::symbol_type now has a public name() member function. + * Noteworthy changes in release 3.6 (2020-05-08) [stable] ** Backward incompatible changes diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index 7ce45078..b862bf3c 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -357,6 +357,29 @@ m4_define([b4_symbol_type_define], Base::clear (); } +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of this symbol. + std::string name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]])[ + /// Backward compatibility (Bison 3.6). symbol_kind_type type_get () const YY_NOEXCEPT; diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index e6da4d81..204b82d9 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -241,6 +241,23 @@ m4_define([b4_shared_declarations], /// Report a syntax error. void error (const syntax_error& err); +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ + ]b4_token_constructor_define[ ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ class context @@ -317,26 +334,14 @@ m4_define([b4_shared_declarations], static symbol_kind_type yytranslate_ (int t); ]b4_parse_error_bmatch( -[custom\|detailed], -[[ /// The user-facing name of the symbol whose (internal) number is - /// YYSYMBOL. No bounds checking. - static const char *symbol_name (symbol_kind_type yysymbol);]], [simple], [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ - /// The user-facing name of the symbol whose (internal) number is - /// YYSYMBOL. No bounds checking. - static const char *symbol_name (symbol_kind_type yysymbol); - /// For a symbol, its name in clear. static const char* const yytname_[]; #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ ]], [verbose], -[[ /// The user-facing name of the symbol whose (internal) number is - /// YYSYMBOL. No bounds checking. - static std::string symbol_name (symbol_kind_type yysymbol); - - /// Convert the symbol name \a n to a form suitable for a diagnostic. +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. static std::string yytnamerr_ (const char *yystr); /// For a symbol, its name in clear. @@ -474,6 +479,7 @@ m4_define([b4_shared_declarations], }; ]b4_parse_param_vars[ +]b4_percent_code_get([[yy_bison_internal_hook]])[ }; ]b4_token_ctor_if([b4_yytranslate_define([$1])[ @@ -607,83 +613,6 @@ m4_if(b4_prefix, [yy], [], #define YYRECOVERING() (!!yyerrstatus_) ]b4_namespace_open[ -]b4_parse_error_bmatch([custom\|detailed], -[[ const char * - ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) - { - static const char *const yy_sname[] = - { - ]b4_symbol_names[ - };]b4_has_translations_if([[ - /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is - internationalizable. */ - static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = - { - ]b4_translatable[ - }; - return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] - ? _(yy_sname[yysymbol]) - : yy_sname[yysymbol]);]], [[ - return yy_sname[yysymbol];]])[ - } -]], -[simple], -[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ - const char * - ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) - { - return yytname_[yysymbol]; - } -#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ -]], -[verbose], -[[ /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - ]b4_parser_class[::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - - std::string - ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) - { - return yytnamerr_ (yytname_[yysymbol]); - } -]])[ - /// Build a parser object. ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) #if ]b4_api_PREFIX[DEBUG @@ -815,7 +744,7 @@ m4_if(b4_prefix, [yy], [], { symbol_kind_type yykind = yysym.kind (); yyo << (yykind < YYNTOKENS ? "token" : "nterm") - << ' ' << symbol_name (yykind) << " ("]b4_locations_if([ + << ' ' << yysym.name () << " ("]b4_locations_if([ << yysym.location << ": "])[; ]b4_symbol_actions([printer])[ yyo << ')'; @@ -1267,8 +1196,86 @@ b4_dollar_popdef])[]dnl { error (]b4_join(b4_locations_if([yyexc.location]), [[yyexc.what ()]])[); - }]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + } +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_ (yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ // ]b4_parser_class[::context. ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla) : yyparser_ (yyparser) diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index a790f6fa..a9f15c8d 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -1979,7 +1979,7 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ - // Pop stack until we find a state that shifts the error token. + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; diff --git a/doc/bison.texi b/doc/bison.texi index 7e51633b..726cbf22 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -12154,6 +12154,8 @@ values, which is always less than @code{YYNTOKENS}. @deftypemethod {parser} {const char *} symbol_name (@code{symbol_kind_t} @var{symbol}) @code{const} The name of the symbol whose kind is @var{symbol}, possibly translated. + +Returns a @code{std::string} when @code{parse.error} is @code{verbose}. @end deftypemethod A custom syntax error function looks as follows. This implementation is @@ -12286,6 +12288,12 @@ applicable) location. The kind of this symbol. @end deftypemethod +@deftypemethod {symbol_type} {const char *} name () @code{const} +The name of the kind of this symbol. + +Returns a @code{std::string} when @code{parse.error} is @code{verbose}. +@end deftypemethod + @sp 1 For each token kind, Bison generates named constructors as follows. diff --git a/examples/c/bistromathic/README.md b/examples/c/bistromathic/README.md index 05f1b7ed..6b66299e 100644 --- a/examples/c/bistromathic/README.md +++ b/examples/c/bistromathic/README.md @@ -14,6 +14,9 @@ This example demonstrates best practices when using Bison. - It supports debug traces with semantic values. - It uses named references instead of the traditional $1, $2, etc. +To customize the interaction with bistromathic, see the GNU Readline user +manual (see `info rluserman`). +