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:
Akim Demaille
2019-02-16 08:01:34 +01:00
parent 37c4d0b175
commit 0b585c49ae
6 changed files with 63 additions and 17 deletions

View File

@@ -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
]])

View File

@@ -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
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~