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

@@ -239,7 +239,8 @@ m4_define([b4_shared_declarations],
class context class context
{ {
public: public:
context (const ]b4_parser_class[& yyparser, const symbol_type& yyla);]b4_locations_if([[ context (const ]b4_parser_class[& yyparser, const symbol_type& yyla);
int token () const { return yyla_.type_get (); }]b4_locations_if([[
const location_type& location () const { return yyla_.location; } const location_type& location () const { return yyla_.location; }
]])[ ]])[
/// Put in YYARG at most YYARGN of the expected tokens, and return the /// Put in YYARG at most YYARGN of the expected tokens, and return the

View File

@@ -741,33 +741,36 @@ void
}]AT_ERROR_CUSTOM_IF([[ }]AT_ERROR_CUSTOM_IF([[
void void
]AT_NAMESPACE[::parser::yyreport_syntax_error (const context& ctx) const ]AT_NAMESPACE[::parser::yyreport_syntax_error (const context& ctx) const
{ {]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
/* 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]),
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [ [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
YYUSE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[ YYUSE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
++global_nerrs; ++global_nerrs;
++*nerrs;]])[ ++*nerrs;]])[]AT_LOCATION_IF([[
if (n) std::cerr << ctx.location () << ": ";]])[
{]AT_LOCATION_IF([[ std::cerr << "syntax error";
std::cerr << ctx.location () << ": ";]])[ {
std::cerr << "syntax error on token [" << yysymbol_name (arg[0]) << ']'; int la = ctx.token ();
if (1 < n) 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:"; std::cerr << " (expected:";
for (int i = 1; i < n; ++i) for (int i = 0; i < n; ++i)
std::cerr << " [" << yysymbol_name (arg[i]) << ']'; std::cerr << " [" << yysymbol_name (expected[i]) << ']';
std::cerr << ')'; std::cerr << ')';
} }
std::cerr << '\n';
} }
std::cerr << '\n';
}]])]) }]])])
# AT_YYLEX_DEFINE(c++)([INPUT], [ACTION]) # AT_YYLEX_DEFINE(c++)([INPUT], [ACTION])
# ----------------------------------------- # ---------------------------------------
# Same as in C. # Same as in C.
m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)]) m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])