lalr1.cc: avoid using yysyntax_error_arguments

* data/skeletons/lalr1.cc (context::token): New.
* tests/local.at (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
This commit is contained in:
Akim Demaille
2020-03-21 09:43:20 +01:00
parent 4192de1f41
commit 1edc98f793
2 changed files with 20 additions and 16 deletions

View File

@@ -741,33 +741,36 @@ void
}]AT_ERROR_CUSTOM_IF([[
void
]AT_NAMESPACE[::parser::yyreport_syntax_error (const context& ctx) const
{
/* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */
int arg[yyntokens_];
int n = ctx.yysyntax_error_arguments (arg, yyntokens_);]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
{]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
YYUSE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
++global_nerrs;
++*nerrs;]])[
if (n)
{]AT_LOCATION_IF([[
std::cerr << ctx.location () << ": ";]])[
std::cerr << "syntax error on token [" << yysymbol_name (arg[0]) << ']';
if (1 < n)
++*nerrs;]])[]AT_LOCATION_IF([[
std::cerr << ctx.location () << ": ";]])[
std::cerr << "syntax error";
{
int la = ctx.token ();
if (la != empty_symbol)
fprintf (stderr, " on token [%s]", yysymbol_name (la));
}
{
enum { TOKENMAX = 10 };
int expected[TOKENMAX];
int n = ctx.yyexpected_tokens (expected, TOKENMAX);
if (0 < n)
{
std::cerr << " (expected:";
for (int i = 1; i < n; ++i)
std::cerr << " [" << yysymbol_name (arg[i]) << ']';
for (int i = 0; i < n; ++i)
std::cerr << " [" << yysymbol_name (expected[i]) << ']';
std::cerr << ')';
}
std::cerr << '\n';
}
std::cerr << '\n';
}]])])
# AT_YYLEX_DEFINE(c++)([INPUT], [ACTION])
# -----------------------------------------
# ---------------------------------------
# Same as in C.
m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])