report: put the dot after %empty in items

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
commit 36143b5ecc698d64a7a3ff266a9ea7b6fba1749b
Author: Akim Demaille <[email protected]>
Date:   Sun Oct 4 14:35:46 2020 +0200

    report: put the dot after %empty in items
    
    When printing items, it is clearer to put the dot after %emtpy rather
    than before:
    
         0 $accept: . unit "end of file"
         1 unit: . assignments exp
    -    2 assignments: . %empty
    +    2 assignments: %empty .
         3            | . assignments assignment
    
    Also, use the Unicode characters if they are supported.
    
    * src/gram.c (item_print): Put the dot after %emtpy.
    * tests/conflicts.at, tests/reduce.at, tests/report.at: Adjust.

diff --git a/src/gram.c b/src/gram.c
index 58f62700..d20441b8 100644
--- a/src/gram.c
+++ b/src/gram.c
@@ -55,14 +55,17 @@ item_print (item_number *item, rule const *previous_rule, FILE *out)
   rule const *r = item_rule (item);
   rule_lhs_print (r, previous_rule ? previous_rule->lhs : NULL, out);
 
-  for (item_number *sp = r->rhs; sp < item; sp++)
-    fprintf (out, " %s", symbols[*sp]->tag);
-  fprintf (out, " %s", dot);
   if (0 <= *r->rhs)
-    for (item_number *sp = item; 0 <= *sp; ++sp)
-      fprintf (out, " %s", symbols[*sp]->tag);
+    {
+      // Non-empty rhs.
+      for (item_number *sp = r->rhs; sp < item; sp++)
+        fprintf (out, " %s", symbols[*sp]->tag);
+      fprintf (out, " %s", dot);
+      for (item_number *sp = item; 0 <= *sp; ++sp)
+        fprintf (out, " %s", symbols[*sp]->tag);
+    }
   else
-    fprintf (out, " %%empty");
+    fprintf (out, " %s %s", empty, dot);
 }
 
 
@@ -122,7 +125,7 @@ rule_rhs_print (rule const *r, FILE *out)
     for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp)
       fprintf (out, " %s", symbols[*rhsp]->tag);
   else
-    fputs (" %empty", out);
+    fprintf (out, " %s", empty);
 }
 
 static void
diff --git a/tests/conflicts.at b/tests/conflicts.at
index 9c1c5814..c7c13147 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -1720,7 +1720,7 @@ State 0
     0 $accept: . start $end
     1 start: . resolved_conflict 'a' reported_conflicts 'a'
     2 resolved_conflict: . 'a' unreachable1
-    3                  | . %empty  ['a']
+    3                  | %empty .  ['a']
 
     $default  reduce using rule 3 (resolved_conflict)
 
@@ -1756,7 +1756,7 @@ State 4
     1 start: resolved_conflict 'a' . reported_conflicts 'a'
     8 reported_conflicts: . 'a'
     9                   | . 'a'
-   10                   | . %empty  ['a']
+   10                   | %empty .  ['a']
 
     'a'  shift, and go to state 5
 
@@ -1765,7 +1765,7 @@ State 4
     reported_conflicts  go to state 6
 
     shift/reduce conflict on token 'a':
-       10 reported_conflicts: . %empty
+       10 reported_conflicts: %empty .
         8 reported_conflicts: . 'a'
       First example: resolved_conflict . 'a' 'a'
       Shift derivation
