api.token.prefix: use code values

* data/bison.m4: Remove useless (and incorrect: m4_* instead of b4_*)
default assignment to api.token.prefix.
Check that api.token.prefix is assigned code.
* tests/input.at (%define code variables): New test.
* NEWS, doc/bison.texi, tests/c++.at, tests/calc.at,
* tests/java.at, tests/local.at: Adjust to use braces.
This commit is contained in:
Akim Demaille
2013-04-11 15:43:26 +02:00
parent 75ae829984
commit 630a021850
9 changed files with 74 additions and 24 deletions

26
NEWS
View File

@@ -256,6 +256,23 @@ GNU Bison NEWS
%param {arg1_type *arg1} {arg2_type *arg2}
** Types of values for %define variables
Bison used to make no difference between '%define foo bar' and '%define
foo "bar"'. The former is now called a 'keyword value', and the latter a
'string value'. A third kind was added: 'code values', such as '%define
foo {bar}'.
Keyword variables are used for fixed value sets, e.g.,
%define lr.type lalr
Code variables are used for value in the target language, e.g.,
%define api.value.type {struct semantic_type}
String variables are used remaining cases, e.g. file names.
** Variable api.token.prefix
The variable api.token.prefix changes the way tokens are identified in
@@ -263,7 +280,7 @@ GNU Bison NEWS
with identifiers in the target language. For instance
%token FILE for ERROR
%define api.token.prefix "TOK_"
%define api.token.prefix {TOK_}
%%
start: FILE for ERROR;
@@ -294,8 +311,9 @@ GNU Bison NEWS
yylval.ival = 42; return INT;
yylval.sval = "42"; return STRING;
The %define variable api.value.type supports several special values. The
keyword value 'union' means that the user provides genuine types, not
The %define variable api.value.type supports both keyword and code values.
The 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).
@@ -316,7 +334,7 @@ GNU Bison NEWS
%token <int> INT "integer"
%token <std::string> STRING "string"
Values between braces denote user defined types. This is where YYSTYPE
Code values (in braces) denote user defined types. This is where YYSTYPE
used to be used.
%code requires

View File

