From 630a021850386acaee461fccee27718577d0a799 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 11 Apr 2013 15:43:26 +0200 Subject: [PATCH] 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. --- NEWS | 26 ++++++++++++++++++++++---- data/bison.m4 | 13 +++++++++---- doc/bison.texi | 12 ++++++------ src/scan-skel.l | 4 +++- tests/c++.at | 4 ++-- tests/calc.at | 8 ++++---- tests/input.at | 25 +++++++++++++++++++++++++ tests/java.at | 2 +- tests/local.at | 4 ++-- 9 files changed, 74 insertions(+), 24 deletions(-) diff --git a/NEWS b/NEWS index cf118c15..5bc4d31e 100644 --- a/NEWS +++ b/NEWS @@ -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 "integer" %token 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 diff --git a/data/bison.m4 b/data/bison.m4 index 910cdf26..a5466aa9 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -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], diff --git a/doc/bison.texi b/doc/bison.texi index 72847a1e..58a14f8b 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -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 IDENTIFIER; %token 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 ":=" diff --git a/src/scan-skel.l b/src/scan-skel.l index 654491ef..f13ee813 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -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")) diff --git a/tests/c++.at b/tests/c++.at index 387d4878..d1d6975a 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -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]) diff --git a/tests/calc.at b/tests/calc.at index a14f2c21..eedfc897 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -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}]) diff --git a/tests/input.at b/tests/input.at index aec855d7..3dfed32d 100644 --- a/tests/input.at +++ b/tests/input.at @@ -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. ## ## ------------------------ ## diff --git a/tests/java.at b/tests/java.at index 7f77f283..3f729260 100644 --- a/tests/java.at +++ b/tests/java.at @@ -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"]]) diff --git a/tests/local.at b/tests/local.at index 46bbfeda..0428b6e8 100644 --- a/tests/local.at +++ b/tests/local.at @@ -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], -- 2.45.2