summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-02-19 20:37:29 +0100
committerAkim Demaille <akim.demaille@gmail.com>2019-02-21 17:46:11 +0100
commit7d6747cec98324891c736066f1e6475d09afb045 (patch)
treeead82036990873fbb00a29c42c40f71e77a06d6a /tests
parent420e7b03ec958ba1d037a133b2d7c82579658d42 (diff)
downloadbison-7d6747cec98324891c736066f1e6475d09afb045.tar.gz
tests: dispatch per lang on the definition of yylex
* tests/local.at (AT_YYLEX_DEFINE): Dispatch on the language. (AT_YYLEX_DEFINE(java)): New. * tests/conflicts.at, tests/java.at: Use it.
Diffstat (limited to 'tests')
-rw-r--r--tests/conflicts.at22
-rw-r--r--tests/java.at7
-rw-r--r--tests/local.at74
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 6c0990dd..f5957369 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