bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/5] fixits: be sure to preserve the action when adding %empty


From: Akim Demaille
Subject: [PATCH 5/5] fixits: be sure to preserve the action when adding %empty
Date: Fri, 3 May 2019 21:19:19 +0200

Currently we remove the rhs to install %empty instead.

* src/reader.c (grammar_rule_check_and_complete): Insert the missing
%empty in front of the rhs, not in replacement thereof.
* tests/actions.at (Add missing %empty): Check that.
---
 src/reader.c     |  7 ++++---
 tests/actions.at | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/reader.c b/src/reader.c
index b5eda9ef..43ca2036 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -357,9 +357,10 @@ grammar_rule_check_and_complete (symbol_list *r)
       && !r->percent_empty_loc.start.file
       && warning_is_enabled (Wempty_rule))
     {
-      complain (&r->rhs_loc, Wempty_rule,
-                _("empty rule without %%empty"));
-      fixits_register (&r->rhs_loc, " %empty ");
+      complain (&r->rhs_loc, Wempty_rule, _("empty rule without %%empty"));
+      location loc = r->rhs_loc;
+      loc.end = loc.start;
+      fixits_register (&loc, " %empty ");
     }
 
   /* See comments in grammar_current_rule_prec_set for how POSIX
diff --git a/tests/actions.at b/tests/actions.at
index 691c84ec..1f279a89 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -259,6 +259,46 @@ AT_BISON_OPTION_POPDEFS
 AT_CLEANUP
 
 
+
+## -------------------- ##
+## Add missing %empty.  ##
+## -------------------- ##
+
+AT_SETUP([Add missing %empty])
+
+AT_DATA([input.y],
+[[%%
+exp: a b c d e
+a: {}
+b:{
+};
+c:
+d
+:
+e:
+%%
+]])
+
+AT_BISON_CHECK([--update -Wall input.y], [], [], [ignore])
+AT_CHECK([cat input.y], [],
+[[%%
+exp: a b c d e
+a:  %empty {}
+b: %empty {
+};
+c: %empty @&t@
+d
+: %empty @&t@
+e: %empty @&t@
+%%
+]])
+
+# No warnings.
+AT_BISON_CHECK([-Wall input.y])
+
+AT_CLEANUP
+
+
 ## ------------------ ##
 ## Initial location.  ##
 ## ------------------ ##
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]