mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
diagnostics: display suggested update after the caret-info
This commit adds the suggestion in green, on the line below the
caret-and-tildes.
foo.y:1.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
1 | %error-verbose
| ^~~~~~~~~~~~~~
| %define parse.error verbose
The current approach, with location_caret_suggestion, is fragile:
there's a protocol of calls to the complain functions which is strict.
We should rather have a richer structure describing the diagnostics,
including with submessages such as the suggestions, passed in the end
to the routines in charge of formatting and printing them.
* src/location.h, src/location.c (location_caret_suggestion): New.
* src/complain.c (deprecated_directive): Use it.
* tests/diagnostics.at, tests/input.at: Adjust expectations.
This commit is contained in:
@@ -17,9 +17,14 @@
|
||||
/* This is an experimental feature. The class names may change in the
|
||||
future. */
|
||||
|
||||
/* Diagnostics. */
|
||||
.warning { color: purple; }
|
||||
.error { color: red; }
|
||||
.note { color: cyan; }
|
||||
.insertion { color: green; }
|
||||
|
||||
/* Semantic values in Bison's own parser traces. */
|
||||
.value { color: green; }
|
||||
|
||||
/* "Sections" in traces (--trace). */
|
||||
.trace0 { color: green; }
|
||||
|
||||
@@ -546,17 +546,16 @@ bison_directive (location const *loc, char const *directive)
|
||||
void
|
||||
deprecated_directive (location const *loc, char const *old, char const *upd)
|
||||
{
|
||||
if (feature_flag & feature_caret)
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive, use %s"),
|
||||
quote_n (1, upd));
|
||||
else
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive: %s, use %s"),
|
||||
quote (old), quote_n (1, upd));
|
||||
/* Register updates only if -Wdeprecated is enabled. */
|
||||
if (warning_is_enabled (Wdeprecated))
|
||||
fixits_register (loc, upd);
|
||||
{
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive: %s, use %s"),
|
||||
quote (old), quote_n (1, upd));
|
||||
if (feature_flag & feature_caret)
|
||||
location_caret_suggestion (*loc, upd, stderr);
|
||||
/* Register updates only if -Wdeprecated is enabled. */
|
||||
fixits_register (loc, upd);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -470,6 +470,19 @@ location_caret (location loc, const char *style, FILE *out)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
location_caret_suggestion (location loc, const char *s, FILE *out)
|
||||
{
|
||||
const char *style = "insertion";
|
||||
fprintf (out, " | %*s",
|
||||
loc.start.column - 1 - caret_info.skip + (caret_info.skip ? 3 : 0),
|
||||
"");
|
||||
begin_use_class (style, out);
|
||||
fputs (s, out);
|
||||
end_use_class (style, out);
|
||||
putc ('\n', out);
|
||||
}
|
||||
|
||||
bool
|
||||
location_empty (location loc)
|
||||
{
|
||||
|
||||
@@ -125,6 +125,10 @@ void caret_free (void);
|
||||
with the color STYLE. */
|
||||
void location_caret (location loc, const char* style, FILE *out);
|
||||
|
||||
/* Display a suggestion of replacement for LOC with S. To call after
|
||||
location_caret. */
|
||||
void location_caret_suggestion (location loc, const char *s, FILE *out);
|
||||
|
||||
/* Return -1, 0, 1, depending whether a is before, equal, or
|
||||
after b. */
|
||||
static inline int
|
||||
|
||||
@@ -318,6 +318,7 @@ input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option
|
||||
## Screen width. ##
|
||||
## -------------- ##
|
||||
|
||||
AT_TEST([[Screen width: 200 columns]],
|
||||
[[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
%error-verbose
|
||||
%%
|
||||
@@ -340,11 +341,17 @@ input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||
input.y:9.8-33: previous declaration
|
||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||
10 | <warning>%error-verbose</warning>
|
||||
| <warning>^~~~~~~~~~~~~~</warning>
|
||||
| <insertion>%define parse.error verbose</insertion>
|
||||
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||
]],
|
||||
[[COLUMNS=200]])
|
||||
|
||||
AT_TEST([[Screen width: 80 columns]],
|
||||
[[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
%error-verbose
|
||||
%%
|
||||
@@ -367,11 +374,17 @@ input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||
input.y:9.8-33: previous declaration
|
||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||
10 | <warning>%error-verbose</warning>
|
||||
| <warning>^~~~~~~~~~~~~~</warning>
|
||||
| <insertion>%define parse.error verbose</insertion>
|
||||
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||
]],
|
||||
[[COLUMNS=80]])
|
||||
|
||||
AT_TEST([[Screen width: 60 columns]],
|
||||
[[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
%error-verbose
|
||||
%%
|
||||
@@ -394,6 +407,11 @@ input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||
input.y:9.8-33: previous declaration
|
||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||
10 | ... <warning>%error-verbose</warning>
|
||||
| <warning>^~~~~~~~~~~~~~</warning>
|
||||
| <insertion>%define parse.error verbose</insertion>
|
||||
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||
]],
|
||||
@@ -419,12 +437,14 @@ exp : '0'
|
||||
%%
|
||||
exp : '0'
|
||||
]])
|
||||
|
||||
|
||||
AT_BISON_CHECK([[-fcaret -Wno-other input.y]], [0], [],
|
||||
[[input.y:2.1-12: warning: deprecated directive: '%pure-parser', use '%define api.pure' [-Wdeprecated]
|
||||
2 | %pure-parser
|
||||
2 | %pure-parser
|
||||
| ^~~~~~~~~~~~
|
||||
| %define api.pure
|
||||
input.y:3.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
|
||||
3 | %error-verbose
|
||||
| ^~~~~~~~~~~~~~
|
||||
| %define parse.error verbose
|
||||
]])
|
||||
|
||||
@@ -2051,21 +2051,26 @@ AT_DATA([[input.y]],
|
||||
start: %empty;
|
||||
]])
|
||||
AT_BISON_CHECK([[-fcaret input.y]], [1], [],
|
||||
[[input.y:1.1-26: warning: deprecated directive, use '%define api.push-pull both' [-Wdeprecated]
|
||||
[[input.y:1.1-26: warning: deprecated directive: '%define api.push_pull both', use '%define api.push-pull both' [-Wdeprecated]
|
||||
1 | %define api.push_pull both
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
input.y:2.1-40: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
|
||||
| %define api.push-pull both
|
||||
input.y:2.1-40: warning: deprecated directive: '%define lr.keep_unreachable_states maybe', use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
|
||||
2 | %define lr.keep_unreachable_states maybe
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
input.y:3.1-23: warning: deprecated directive, use '%define api.namespace {foo}' [-Wdeprecated]
|
||||
| %define lr.keep-unreachable-state maybe
|
||||
input.y:3.1-23: warning: deprecated directive: '%define namespace "foo"', use '%define api.namespace {foo}' [-Wdeprecated]
|
||||
3 | %define namespace "foo"
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~
|
||||
input.y:4.1-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated]
|
||||
| %define api.namespace {foo}
|
||||
input.y:4.1-15: warning: deprecated directive: '%define variant', use '%define api.value.type variant' [-Wdeprecated]
|
||||
4 | %define variant
|
||||
| ^~~~~~~~~~~~~~~
|
||||
input.y:5.1-34: warning: deprecated directive, use '%define api.parser.class {parser}' [-Wdeprecated]
|
||||
| %define api.value.type variant
|
||||
input.y:5.1-34: warning: deprecated directive: '%define parser_class_name {parser}', use '%define api.parser.class {parser}' [-Wdeprecated]
|
||||
5 | %define parser_class_name {parser}
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
| %define api.parser.class {parser}
|
||||
input.y:2.1-40: error: invalid value for %define Boolean variable 'lr.keep-unreachable-state'
|
||||
2 | %define lr.keep_unreachable_states maybe
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user