cex: always show ε/%empty in counterexamples

On a case such as
    %%
    exp
    : empty "a"
    | "a" empty

    empty
    : %empty

we used to display

    warning: shift/reduce conflict on token "a" [-Wcounterexamples]
    Example: • "a"
    Shift derivation
      exp
      ↳ 2: • "a" empty
                 ↳ 2: ε
    Example: • "a"
    Reduce derivation
      exp
      ↳ 1: empty  "a"
           ↳ 3: •

where the shift derivation shows an item "2: empty → ε", with an
explicit "ε", but the reduce derivation shows "3: empty → •", without
"ε".

For consistency, let's always show ε/%empty in rules with an empty
rhs:

    Reduce derivation
      exp
      ↳ 1: empty    "a"
           ↳ 3: ε •

* src/derivation.c (derivation_width, derivation_print_tree_impl):
Always show ε/%empty in counterexamples.
* tests/diagnostics.at: Check that case.
* tests/conflicts.at, tests/counterexample.at: Adjust.
This commit is contained in:
Akim Demaille
2020-08-31 07:22:17 +02:00
parent 82d913741b
commit 325ec7d324
6 changed files with 141 additions and 66 deletions

View File

@@ -10605,8 +10605,8 @@ This shows two separate derivations in the grammar for the same @code{exp}:
given example. Here, the first derivation completes a reduction when seeing
@samp{/}, causing @samp{e1 + e2} to be grouped as an @code{exp}. The second
derivation shifts on @samp{/}, resulting in @samp{e2 / e3} being grouped as
an @code{exp}. Therefore, it is easy to see that adding @code{%precedence}
directives would fix this conflict.
an @code{exp}. Therefore, it is easy to see that adding
precedence/associativity directives would fix this conflict.
The remaining states are similar: