diff --git a/data/bison-default.css b/data/bison-default.css index db9d87eb..41304a2b 100644 --- a/data/bison-default.css +++ b/data/bison-default.css @@ -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; } diff --git a/src/complain.c b/src/complain.c index 8715898f..aba63e3f 100644 --- a/src/complain.c +++ b/src/complain.c @@ -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 diff --git a/src/location.c b/src/location.c index 46cb10ea..b36f49d3 100644 --- a/src/location.c +++ b/src/location.c @@ -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) { diff --git a/src/location.h b/src/location.h index b9e4c726..8eb7c472 100644 --- a/src/location.h +++ b/src/location.h @@ -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 diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 03960d5f..4042a815 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -318,6 +318,7 @@ input.y: warning: fix-its can be applied. Rerun with option AT_TEST([[Screen width: 200 columns]], [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ + %error-verbose %% exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ ]], @@ -340,11 +341,17 @@ input.y:9.92-117: warning: symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ input.y:9.8-33: previous declaration 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +input.y:10.56-69: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated] + 10 | %error-verbose + | ^~~~~~~~~~~~~~ + | %define parse.error verbose +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], [[COLUMNS=200]]) AT_TEST([[Screen width: 80 columns]], [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ + %error-verbose %% exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ ]], @@ -367,11 +374,17 @@ input.y:9.92-117: warning: symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ input.y:9.8-33: previous declaration 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF... | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +input.y:10.56-69: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated] + 10 | %error-verbose + | ^~~~~~~~~~~~~~ + | %define parse.error verbose +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], [[COLUMNS=80]]) AT_TEST([[Screen width: 60 columns]], [[%token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ + %error-verbose %% exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ ]], @@ -394,6 +407,11 @@ input.y:9.92-117: warning: symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ input.y:9.8-33: previous declaration 9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMN... | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +input.y:10.56-69: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated] + 10 | ... %error-verbose + | ^~~~~~~~~~~~~~ + | %define parse.error verbose +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], [[COLUMNS=60]]) @@ -419,12 +437,14 @@ exp : '0' ]]) AT_BISON_CHECK([[-fcaret -Wno-other input.y]], [0], [], -[[input.y:2.1-12: warning: deprecated directive, use '%define api.pure' [-Wdeprecated] +[[input.y:2.1-12: warning: deprecated directive: '%pure-parser', use '%define api.pure' [-Wdeprecated] 2 | %pure-parser | ^~~~~~~~~~~~ -input.y:3.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated] + | %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 ]]) AT_CLEANUP diff --git a/tests/input.at b/tests/input.at index 7174159b..20a0c9ba 100644 --- a/tests/input.at +++ b/tests/input.at @@ -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 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~