api.value.type: use keyword/brace values

Suggested by Joel E. Denny.
http://lists.gnu.org/archive/html/bison-patches/2013-03/msg00016.html

* data/bison.m4 (b4_percent_define_get_kind): New.
(b4_variant_flag): Check that api.value.type is defined as the 'variant'
keyword value.
* data/c.m4 (_b4_value_type_setup_keyword): New.
(b4_value_type_setup): Use it to simplify reading.
Use b4_define_silent.
Decode api.value.type, including its type.
(b4_value_type_define): Likewise.
* data/c++.m4 (b4_value_type_declare): Adjust the decoding of api.value.type,
taking its kind into account.
* doc/bison.texi: Adjust all the examples to the new syntax.
* NEWS: Ditto.
* tests/types.at: Adjust
This commit is contained in:
Akim Demaille
2013-04-05 14:40:25 +02:00
parent 1fa19a7697
commit 435575cb5e
6 changed files with 105 additions and 51 deletions

18
NEWS
View File

@@ -295,11 +295,11 @@ GNU Bison NEWS
yylval.sval = "42"; return STRING;
The %define variable api.value.type supports several special values. The
value "union" means that the user provides genuine types, not union member
names such as "ival" and "sval" above (WARNING: will fail if
keyword value 'union' means that the user provides genuine types, not
union member names such as "ival" and "sval" above (WARNING: will fail if
-y/--yacc/%yacc is enabled).
%define api.value.type "union"
%define api.value.type union
%token <int> INT "integer"
%token <char *> STRING "string"
%printer { fprintf (yyo, "%d", $$); } <int>
@@ -309,15 +309,15 @@ GNU Bison NEWS
yylval.INT = 42; return INT;
yylval.STRING = "42"; return STRING;
The value "variant" is somewhat equivalent, but for C++ special provision
is made to allow classes to be used (more about this below).
The keyword value variant is somewhat equivalent, but for C++ special
provision is made to allow classes to be used (more about this below).
%define api.value.type "variant"
%define api.value.type variant
%token <int> INT "integer"
%token <std::string> STRING "string"
Any other name is a user type to use. This is where YYSTYPE used to be
used.
Values between braces denote user defined types. This is where YYSTYPE
used to be used.
%code requires
{
@@ -334,7 +334,7 @@ GNU Bison NEWS
} u;
};
}
%define api.value.type "struct my_value"
%define api.value.type {struct my_value}
%token <u.ival> INT "integer"
%token <u.sval> STRING "string"
%printer { fprintf (yyo, "%d", $$); } <u.ival>