bison-patches
[Top][All Lists]
Advanced

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

fixits: avoid generating empty lines


From: Akim Demaille
Subject: fixits: avoid generating empty lines
Date: Wed, 16 Jan 2019 06:57:16 +0100

commit b7e0d3131d2e0e5a370d3dea4c89958366d59d28
Author: Akim Demaille <address@hidden>
Date:   Tue Jan 15 18:20:37 2019 +0100

    fixits: avoid generating empty lines
    
    * src/fixits.c (fixits_run): If erase the content of a line, also
    erase the following \n.
    * tests/input.at (Deprecated directives): Update expectations.

diff --git a/src/fixits.c b/src/fixits.c
index 769b8508..b0afa443 100644
--- a/src/fixits.c
+++ b/src/fixits.c
@@ -161,6 +161,21 @@ fixits_run (void)
             break;
           ++offset;
         }
+      /* If erasing the content of a full line, also remove the
+         end-of-line. */
+      if (f->fix[0] == 0 && f->location.start.column == 1)
+        {
+          int c = getc (in);
+          if (c == EOF)
+            break;
+          else if (c == '\n')
+            {
+              ++line;
+              offset = 1;
+            }
+          else
+            ungetc (c, in);
+        }
     }
   /* Paste the rest of the file.  */
   {
diff --git a/tests/input.at b/tests/input.at
index 40ba92bd..a61fcf2b 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -2586,7 +2586,6 @@ AT_CHECK([cat input.y], [],
 %output "foo"
 %pure-parser
 %token-table
-
 %glr-parser
 %define api.prefix {bar}
 %%
@@ -2594,7 +2593,7 @@ exp : '0'
 ]])
 
 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
-[[input.y:28.1-24: error: %define variable 'api.prefix' redefined
+[[input.y:27.1-24: error: %define variable 'api.prefix' redefined
  %define api.prefix {bar}
  ^~~~~~~~~~~~~~~~~~~~~~~~
 input.y:19.1-24:     previous definition




reply via email to

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