From 07e65a77aa7b9ae259f6fcf16e8f322f4814ee39 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 13 Apr 2013 09:30:05 +0200 Subject: [PATCH] muscle: factor the kind check in M4 * data/bison.m4 (b4_percent_define_check_kind): New. Use it to check api.token.prefix. * data/c++.m4: Check the kind of api.namespace. * doc/bison.texi: Update a reference to former 'namespace' variable. * tests/input.at ("%define" code variables): Check api.namespace. --- data/bison.m4 | 22 ++++++++++++++++------ data/c++.m4 | 6 ++++++ doc/bison.texi | 2 +- tests/input.at | 18 +++++++++++------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/data/bison.m4 b/data/bison.m4 index e96e1830..904bcf2b 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -847,6 +847,21 @@ m4_define([b4_percent_define_if_define], b4_percent_define_if_define_([$1], [$2], $[1], $[2])]) +# b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) +# --------------------------------------------------------------------- +m4_define([b4_percent_define_check_kind], +[b4_percent_define_ifdef_([$1], + [m4_if(b4_percent_define_get_kind([[$1]]), [$2], [], + [b4_error([m4_default([$3], [complain])], + b4_percent_define_get_loc([$1]), + [m4_case([$2], + [code], [[%%define variable '%s' requires '{...}' values]], + [keyword], [[%%define variable '%s' requires '...' values]], + [string], [[%%define variable '%s' requires '"..."' values]])], + [$1])])])dnl +]) + + # b4_percent_define_check_values(VALUES) # -------------------------------------- # Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly @@ -1018,12 +1033,7 @@ b4_percent_define_ifdef([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])])]) +b4_percent_define_check_kind([api.token.prefix], [code], [deprecated]) # api.value.type >< %union. b4_percent_define_ifdef([api.value.type], diff --git a/data/c++.m4 b/data/c++.m4 index e2c20fbd..2d686b6b 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -25,6 +25,11 @@ m4_include(b4_pkgdatadir/[c.m4]) m4_define([b4_comment], [b4_comment_([$1], [$2// ], [$2// ])]) +## -------- ## +## Checks. ## +## -------- ## + +b4_percent_define_check_kind([api.namespace], [code], [deprecated]) ## ---------------- ## ## Default values. ## @@ -38,6 +43,7 @@ b4_percent_define_default([[parser_class_name]], [[parser]]) # b4_percent_define_default([[api.location.type]], [[location]]) b4_percent_define_default([[filename_type]], [[std::string]]) +# Make it a warning for those who used betas of Bison 3.0. b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix])) b4_percent_define_default([[global_tokens_and_yystype]], [[false]]) diff --git a/doc/bison.texi b/doc/bison.texi index 58a14f8b..c36e2e27 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -12758,7 +12758,7 @@ push parser, @code{yypush_parse}, @code{yypull_parse}, @code{yypstate}, @code{yypstate_new} and @code{yypstate_delete} will also be renamed. For example, if you use @samp{%name-prefix "c_"}, the names become @code{c_parse}, @code{c_lex}, and so on. For C++ parsers, see the -@code{%define namespace} documentation in this section. +@code{%define api.namespace} documentation in this section. @end deffn diff --git a/tests/input.at b/tests/input.at index 3dfed32d..d70eaad4 100644 --- a/tests/input.at +++ b/tests/input.at @@ -1441,19 +1441,23 @@ AT_CLEANUP AT_SETUP([["%define" code variables]]) m4_pushdef([AT_TEST], -[AT_DATA([input.y], -[[%define api.token.prefix ]$1[ +[AT_DATA([input.yy], +[[%skeleton "lalr1.cc" +%define api.namespace ]$1[quux]$2[ +%define api.token.prefix ]$1[quux]$2[ +%token TOK // Otherwise api.token.prefix is unused. %% -start: %empty; +start: TOK; ]]) -AT_BISON_CHECK([[input.y]], [0], [], -[[input.y:1.9-24: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated] +AT_BISON_CHECK([[input.yy]], [0], [], +[[input.yy:3.9-24: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated] +input.yy:2.9-21: warning: %define variable 'api.namespace' requires '{...}' values [-Wdeprecated] ]]) ]) -AT_TEST(["abc"]) -AT_TEST([abcde]) +AT_TEST([], []) +AT_TEST(["], ["]) m4_popdef([AT_TEST]) AT_CLEANUP -- 2.45.2