[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/7] lalr1.cc: avoid using yysyntax_error_arguments
From: |
Akim Demaille |
Subject: |
[PATCH 7/7] lalr1.cc: avoid using yysyntax_error_arguments |
Date: |
Sat, 21 Mar 2020 12:53:15 +0100 |
* data/skeletons/lalr1.cc (context::token): New.
* tests/local.at (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
---
data/skeletons/lalr1.cc | 3 ++-
tests/local.at | 33 ++++++++++++++++++---------------
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index e35b21c5..75252f6f 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++)])
--
2.25.1
- [PATCH 0/7] Deprecate yysyntax_error_arguments, Akim Demaille, 2020/03/21
- [PATCH 1/7] doc: c++: promote api.token.raw, Akim Demaille, 2020/03/21
- [PATCH 2/7] style: reduce length of private constant, Akim Demaille, 2020/03/21
- [PATCH 5/7] tests: yacc.c: avoid yysyntax_error_arguments, Akim Demaille, 2020/03/21
- [PATCH 3/7] yacc.c: use negative numbers for errors in auxiliary functions, Akim Demaille, 2020/03/21
- [PATCH 4/7] examples: don't use yysyntax_error_arguments, Akim Demaille, 2020/03/21
- [PATCH 7/7] lalr1.cc: avoid using yysyntax_error_arguments,
Akim Demaille <=
- [PATCH 6/7] bison: avoid using yysyntax_error_arguments, Akim Demaille, 2020/03/21
- Re: [PATCH 0/7] Deprecate yysyntax_error_arguments, Akim Demaille, 2020/03/26