%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
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;
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).
%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
## 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])
[%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],
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". */
@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
@example
%token FILE for ERROR
-%define api.token.prefix "TOK_"
+%define api.token.prefix @{TOK_@}
%%
start: FILE for ERROR;
@end example
@item Default Value:
empty
@item History:
-introduced in Bison 2.8
+introduced in Bison 3.0
@end itemize
@end deffn
@c api.token.prefix
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;
@comment file: calc++-parser.yy
@example
-%define api.token.prefix "TOK_"
+%define api.token.prefix @{TOK_@}
%token
END 0 "end of file"
ASSIGN ":="
"@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;
/* 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"))
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])
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])
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])
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}])
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}])
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. ##
## ------------------------ ##
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"]])
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],