[PATCH 3/7] tests: factor the access to token kinds

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
* tests/local.at (AT_BISON_OPTION_PUSHDEFS): Define AT_TOKEN.
(AT_BISON_OPTION_POPDEFS): Undefine it.
* tests/actions.at, tests/c++.at, tests/calc.at: Use AT_TOKEN.
---
 tests/actions.at |  5 +----
 tests/c++.at     | 12 ++++++------
 tests/calc.at    |  6 +++---
 tests/local.at   |  6 ++++++
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/tests/actions.at b/tests/actions.at
index 3978ae8f..5554afea 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -1827,10 +1827,7 @@ float: UNTYPED INT
 };
 %%
 ]AT_YYERROR_DEFINE[
-]AT_YYLEX_DEFINE(AT_CXX_IF([[{yy::parser::token::UNTYPED,
-                                 yy::parser::token::INT,
-                                  EOF}]],
-                               [[{UNTYPED, INT, EOF}]]),
+]AT_YYLEX_DEFINE([[{]AT_TOKEN([UNTYPED])[, ]AT_TOKEN([INT])[, EOF}]],
                  [AT_VAL.ival = toknum * 10;
                   AT_VAL.fval = YY_CAST (float, toknum) / 10.0f;])[
 ]AT_MAIN_DEFINE[
diff --git a/tests/c++.at b/tests/c++.at
index 2a3a8ca2..52ff8287 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -445,13 +445,13 @@ namespace yy
         return parser::make_END_OF_FILE (]AT_LOCATION_IF([location ()])[);]],
 [AT_LOCATION_IF([
         *llocp = location ();])[
-        return parser::token::END_OF_FILE;]])[
+        return ]AT_TOKEN([END_OF_FILE])[;]])[
 
       case ',':]AT_TOKEN_CTOR_IF([[
         return parser::make_COMMA (]AT_LOCATION_IF([location ()])[);]],
 [AT_LOCATION_IF([
         *llocp = location ();])[
-        return parser::token::COMMA;]])[
+        return ]AT_TOKEN([COMMA])[;]])[
 
       default:
         stage = stage - '0';
@@ -460,14 +460,14 @@ namespace yy
            return parser::make_NUMBER (stage]AT_LOCATION_IF([, location ()])[);]], [[
            lvalp->BUILD (int, stage);]AT_LOCATION_IF([
            *llocp = location ();])[
-           return parser::token::NUMBER;]])[
+           return ]AT_TOKEN(NUMBER)[;]])[
          }
        else
          {]AT_TOKEN_CTOR_IF([[
            return parser::make_TEXT (to_string (stage)]AT_LOCATION_IF([, location ()])[);]], [[
            lvalp->BUILD (string, to_string (stage));]AT_LOCATION_IF([
            *llocp = location ();])[
-           return parser::token::TEXT;]])[
+           return ]AT_TOKEN([TEXT])[;]])[
          }
     }
   }
@@ -1369,7 +1369,7 @@ m4_popdef([AT_TEST])
 
 AT_SETUP([[C++ GLR parser identifier shadowing]])
 
-AT_BISON_OPTION_PUSHDEFS
+AT_BISON_OPTION_PUSHDEFS([%skeleton "glr.cc"])
 AT_DATA_GRAMMAR([input.yy], [
 %skeleton "glr.cc"
 
@@ -1396,7 +1396,7 @@ int yylex (yy::parser::semantic_type *lvalp)
   // bug with a macro that erroneously expanded this identifier to
   // yystackp->yyval.
   YYUSE (lvalp);
-  return yy::parser::token::ZERO;
+  return ]AT_TOKEN([ZERO])[;
 }
 
 void yy::parser::error (std::string const&)
diff --git a/tests/calc.at b/tests/calc.at
index f109342d..c11ab5c3 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -241,12 +241,12 @@ read_integer (]AT_YYLEX_FORMALS[)
     {
       unget_char (]AT_YYLEX_PRE_ARGS[ c);
       ]AT_VAL[.]AT_VALUE_UNION_IF([NUM], [ival])[ = read_integer (]AT_YYLEX_ARGS[);
-      return ]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[NUM;
+      return ]AT_TOKEN([NUM])[;
     }
 
   /* Return end-of-file.  */
   if (c == EOF)
-    return ]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[CALC_EOF;
+    return ]AT_TOKEN([CALC_EOF])[;
 
   /* An explicit error raised by the scanner. */
   if (c == '#')
@@ -254,7 +254,7 @@ read_integer (]AT_YYLEX_FORMALS[)
       fprintf (stderr, "%d.%d: ",
                AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);])[
       fputs ("syntax error: invalid character: '#'\n", stderr);
-      return ]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[]AT_API_PREFIX[error;
+      return ]AT_TOKEN(AT_API_PREFIX[][error])[;
     }
 
   /* Return single chars. */
diff --git a/tests/local.at b/tests/local.at
index 4ef48c37..e4242b39 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -355,6 +355,11 @@ m4_pushdef([AT_PURE_LEX_IF],
 m4_pushdef([AT_TOKEN_TRANSLATE_IF],
 [AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])])
 
+m4_pushdef([AT_TOKEN],
+           [AT_CXX_IF([AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[$1]],
+                      [AT_TOKEN_PREFIX[$1]])])
+
+
 m4_pushdef([AT_YYSTYPE],
 [AT_CXX_IF([AT_NAMESPACE[::parser::semantic_type]],
                [AT_API_PREFIX[STYPE]])])
@@ -425,6 +430,7 @@ m4_popdef([AT_YYLTYPE])
 m4_popdef([AT_YYSTYPE])
 m4_popdef([AT_VAL])
 m4_popdef([AT_LOC])
+m4_popdef([AT_TOKEN])
 m4_popdef([AT_TOKEN_TRANSLATE_IF])
 m4_popdef([AT_PURE_LEX_IF])
 m4_popdef([AT_YYERROR_SEES_LOC_IF])
-- 
2.29.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.