[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/8] tests: dispatch per lang on the definition of yylex
From: |
Akim Demaille |
Subject: |
[PATCH 3/8] tests: dispatch per lang on the definition of yylex |
Date: |
Thu, 21 Feb 2019 07:09:41 +0100 |
* tests/local.at (AT_YYLEX_DEFINE): Dispatch on the language.
(AT_YYLEX_DEFINE(java)): New.
* tests/conflicts.at, tests/java.at: Use it.
---
tests/conflicts.at | 22 ++------------
tests/java.at | 7 ++---
tests/local.at | 74 +++++++++++++++++++++++++++++++++-------------
3 files changed, 58 insertions(+), 45 deletions(-)
diff --git a/tests/conflicts.at b/tests/conflicts.at
index 5ae1e02b..02f0ea1e 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -437,26 +437,8 @@ AT_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
]$2[
]AT_JAVA_IF([[%code lexer {
-
- /*--------.
- | yylex. |
- `--------*/
-
- public String input = "]$3[";
- public int index = 0;
- public int yylex ()
- {
- if (index < input.length ())
- return input.charAt (index++);
- else
- return 0;
- }
- public Object getLVal ()
- {
- return new Integer(1);
- }
-
-]AT_YYERROR_DEFINE[
+ ]AT_YYLEX_DEFINE([$3], [[return new Integer(1)]])[
+ ]AT_YYERROR_DEFINE[
};
%%
]], [[
diff --git a/tests/java.at b/tests/java.at
index fe9ae6dd..0fe46c60 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -154,14 +154,11 @@ AT_LOCATION_IF([[
else
return st.ttype;
}
-
-
]AT_LEXPARAM_IF([[
};
%%]], [[
-}]])
+}]])[
-[
class Position {
public int line;
public int token;
@@ -198,8 +195,8 @@ class Position {
return token;
}
}
-
]])
+
AT_BISON_OPTION_POPDEFS
])# _AT_DATA_JAVA_CALC_Y
diff --git a/tests/local.at b/tests/local.at
index e9c1ada1..552298ad 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -427,25 +427,10 @@ m4_define([AT_YYLEX_DECLARE],
[static AT_YYLEX_DECLARE_EXTERN[]dnl
])
-m4_define([AT_YYLEX_DEFINE],
-[[#include <assert.h>
-static
-]AT_YYLEX_PROTOTYPE[
-{
- ]m4_bmatch([$1], [^\(".*"\)?$],
- [[static char const input[] = ]m4_default([$1], [""])],
- [[static int const input[] = ]$1])[;
- static size_t toknum = 0;
- int res;
- ]AT_USE_LEX_ARGS[
- assert (toknum < sizeof input / sizeof input[0]);
- res = input[toknum++];
- ]$2[;]AT_TOKEN_CTOR_IF([], [[
- ]AT_LOCATION_IF([[
- ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
- ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = ]AT_CXX_IF([(unsigned )],
[(int)])[toknum;]])[
- return res;]])[
-}]])
+
+# AT_YYLEX_DEFINE([INPUT], [ACTION])
+m4_define([AT_YYLEX_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
+
# AT_YYERROR_FORMALS
# AT_YYERROR_PROTOTYPE
@@ -537,6 +522,27 @@ AT_YYERROR_SEES_LOC_IF([[
}]])
+m4_define([AT_YYLEX_DEFINE(c)],
+[[#include <assert.h>
+static
+]AT_YYLEX_PROTOTYPE[
+{
+ ]m4_bmatch([$1], [^\(".*"\)?$],
+ [[static char const input[] = ]m4_default([$1], [""])],
+ [[static int const input[] = ]$1])[;
+ static size_t toknum = 0;
+ int res;
+ ]AT_USE_LEX_ARGS[
+ assert (toknum < sizeof input / sizeof input[0]);
+ res = input[toknum++];
+ ]$2[;]AT_TOKEN_CTOR_IF([], [[
+ ]AT_LOCATION_IF([[
+ ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
+ ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = ]AT_CXX_IF([(unsigned )],
[(int)])[toknum;]])[
+ return res;]])[
+}]])
+
+
m4_define([AT_MAIN_DEFINE(c)],
[[#include <stdlib.h> /* getenv. */
#include <string.h> /* strcmp. */
@@ -573,6 +579,12 @@ void
}]])
+# AT_YYERROR_DEFINE(c++)([INPUT], [ACTION])
+# -----------------------------------------
+# Same as in C.
+m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])
+
+
m4_define([AT_MAIN_DEFINE(c++)],
[[#include <cstdlib> // getenv.
#include <cstring> // strcmp.
@@ -626,7 +638,29 @@ m4_define([AT_YYERROR_DEFINE(java)],
{
System.err.println (s);
}
-]])])
+]])
+])
+
+m4_define([AT_YYLEX_DEFINE(java)],
+[[
+ /*--------.
+ | yylex. |
+ `--------*/
+
+ public String input = "]$1[";
+ public int index = 0;
+ public int yylex ()
+ {
+ if (index < input.length ())
+ return input.charAt (index++);
+ else
+ return 0;
+ }
+ public Object getLVal ()
+ {
+ ]$2[;
+ }
+]])
m4_define([AT_MAIN_DEFINE(java)],
[[class input
--
2.20.1
- [PATCH 0/8] Clean up the tests, Akim Demaille, 2019/02/21
- [PATCH 1/8] tests: formatting changes, Akim Demaille, 2019/02/21
- [PATCH 5/8] tests: java: factor the definition of Position, Akim Demaille, 2019/02/21
- [PATCH 2/8] tests: de-duplicate, Akim Demaille, 2019/02/21
- [PATCH 8/8] tests: factor the execution of Java parsers, Akim Demaille, 2019/02/21
- [PATCH 3/8] tests: dispatch per lang on the definition of yylex,
Akim Demaille <=
- [PATCH 7/8] tests: fix a Java tests, Akim Demaille, 2019/02/21
- [PATCH 6/8] tests: simplify AT_PARSER_CHECK usage, Akim Demaille, 2019/02/21
- [PATCH 4/8] tests: dispatch per lang on AT_DATA_GRAMMAR, Akim Demaille, 2019/02/21