[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 0/5] glr2.cc: add support for custom error messages
From: |
Akim Demaille |
Subject: |
[PATCH 0/5] glr2.cc: add support for custom error messages |
Date: |
Sun, 12 Sep 2021 12:05:44 +0200 |
The series of patches installs support for `%define parse.error custom`
in glr2.cc. It has the same interface as that of lalr1.cc. For instance
(taken from examples/c++/glr):
// Generate a custom error message.
void
yy::parser::report_syntax_error (const context& ctx) const
{
std::cerr << ctx.location () << ": syntax error";
if (!ctx.lookahead ().empty ())
std::cerr << " on token " << ctx.lookahead ().name ();
{
enum { TOKENMAX = 10 };
symbol_kind_type expected[TOKENMAX];
int n = ctx.expected_tokens (expected, TOKENMAX);
if (0 < n)
{
for (int i = 0; i < n; ++i)
std::cerr << (i == 0 ? " (expected " : " or ")
<< symbol_name (expected[i]);
std::cerr << ')';
}
}
std::cerr << '\n';
}
This was reported by Tom Shields <thomas.evans.shields@icloud.com>.
<https://lists.gnu.org/r/bug-bison/2021-08/msg00003.html>
Forthcoming changes will address the fact that currently one cannot
link two glr2.cc parsers together.
Akim Demaille (5):
c++: avoid using the obsolete names
c++: add move assignments to the symbol type
glr2.cc: start the transition to using symbol_type
glr2.cc: custom error messages
c++: demonstrate custom error messages in the examples
data/skeletons/c++.m4 | 57 +++-
data/skeletons/glr2.cc | 460 ++++++++++++++++++--------------
data/skeletons/lalr1.cc | 8 +-
data/skeletons/variant.hh | 4 +-
examples/c++/README.md | 9 +
examples/c++/glr/README.md | 3 +
examples/c++/glr/c++-types.test | 2 +-
examples/c++/glr/c++-types.yy | 47 +++-
examples/c/bistromathic/parse.y | 5 +-
tests/c++.at | 5 +-
tests/calc.at | 5 +
tests/glr-regression.at | 26 +-
tests/local.at | 2 +-
tests/types.at | 1 +
14 files changed, 395 insertions(+), 239 deletions(-)
--
2.32.0
- [PATCH 0/5] glr2.cc: add support for custom error messages,
Akim Demaille <=
- [PATCH 1/5] c++: avoid using the obsolete names, Akim Demaille, 2021/09/12
- [PATCH 2/5] c++: add move assignments to the symbol type, Akim Demaille, 2021/09/12
- [PATCH 3/5] glr2.cc: start the transition to using symbol_type, Akim Demaille, 2021/09/12
- [PATCH 4/5] glr2.cc: custom error messages, Akim Demaille, 2021/09/12
- [PATCH 5/5] c++: demonstrate custom error messages in the examples, Akim Demaille, 2021/09/12