@@ -912,10 +912,6 @@ m4_define([b4_percent_code_ifdef],
## Common variables. ##
## ------------------ ##
# Default values for %define.
# ---------------------------
# If the api.token.prefix, it is empty.
m4_percent_define_default([[api.token.prefix]], [[]])
# b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
@@ -1007,6 +1003,15 @@ b4_percent_define_ifdef([api.prefix],
[%name-prefix],
[%define api.prefix])])])
# api.token.prefix={...}
# Make it a warning for those who used betas of Bison 3.0.
b4_percent_define_ifdef([api.token.prefix],
[m4_if(b4_percent_define_get_kind([[api.token.prefix]]), [code], [],
[b4_error([deprecated],
b4_percent_define_get_loc([api.token.prefix]),
[[%%define variable '%s' requires '{...}' values]],
[api.token.prefix])])])
# api.value.type >< %union.
b4_percent_define_ifdef([api.value.type],
[m4_ifdef([b4_union_members],

View File

@@ -3787,7 +3787,7 @@ return ID;
If the @code{%define} variable @code{api.token.prefix} is defined
(@pxref{%define Summary,,api.token.prefix}), then it is also used to prefix
the union member names. For instance, with @samp{%define api.token.prefix
TOK_}:
@{TOK_@}}:
@example
/* For an "integer". */
@@ -5884,7 +5884,7 @@ introduced in Bison 2.8
@c ================================================== api.token.prefix
@deffn Directive {%define api.token.prefix} @var{prefix}
@deffn Directive {%define api.token.prefix} @{@var{prefix}@}
@itemize
@item Languages(s): all
@@ -5895,7 +5895,7 @@ target language. For instance
@example
%token FILE for ERROR
%define api.token.prefix "TOK_"
%define api.token.prefix @{TOK_@}
%%
start: FILE for ERROR;
@end example
@@ -5922,7 +5922,7 @@ letters, underscores, and ---not at the beginning--- digits).
@item Default Value:
empty
@item History:
introduced in Bison 2.8
introduced in Bison 3.0
@end itemize
@end deffn
@c api.token.prefix
@@ -10917,7 +10917,7 @@ also pass the @var{location}.
For instance, given the following declarations:
@example
%define api.token.prefix "TOK_"
%define api.token.prefix @{TOK_@}
%token <std::string> IDENTIFIER;
%token <int> INTEGER;
%token COLON;
@@ -11243,7 +11243,7 @@ tokens with @code{TOK_} (@pxref{%define Summary,,api.token.prefix}).
@comment file: calc++-parser.yy
@example
%define api.token.prefix "TOK_"
%define api.token.prefix @{TOK_@}
%token
END 0 "end of file"
ASSIGN ":="

View File

@@ -83,7 +83,7 @@ static void fail_for_invalid_at (char const *at);
"@output(" at_init (&argc, argv, &at_ptr, &at_output);
/* This pattern must not match more than the previous @ patterns. */
@[^@{}'(\n]* fail_for_invalid_at (yytext);
@[^@{}\'(\n]* fail_for_invalid_at (yytext);
\n out_lineno++; ECHO;
[^@\n]+ ECHO;
@@ -183,6 +183,8 @@ flag (const char *arg)
/* compare with values issued from b4_error */
if (STREQ (arg, "complain"))
return complaint;
else if (STREQ (arg, "deprecated"))
return Wdeprecated;
else if (STREQ (arg, "fatal"))
return fatal;
else if (STREQ (arg, "note"))

View File

@@ -325,8 +325,8 @@ AT_TEST([%define parse.assert])
AT_TEST([%locations %define parse.assert])
AT_TEST([[%define parse.assert %code {\n#define TWO_STAGE_BUILD\n}]])
AT_TEST([[%define parse.assert %define api.token.constructor]])
AT_TEST([[%define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
AT_TEST([[%locations %define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
AT_TEST([[%define parse.assert %define api.token.constructor %define api.token.prefix {TOK_}]])
AT_TEST([[%locations %define parse.assert %define api.token.constructor %define api.token.prefix {TOK_}]])
m4_popdef([AT_TEST])

View File

@@ -608,7 +608,7 @@ AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %locations]
AT_CHECK_CALC_LALR([%define parse.error verbose %locations])
AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
AT_CHECK_CALC_LALR([%debug])
AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
@@ -651,7 +651,7 @@ AT_CHECK_CALC_GLR([%define parse.error verbose %locations %defines %name-prefix
AT_CHECK_CALC_GLR([%debug])
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %define api.prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %define api.prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
@@ -684,7 +684,7 @@ AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %define api.prefi
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%defines %locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
@@ -719,7 +719,7 @@ AT_CHECK_CALC_GLR_CC([%debug])
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])

View File

@@ -1434,6 +1434,31 @@ AT_BISON_CHECK([[Input.y]], [1], [],
AT_CLEANUP
## ------------------------ ##
## %define code variables. ##
## ------------------------ ##
AT_SETUP([["%define" code variables]])
m4_pushdef([AT_TEST],
[AT_DATA([input.y],
[[%define api.token.prefix ]$1[
%%
start: %empty;
]])
AT_BISON_CHECK([[input.y]], [0], [],
[[input.y:1.9-24: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated]
]])
])
AT_TEST(["abc"])
AT_TEST([abcde])
m4_popdef([AT_TEST])
AT_CLEANUP
## ------------------------ ##
## %define enum variables. ##
## ------------------------ ##

View File

@@ -461,7 +461,7 @@ AT_CHECK_JAVA_GREP([[class YYParser]])
AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
AT_CHECK_JAVA_GREP([[class PrefixParser]])
AT_CHECK_JAVA_MINIMAL([[%define api.token.prefix "TOK_"]])
AT_CHECK_JAVA_MINIMAL([[%define api.token.prefix {TOK_}]])
AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]])

View File

@@ -190,8 +190,8 @@ m4_pushdef([AT_NAME_PREFIX],
m4_pushdef([AT_TOKEN_CTOR_IF],
[m4_bmatch([$3], [%define api\.token\.constructor], [$1], [$2])])
m4_pushdef([AT_TOKEN_PREFIX],
[m4_bmatch([$3], [%define api\.token\.prefix ".*"],
[m4_bregexp([$3], [%define api\.token\.prefix "\(.*\)"], [\1])])])
[m4_bmatch([$3], [%define api\.token\.prefix {.*}],
[m4_bregexp([$3], [%define api\.token\.prefix {\(.*\)}], [\1])])])
m4_pushdef([AT_VARIANT_IF],
[m4_bmatch([$3], [%define api\.value\.type "?variant"?], [$1], [$2])])
m4_pushdef([AT_API_prefix],