mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13:04 +00:00
c++: provide yy::parser::symbol_type::name
* data/skeletons/c++.m4 (yy::parser::basic_symbol::name): New. * data/skeletons/lalr1.cc (yy_print_): Use it. * doc/bison.texi: Document. * tests/c++.at: Check.
This commit is contained in:
4
NEWS
4
NEWS
@@ -8,6 +8,10 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
In C++, yy::parser::symbol_name is now a public member, as was intended.
|
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]
|
* Noteworthy changes in release 3.6 (2020-05-08) [stable]
|
||||||
|
|
||||||
** Backward incompatible changes
|
** Backward incompatible changes
|
||||||
|
|||||||
@@ -357,6 +357,29 @@ m4_define([b4_symbol_type_define],
|
|||||||
Base::clear ();
|
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).
|
/// Backward compatibility (Bison 3.6).
|
||||||
symbol_kind_type type_get () const YY_NOEXCEPT;
|
symbol_kind_type type_get () const YY_NOEXCEPT;
|
||||||
|
|
||||||
|
|||||||
@@ -256,8 +256,7 @@ m4_define([b4_shared_declarations],
|
|||||||
[verbose],
|
[verbose],
|
||||||
[[ /// The user-facing name of the symbol whose (internal) number is
|
[[ /// The user-facing name of the symbol whose (internal) number is
|
||||||
/// YYSYMBOL. No bounds checking.
|
/// YYSYMBOL. No bounds checking.
|
||||||
static std::string symbol_name (symbol_kind_type yysymbol);
|
static std::string symbol_name (symbol_kind_type yysymbol);]])[
|
||||||
]])[
|
|
||||||
|
|
||||||
]b4_token_constructor_define[
|
]b4_token_constructor_define[
|
||||||
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
||||||
@@ -822,7 +821,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
{
|
{
|
||||||
symbol_kind_type yykind = yysym.kind ();
|
symbol_kind_type yykind = yysym.kind ();
|
||||||
yyo << (yykind < YYNTOKENS ? "token" : "nterm")
|
yyo << (yykind < YYNTOKENS ? "token" : "nterm")
|
||||||
<< ' ' << symbol_name (yykind) << " ("]b4_locations_if([
|
<< ' ' << yysym.name () << " ("]b4_locations_if([
|
||||||
<< yysym.location << ": "])[;
|
<< yysym.location << ": "])[;
|
||||||
]b4_symbol_actions([printer])[
|
]b4_symbol_actions([printer])[
|
||||||
yyo << ')';
|
yyo << ')';
|
||||||
|
|||||||
@@ -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}
|
@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.
|
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
|
@end deftypemethod
|
||||||
|
|
||||||
A custom syntax error function looks as follows. This implementation is
|
A custom syntax error function looks as follows. This implementation is
|
||||||
@@ -12286,6 +12288,12 @@ applicable) location.
|
|||||||
The kind of this symbol.
|
The kind of this symbol.
|
||||||
@end deftypemethod
|
@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
|
@sp 1
|
||||||
|
|
||||||
For each token kind, Bison generates named constructors as follows.
|
For each token kind, Bison generates named constructors as follows.
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ int main()
|
|||||||
parser::symbol_type s = parser::make_INT (12);
|
parser::symbol_type s = parser::make_INT (12);
|
||||||
assert_eq (s.kind (), parser::symbol_kind::S_INT);
|
assert_eq (s.kind (), parser::symbol_kind::S_INT);
|
||||||
assert_eq (parser::symbol_name (s.kind ()), "\"int\"");
|
assert_eq (parser::symbol_name (s.kind ()), "\"int\"");
|
||||||
|
assert_eq (s.name (), "\"int\"");
|
||||||
assert_eq (s.value.as<int> (), 12);
|
assert_eq (s.value.as<int> (), 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user