Merge branch maint

* maint:
  news: update
  maint: post-release administrivia
  version 3.6.1
  c++: style: reorder generated code
  c++: provide yy::parser::symbol_type::name
  c++: make parser::symbol_name public
  examples: beware of ~/.inputrc
  build: also provide lzip compressed tarballs
  style: minor fixes
  yacc.c: restore ansi-c compatibility
This commit is contained in:
Akim Demaille
2020-05-10 17:33:12 +02:00
11 changed files with 173 additions and 107 deletions

View File

@@ -1 +1 @@
3.6
3.6.1

14
NEWS
View File

@@ -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

View File

@@ -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;

View File

@@ -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)

View File

@@ -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];

View File

@@ -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.

View File

@@ -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`).
<!---
Local Variables:
fill-column: 76

View File

@@ -15,6 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Users may customize the behavior of readline, which might break our
# expected results.
INPUTRC=/dev/null
export INPUTRC
# Beware of portability issues of readline when not feeding it from a
# terminal.

View File

@@ -2705,7 +2705,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];

View File

@@ -109,11 +109,6 @@ AT_DATA_GRAMMAR([list.yy],
%define parse.assert
%debug
%code top
{
// Get access to stack_symbol_type for the tests.
# define private public
}
%code provides
{
]AT_YYLEX_DECLARE[
@@ -136,6 +131,14 @@ AT_DATA_GRAMMAR([list.yy],
%code requires { #include <vector> }
%code { int yylex (yy::parser::semantic_type* lvalp); }
// A hack which relies on internal hooks to check stack_symbol_type,
// which is private.
%code yy_bison_internal_hook {
public:
typedef stack_symbol_type yy_stack_symbol_type;
typedef stack_type yy_stack_type;
}
%%
exp: "int" { $$.push_back ($1); }
%%
@@ -157,6 +160,9 @@ int main()
// symbol_type: construction, accessor.
{
parser::symbol_type s = parser::make_INT (12);
assert_eq (s.kind (), parser::symbol_kind::S_INT);
assert_eq (parser::symbol_name (s.kind ()), "\"int\"");
assert_eq (s.name (), "\"int\"");
assert_eq (s.value.as<int> (), 12);
}
@@ -180,12 +186,13 @@ int main()
}
// stack_symbol_type: construction, accessor.
typedef parser::yy_stack_symbol_type stack_symbol_type;
{
#if 201103L <= YY_CPLUSPLUS
auto ss = parser::stack_symbol_type(1, parser::make_INT(123));
auto ss = stack_symbol_type (1, parser::make_INT(123));
#else
parser::symbol_type s = parser::make_INT (123);
parser::stack_symbol_type ss(1, s);
stack_symbol_type ss(1, s);
#endif
assert_eq (ss.value.as<int> (), 123);
}
@@ -194,17 +201,17 @@ int main()
// Sufficiently many so that it will be resized.
// Probably 3 times (starting at 200).
{
parser::stack_type st;
parser::yy_stack_type st;
const int mucho = 1700;
const int int_reduction_state = 1; // Read list.output to find it.
for (int i = 0; i < mucho; ++i)
{
#if 201103L <= YY_CPLUSPLUS
st.push(parser::stack_symbol_type{int_reduction_state,
parser::make_INT (i)});
st.push(stack_symbol_type{int_reduction_state,
parser::make_INT (i)});
#else
parser::symbol_type s = parser::make_INT (i);
parser::stack_symbol_type ss (int_reduction_state, s);
stack_symbol_type ss (int_reduction_state, s);
st.push (ss);
#endif
}

View File

@@ -500,7 +500,7 @@ m4_define([AT_DATA_SOURCE_PROLOGUE],
# The prologue that should be included in any grammar whose parser is
# meant to be compiled.
m4_define([AT_DATA_GRAMMAR_PROLOGUE],
[[%code top {
[[%code top { /* -*- ]AT_LANG[ -*- */
]AT_DATA_SOURCE_PROLOGUE[]dnl
[}
]])