mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 18:53:04 +00:00
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.
This commit is contained in:
@@ -437,26 +437,8 @@ AT_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
|||||||
]$2[
|
]$2[
|
||||||
|
|
||||||
]AT_JAVA_IF([[%code lexer {
|
]AT_JAVA_IF([[%code lexer {
|
||||||
|
]AT_YYLEX_DEFINE([$3], [[return new Integer(1)]])[
|
||||||
/*--------.
|
]AT_YYERROR_DEFINE[
|
||||||
| 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[
|
|
||||||
};
|
};
|
||||||
%%
|
%%
|
||||||
]], [[
|
]], [[
|
||||||
|
|||||||
@@ -154,14 +154,11 @@ AT_LOCATION_IF([[
|
|||||||
else
|
else
|
||||||
return st.ttype;
|
return st.ttype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
]AT_LEXPARAM_IF([[
|
]AT_LEXPARAM_IF([[
|
||||||
};
|
};
|
||||||
%%]], [[
|
%%]], [[
|
||||||
}]])
|
}]])[
|
||||||
|
|
||||||
[
|
|
||||||
class Position {
|
class Position {
|
||||||
public int line;
|
public int line;
|
||||||
public int token;
|
public int token;
|
||||||
@@ -198,8 +195,8 @@ class Position {
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
])# _AT_DATA_JAVA_CALC_Y
|
])# _AT_DATA_JAVA_CALC_Y
|
||||||
|
|
||||||
|
|||||||
@@ -427,25 +427,10 @@ m4_define([AT_YYLEX_DECLARE],
|
|||||||
[static AT_YYLEX_DECLARE_EXTERN[]dnl
|
[static AT_YYLEX_DECLARE_EXTERN[]dnl
|
||||||
])
|
])
|
||||||
|
|
||||||
m4_define([AT_YYLEX_DEFINE],
|
|
||||||
[[#include <assert.h>
|
# AT_YYLEX_DEFINE([INPUT], [ACTION])
|
||||||
static
|
m4_define([AT_YYLEX_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
|
||||||
]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_YYERROR_FORMALS
|
# AT_YYERROR_FORMALS
|
||||||
# AT_YYERROR_PROTOTYPE
|
# 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)],
|
m4_define([AT_MAIN_DEFINE(c)],
|
||||||
[[#include <stdlib.h> /* getenv. */
|
[[#include <stdlib.h> /* getenv. */
|
||||||
#include <string.h> /* strcmp. */
|
#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++)],
|
m4_define([AT_MAIN_DEFINE(c++)],
|
||||||
[[#include <cstdlib> // getenv.
|
[[#include <cstdlib> // getenv.
|
||||||
#include <cstring> // strcmp.
|
#include <cstring> // strcmp.
|
||||||
@@ -626,7 +638,29 @@ m4_define([AT_YYERROR_DEFINE(java)],
|
|||||||
{
|
{
|
||||||
System.err.println (s);
|
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)],
|
m4_define([AT_MAIN_DEFINE(java)],
|
||||||
[[class input
|
[[class input
|
||||||
|
|||||||
Reference in New Issue
Block a user