mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +00:00
diagnostics: modernize bison's syntax errors
We used to display the unexpected token first:
$ bison foo.y
foo.y:1.8-13: error: syntax error, unexpected %token, expecting character literal or identifier or <tag>
1 | %token %token
| ^~~~~~
GCC uses a different format:
$ gcc-mp-9 foo.c
foo.c:1:5: error: expected identifier or '(' before ')' token
1 | int()()()
| ^
and so does Clang:
$ clang-mp-9.0 foo.c
foo.c:1:5: error: expected identifier or '('
int()()()
^
1 error generated.
They display the unexpected token last (or not at all). Also, they
don't waste width with "syntax error". Let's try that. It gives, for
the same example as above:
$ bison foo.y
foo.y:1.8-13: error: expected character literal or identifier or <tag> before %token
1 | %token %token
| ^~~~~~
* src/complain.h, src/complain.c (syntax_error): New.
* src/parse-gram.y (yyreport_syntax_error): Use it.
This commit is contained in:
@@ -161,6 +161,11 @@ void duplicate_directive (char const *directive,
|
||||
void duplicate_rule_directive (char const *directive,
|
||||
location first, location second);
|
||||
|
||||
/** Report a syntax error, where argv[0] is the unexpected
|
||||
token, and argv[1...argc] are the expected ones. */
|
||||
void syntax_error (location loc,
|
||||
int argc, const char* argv[]);
|
||||
|
||||
/** Warnings treated as errors shouldn't stop the execution as regular
|
||||
errors should (because due to their nature, it is safe to go
|
||||
on). Thus, there are three possible execution statuses. */
|
||||
|
||||
Reference in New Issue
Block a user