diagnostics: also show suggested %empty

* src/reader.c (grammar_rule_check_and_complete): Suggest to add %empty.
* tests/actions.at, tests/diagnostics.at: Adjust expectations.
This commit is contained in:
Akim Demaille
2019-10-06 10:48:59 +02:00
parent fec13ce2db
commit 9e6c5328d3
4 changed files with 42 additions and 0 deletions

21
NEWS
View File

@@ -39,6 +39,27 @@ GNU Bison NEWS
The gain is typically moderate, but in extreme cases (very simple user The gain is typically moderate, but in extreme cases (very simple user
actions), a 10% improvement can be observed. actions), a 10% improvement can be observed.
*** Diagnostics with insertion
The diagnostics now display suggestion below the underlined source.
Replacement for undeclared symbols are now also suggested.
$ cat /tmp/foo.y
%%
list: lis '.' |
$ bison -Wall foo.y
foo.y:2.7-9: error: symbol 'lis' is used, but is not defined as a token and has no rules; did you mean 'list'?
2 | list: lis '.' |
| ^~~
| list
foo.y:2.16: warning: empty rule without %empty [-Wempty-rule]
2 | list: lis '.' |
| ^
| %empty
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
*** Debug traces in Java *** Debug traces in Java
The Java backend no longer emits code and data for parser tracing if the The Java backend no longer emits code and data for parser tracing if the

View File

@@ -358,6 +358,8 @@ grammar_rule_check_and_complete (symbol_list *r)
&& warning_is_enabled (Wempty_rule)) && warning_is_enabled (Wempty_rule))
{ {
complain (&r->rhs_loc, Wempty_rule, _("empty rule without %%empty")); complain (&r->rhs_loc, Wempty_rule, _("empty rule without %%empty"));
if (feature_flag & feature_caret)
location_caret_suggestion (r->rhs_loc, "%empty", stderr);
location loc = r->rhs_loc; location loc = r->rhs_loc;
loc.end = loc.start; loc.end = loc.start;
fixits_register (&loc, " %empty "); fixits_register (&loc, " %empty ");

View File

@@ -134,6 +134,7 @@ AT_BISON_CHECK([-fcaret -Wempty-rule 1.y], [0], [],
[[1.y:11.17-18: warning: empty rule without %empty [-Wempty-rule] [[1.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
11 | a: /* empty. */ {}; 11 | a: /* empty. */ {};
| ^~ | ^~
| %empty
1.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] 1.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]]) ]])
@@ -149,9 +150,11 @@ AT_BISON_CHECK([-fcaret 2.y], [0], [],
[[2.y:11.17-18: warning: empty rule without %empty [-Wempty-rule] [[2.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
11 | a: /* empty. */ {}; 11 | a: /* empty. */ {};
| ^~ | ^~
| %empty
2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule] 2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule]
13 | c: /* empty. */ {}; 13 | c: /* empty. */ {};
| ^~ | ^~
| %empty
2.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] 2.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]]) ]])

View File

@@ -128,18 +128,23 @@ e:
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] [[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
11 | a: <warning>{}</warning> 11 | a: <warning>{}</warning>
| <warning>^~</warning> | <warning>^~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:12.3-13.1: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:12.3-13.1: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
12 | b:<warning>{</warning> 12 | b:<warning>{</warning>
| <warning>^</warning> | <warning>^</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:14.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:14.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
14 | c: 14 | c:
| <warning>^</warning> | <warning>^</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:16.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:16.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
16 | : 16 | :
| <warning>^</warning> | <warning>^</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:17.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:17.3: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
17 | e: 17 | e:
| <warning>^</warning> | <warning>^</warning>
| <fixit-insert>%empty</fixit-insert>
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>] input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
]]) ]])
@@ -167,27 +172,35 @@ h: { 🐃 }
[[input.y:11.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] [[input.y:11.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
11 | a: <warning>{ }</warning> 11 | a: <warning>{ }</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:12.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:12.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
12 | b: <warning>{ }</warning> 12 | b: <warning>{ }</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:13.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:13.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
13 | c: <warning>{------------}</warning> 13 | c: <warning>{------------}</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:14.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:14.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
14 | d: <warning>{éééééééééééé}</warning> 14 | d: <warning>{éééééééééééé}</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:15.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:15.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
15 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning> 15 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:16.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:16.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
16 | f: <warning>{ 42 }</warning> 16 | f: <warning>{ 42 }</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:17.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:17.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
17 | g: <warning>{ "฿¥$€₦" }</warning> 17 | g: <warning>{ "฿¥$€₦" }</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:18.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:18.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
18 | h: <warning>{ 🐃 }</warning> 18 | h: <warning>{ 🐃 }</warning>
| <warning>^~~~~~~~~~~~~~</warning> | <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>] input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
]]) ]])
@@ -211,7 +224,9 @@ b: {}
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] [[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
11 | a: <warning>{}</warning> 11 | a: <warning>{}</warning>
| <warning>^~</warning> | <warning>^~</warning>
| <fixit-insert>%empty</fixit-insert>
/dev/stdout:1.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] /dev/stdout:1.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
| <fixit-insert>%empty</fixit-insert>
/dev/stdout: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>] /dev/stdout: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
]]) ]])
@@ -307,6 +322,7 @@ input.y:10.9-11: previous declaration
<note>FOO</note> <note>FOO</note>
| <note>^~~</note> | <note>^~~</note>
input.y:13.5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>] input.y:13.5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
13 | exp:
| <warning>^</warning> | <warning>^</warning>
| <fixit-insert>%empty</fixit-insert> | <fixit-insert>%empty</fixit-insert>
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>] input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]