diff --git a/NEWS b/NEWS
index a64e3492..fbf9f4cc 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,27 @@ GNU Bison NEWS
The gain is typically moderate, but in extreme cases (very simple user
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
The Java backend no longer emits code and data for parser tracing if the
diff --git a/src/reader.c b/src/reader.c
index 928c8a7a..fb8a19d6 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -358,6 +358,8 @@ grammar_rule_check_and_complete (symbol_list *r)
&& warning_is_enabled (Wempty_rule))
{
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;
loc.end = loc.start;
fixits_register (&loc, " %empty ");
diff --git a/tests/actions.at b/tests/actions.at
index eaa720c0..84dab3c0 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -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]
11 | a: /* empty. */ {};
| ^~
+ | %empty
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]
11 | a: /* empty. */ {};
| ^~
+ | %empty
2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule]
13 | c: /* empty. */ {};
| ^~
+ | %empty
2.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index deac06ff..d92d134b 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -128,18 +128,23 @@ e:
[[input.y:11.4-5: warning: empty rule without %empty [-Wempty-rule]
11 | a: {}
| ^~
+ | %empty
input.y:12.3-13.1: warning: empty rule without %empty [-Wempty-rule]
12 | b:{
| ^
+ | %empty
input.y:14.3: warning: empty rule without %empty [-Wempty-rule]
14 | c:
| ^
+ | %empty
input.y:16.2: warning: empty rule without %empty [-Wempty-rule]
16 | :
| ^
+ | %empty
input.y:17.3: warning: empty rule without %empty [-Wempty-rule]
17 | e:
| ^
+ | %empty
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
@@ -167,27 +172,35 @@ h: { 🐃 }
[[input.y:11.4-17: warning: empty rule without %empty [-Wempty-rule]
11 | a: { }
| ^~~~~~~~~~~~~~
+ | %empty
input.y:12.4-17: warning: empty rule without %empty [-Wempty-rule]
12 | b: { }
| ^~~~~~~~~~~~~~
+ | %empty
input.y:13.4-17: warning: empty rule without %empty [-Wempty-rule]
13 | c: {------------}
| ^~~~~~~~~~~~~~
+ | %empty
input.y:14.4-17: warning: empty rule without %empty [-Wempty-rule]
14 | d: {éééééééééééé}
| ^~~~~~~~~~~~~~
+ | %empty
input.y:15.4-17: warning: empty rule without %empty [-Wempty-rule]
15 | e: {∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}
| ^~~~~~~~~~~~~~
+ | %empty
input.y:16.4-17: warning: empty rule without %empty [-Wempty-rule]
16 | f: { 42 }
| ^~~~~~~~~~~~~~
+ | %empty
input.y:17.4-17: warning: empty rule without %empty [-Wempty-rule]
17 | g: { "฿¥$€₦" }
| ^~~~~~~~~~~~~~
+ | %empty
input.y:18.4-17: warning: empty rule without %empty [-Wempty-rule]
18 | h: { 🐃 }
| ^~~~~~~~~~~~~~
+ | %empty
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
@@ -211,7 +224,9 @@ b: {}
[[input.y:11.4-5: warning: empty rule without %empty [-Wempty-rule]
11 | a: {}
| ^~
+ | %empty
/dev/stdout:1.4-5: warning: empty rule without %empty [-Wempty-rule]
+ | %empty
/dev/stdout: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
@@ -307,6 +322,7 @@ input.y:10.9-11: previous declaration
input.y:13.5: warning: empty rule without %empty [-Wempty-rule]
13 | exp:
| ^
+ | %empty
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])