c++: give public access to the symbol kind

symbol_type::token () was removed: it returned the token kind of a
symbol.  To do that, one needs to convert from the symbol kind to the
token kind, which requires a table.

This broke some users' unit tests for scanners, see
https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html
https://lists.gnu.org/r/bug-bison/2020-03/msg00020.html
https://lists.gnu.org/r/help-bison/2020-04/msg00005.html

Instead of making this possible again, let's check the symbol's kind
instead.  So give proper access to a symbol's kind.

That feature existed, undocumented, as 'type_get()'.  Let's rename
this as 'kind()'.

* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc (type_get): Rename as...
(kind): This.
(type_get): Install a backward compatibility alias.
* doc/bison.texi (Complete Symbols): Document symbol_type and
symbol_type::kind.
This commit is contained in:
Akim Demaille
2020-04-17 08:51:18 +02:00
parent e86b14069d
commit d6ae95fb50
6 changed files with 67 additions and 35 deletions

16
NEWS
View File

@@ -73,8 +73,8 @@ GNU Bison NEWS
**** Token aliases internationalization
When the %define variable parse.error is set to `custom` or `detailed`,
one may use the _() annotation to specify which token aliases are to be
translated. For instance
one may specify which token aliases are to be translated using _(). For
instance
%token
PLUS "+"
@@ -163,6 +163,18 @@ GNU Bison NEWS
Contributed by Victor Morales Cayuela.
*** C++
The token and symbol kinds are yy::parser::token_kind_type and
yy::parser::symbol_kind_type.
The symbol_type::kind() member function allows to get the kind of a
symbol. This can be used to write unit tests for scanners, e.g.,
yy::parser::symbol_type t = make_NUMBER ("123");
assert (t.kind () == yy::parser::symbol_kind::S_NUMBER);
assert (t.value.as<int> () == 123);
** Documentation
*** User Manual