diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index cc357d41..42b0c019 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -239,7 +239,8 @@ m4_define([b4_shared_declarations], class context { 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; } ]])[ /// Put in YYARG at most YYARGN of the expected tokens, and return the diff --git a/tests/local.at b/tests/local.at index 42de48c6..5cc51e7e 100644 --- a/tests/local.at +++ b/tests/local.at @@ -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++)])