@@ -1779,7 +1779,7 @@ State 4
                                  `-> 10: %empty .
 
     shift/reduce conflict on token 'a':
-       10 reported_conflicts: . %empty
+       10 reported_conflicts: %empty .
         9 reported_conflicts: . 'a'
       First example: resolved_conflict . 'a' 'a'
       Shift derivation
@@ -1891,11 +1891,11 @@ AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
     6      | . empty_c1 'c'
     7      | . empty_c2 'c'
     8      | . empty_c3 'c'
-    9 empty_a: . %empty  ['a']
-   10 empty_b: . %empty  []
-   11 empty_c1: . %empty  []
-   12 empty_c2: . %empty  []
-   13 empty_c3: . %empty  ['c']
+    9 empty_a: %empty .  ['a']
+   10 empty_b: %empty .  []
+   11 empty_c1: %empty .  []
+   12 empty_c2: %empty .  []
+   13 empty_c3: %empty .  ['c']
 
     'b'  shift, and go to state 1
 
@@ -1969,11 +1969,11 @@ AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
     6      | . empty_c1 'c'
     7      | . empty_c2 'c'
     8      | . empty_c3 'c'
-    9 empty_a: . %empty  []
-   10 empty_b: . %empty  []
-   11 empty_c1: . %empty  []
-   12 empty_c2: . %empty  ['c']
-   13 empty_c3: . %empty  ['c']
+    9 empty_a: %empty .  []
+   10 empty_b: %empty .  []
+   11 empty_c1: %empty .  []
+   12 empty_c2: %empty .  ['c']
+   13 empty_c3: %empty .  ['c']
 
     'a'  error (nonassociative)
     'b'  error (nonassociative)
@@ -1994,8 +1994,8 @@ AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
     Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
 
     reduce/reduce conflict on token 'c':
-       12 empty_c2: . %empty
-       13 empty_c3: . %empty
+       12 empty_c2: %empty .
+       13 empty_c3: %empty .
       Example: . 'c'
       First reduce derivation
         start
diff --git a/tests/reduce.at b/tests/reduce.at
index c1af62ee..f9d59a26 100644
--- a/tests/reduce.at
+++ b/tests/reduce.at
@@ -1164,7 +1164,7 @@ State 12
 
     4 A: 'a' 'a' . B
     5 B: . 'a'
-    6  | . %empty  ]AT_COND_CASE([[LALR]], [[['a', 'b']]], [[['a']]])[
+    6  | %empty .  ]AT_COND_CASE([[LALR]], [[['a', 'b']]], [[['a']]])[
 
     ]AT_COND_CASE([[canonical LR]], [['a']],
                   [[$default]])[  reduce using rule 6 (B)
@@ -1194,7 +1194,7 @@ State 15
 
     4 A: 'a' 'a' . B
     5 B: . 'a'
-    6  | . %empty  [$end]
+    6  | %empty .  [$end]
     7 c: 'a' 'a' . 'b'
 
     'a'  shift, and go to state ]AT_COND_CASE([[canonical LR]], [[20]],
@@ -1257,7 +1257,7 @@ State 22]])[
 
     4 A: 'a' 'a' . B
     5 B: . 'a'
-    6  | . %empty  ['b']
+    6  | %empty .  ['b']
 
     'a'  shift, and go to state ]AT_COND_CASE([[canonical LR]], [[23]],
                                               [[16]])[
@@ -1683,8 +1683,8 @@ State 3
     1 start: a . b
     2      | a . b 'a'
     3      | a . c 'b'
-    5 b: . %empty  [$end, 'a']
-    6 c: . %empty  ['b']]AT_COND_CASE([[most]], [[
+    5 b: %empty .  [$end, 'a']
+    6 c: %empty .  ['b']]AT_COND_CASE([[most]], [[
 
     'b'       reduce using rule 6 (c)
     $default  reduce using rule 5 (b)]], [[
diff --git a/tests/report.at b/tests/report.at
index d55497aa..c6190491 100644
--- a/tests/report.at
+++ b/tests/report.at
@@ -376,7 +376,7 @@ State 0
 
     0 $accept: . unit "end of file"
     1 unit: . assignments exp
-    2 assignments: . %empty
+    2 assignments: %empty .
     3            | . assignments assignment
 
     $default  reduce using rule 2 (assignments)
@@ -498,7 +498,7 @@ State 11
 
 State 12
 
-    6 @1: . %empty
+    6 @1: %empty .
     8 exp: "incr" exp . @1 @2 exp
 
     $default  reduce using rule 6 (@1)
@@ -531,7 +531,7 @@ State 14
 
 State 15
 
-    7 @2: . %empty
+    7 @2: %empty .
     8 exp: "incr" exp @1 . @2 exp
 
     $default  reduce using rule 7 (@2)
@@ -1631,7 +1631,7 @@ State 1
 
     0 $accept: YY_PARSE_unit . unit "end of file"
     3 unit: . assignments exp
-    4 assignments: . %empty
+    4 assignments: %empty .
     5            | . assignments assignment
 
     $default  reduce using rule 4 (assignments)
@@ -1643,7 +1643,7 @@ State 1
 State 2
 
     1 $accept: YY_PARSE_assignments . assignments "end of file"
-    4 assignments: . %empty
+    4 assignments: %empty .
     5            | . assignments assignment
 
     $default  reduce using rule 4 (assignments)
@@ -1815,7 +1815,7 @@ State 18
 
 State 19
 
-    8 @1: . %empty
+    8 @1: %empty .
    10 exp: "incr" exp . @1 @2 exp
 
     $default  reduce using rule 8 (@1)
@@ -1855,7 +1855,7 @@ State 22
 
 State 23
 
-    9 @2: . %empty
+    9 @2: %empty .
    10 exp: "incr" exp @1 . @2 exp
 
     $default  reduce using rule 9 (@2)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.