bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 8/8] diagnostics: suggest fixes for undeclared symbols


From: Akim Demaille
Subject: Re: [PATCH 8/8] diagnostics: suggest fixes for undeclared symbols
Date: Sun, 6 Oct 2019 14:00:45 +0200


> Le 6 oct. 2019 à 13:59, Akim Demaille <address@hidden> a écrit :
> 
>> Le 2 oct. 2019 à 08:22, Akim Demaille <address@hidden> a écrit :
>> 
>> From
>> 
>>   input.y:1.17-19: warning: symbol baz is used, but is not defined as a 
>> token and has no rules [-Wother]
>>        1 | %printer {} foo baz
>>          |                 ^~~
>> 
>> to
>> 
>>   input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a 
>> token and has no rules; did you mean 'bar'? [-Wother]
>>       1 | %printer {} foo baz
>>         |                 ^~~
>>         |                 bar
>> 
>> * bootstrap.conf: We need fstrcmp.
>> * src/symtab.c (symbol_from_uniqstr_fuzzy): New.
>> (complain_symbol_undeclared): Use it.
>> * tests/input.at: Adjust expectations.
> 
> I appended this patch to that series:
> 
> commit fec13ce2db675d18afb887e3c98f347a2b3de31e
> Author: Akim Demaille <address@hidden>
> Date:   Wed Oct 2 08:57:58 2019 +0200
> 
>    diagnostics: sort symbols per location
> 
>    Because the checking of the grammar is made by phases after the whole
>    grammar was read, we sometimes have diagnostics that look weird.  In
>    some case, within one type of checking, the entities are not checked
>    in the order in which they appear in the file.  For instance, checking
>    symbols is done on the list of symbols sorted by tag:
> 
>        foo.y:1.20-22: warning: symbol BAR is used, but is not defined as a 
> token and has no rules [-Wother]
>            1 | %destructor {} QUX BAR
>              |                    ^~~
>        foo.y:1.16-18: warning: symbol QUX is used, but is not defined as a 
> token and has no rules [-Wother]
>            1 | %destructor {} QUX BAR
>              |                ^~~
> 
>    Let's sort them by location instead:
> 
>        foo.y:1.16-18: warning: symbol 'QUX' is used, but is not defined as a 
> token and has no rules [-Wother]
>            1 | %destructor {} QUX BAR
>              |                ^~~
>        foo.y:1.20-22: warning: symbol 'BAR' is used, but is not defined as a 
> token and has no rules [-Wother]
>            1 | %destructor {} QUX BAR
>              |                    ^~~
> 
>    * src/location.h (location_cmp): Be robust to empty file names.
>    * src/symtab.c (symbol_cmp): Sort by location.
>    * tests/input.at: Adjust expectations.

and then this one.  Eventually, I think we need a deep rewrite of the 
diagnostics support, something higher-level.


commit 9e6c5328d321da6bc1d7ce0db4e3676d8132a295
Author: Akim Demaille <address@hidden>
Date:   Sun Oct 6 10:48:59 2019 +0200

    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.

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>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    11 | a: <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>]
    12 | b:<warning>{</warning>
       |   <warning>^</warning>
+      |   <fixit-insert>%empty</fixit-insert>
 input.y:14.3: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    14 | c:
       |   <warning>^</warning>
+      |   <fixit-insert>%empty</fixit-insert>
 input.y:16.2: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    16 | :
       |  <warning>^</warning>
+      |  <fixit-insert>%empty</fixit-insert>
 input.y:17.3: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    17 | e:
       |   <warning>^</warning>
+      |   <fixit-insert>%empty</fixit-insert>
 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>]
    11 | a: <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>]
    12 | b: <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>]
    13 | c: <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>]
    14 | d: <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>]
    15 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning>
       |    <warning>^~~~~~~~~~~~~~</warning>
+      |    <fixit-insert>%empty</fixit-insert>
 input.y:16.4-17: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    16 | f: <warning>{  42      }</warning>
       |    <warning>^~~~~~~~~~~~~~</warning>
+      |    <fixit-insert>%empty</fixit-insert>
 input.y:17.4-17: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    17 | g: <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>]
    18 | h: <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>]
 ]])
 
@@ -211,7 +224,9 @@ b: {}
 [[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    11 | a: <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>]
+      |    <fixit-insert>%empty</fixit-insert>
 /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
 input.y:13.5: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
    13 | exp:
       |     <warning>^</warning>
+      |     <fixit-insert>%empty</fixit-insert>
 input.y: <warning>warning:</warning> fix-its can be applied.  Rerun with 
option '--update'. [<warning>-Wother</warning>]
 ]])
 




reply via email to

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