[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/9] muscle: factor the kind check in M4
From: |
Akim Demaille |
Subject: |
[PATCH 2/9] muscle: factor the kind check in M4 |
Date: |
Mon, 15 Apr 2013 10:58:21 +0200 |
* 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 e96e183..904bcf2 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 e2c20fb..2d686b6 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 58a14f8..c36e2e2 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
address@hidden namespace} documentation in this section.
address@hidden api.namespace} documentation in this section.
@end deffn
diff --git a/tests/input.at b/tests/input.at
index 3dfed32..d70eaad 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
--
1.8.2
- [PATCH 0/9] {master} check the kind of %define variable values, Akim Demaille, 2013/04/15
- [PATCH 4/9] muscle: factor the handling of used variables, Akim Demaille, 2013/04/15
- [PATCH 1/9] muscle: factor conditionals on defined %define variables, Akim Demaille, 2013/04/15
- [PATCH 7/9] muscle: minor refactoring, Akim Demaille, 2013/04/15
- [PATCH 5/9] muscle: factor the field retrieval, Akim Demaille, 2013/04/15
- [PATCH 8/9] muscle: let -D/-F support the three kinds of %define variable values, Akim Demaille, 2013/04/15
- [PATCH 2/9] muscle: factor the kind check in M4,
Akim Demaille <=
- [PATCH 6/9] muscle: minor simplification which uncovers a missing warning, Akim Demaille, 2013/04/15
- [PATCH 9/9] muscle: enforce definition syntax for keyword variables, Akim Demaille, 2013/04/15
- [PATCH 3/9] muscle: factor the computation of variable names, Akim Demaille, 2013/04/15