Commit Graph

12 Commits

Author SHA1 Message Date
Akim Demaille
b0bb4cde2e cex: suggest -Wcounterexamples when there are unexpected conflicts
Suggesting -Wcounterexamples when there are conflicts is probably not
what the user wants.  If she knows her conflicts and has set
%expect/%expect-rr appropriately, we shouldn't warn.

The commit also swaps the counterexamples and the report of conflicts,
into, IMHO, a more natural order: from

    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

to

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

* src/conflicts.c (rule_conflicts_print): Rename as...
(report_rule_expectation_mismatches): this.
Move the handling of report_counterexamples to...
(conflicts_print): Here.
Display this warning when applicable.
2020-06-10 09:51:39 +02:00
Akim Demaille
d2acc4b401 cex: rename -Wcounterexample as -Wcounterexamples, and support -Wcex
Plural vs. singular is always a problem...

But we already have conflicts-sr and conflicts-rr, so counterexamples
makes more sense than counterexample.  Besides, -Wcounterexample will
still be accepted as an unambiguous prefix of -Wcounterexamples.

Add -Wcex as a convenient alias.

While at it, use only "counterexample", never "counter example".

* src/complain.h, src/complain.c
(Wcounterexample, warning_counterexample): Rename as...
(Wcounterexamples, warning_counterexamples): these.
(argmatch_warning_docs): Rename -Wcounterexample as -Wcounterexamples.
(argmatch_warning_args): Likewise.
Add support for -Wcex.
Adjust dependencies.
2020-06-10 07:53:44 +02:00
Akim Demaille
ae5edcc23b cex: color the counterexamples
Use colors to show the counterexamples and the derivations in color,
to highlight their structure.  Align the outputs, and add i18n
support. Reduce width by using a one-space separator instead of
two-space.

From

    Example  A  •  B  C
    First  derivation  s ::=[ a ::=[ A  • ]  x ::=[ B  C ] ]
    Second derivation  s ::=[ y ::=[ A  •  B ]  c ::=[ C ] ]

to

    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

with colors.

* data/bison-default.css (cex-dot, cex-0, cex-1, cex-2, cex-3, cex-4)
(cex-5, cex-6, cex-7, cex-step, cex-leaf): New.
* src/derivation.c (derivation_print_styled_impl): New.
(derivation_print, derivation_print_leaves): Use it.
* src/counterexample.c: Reformat the output.
* tests/counterexample.at: Adjust.
2020-06-07 09:18:58 +02:00
Akim Demaille
296e2f90ab cex: enforce case for tokens/nonterminals
It's unfortunate that the traditions between formal language theory
and Yacc differs, but here, tokens should be upper case, and
nonterminals should be lower case.

* tests/counterexample.at: Comply with this.
2020-06-07 09:18:58 +02:00
Akim Demaille
1ccb4be02b cex: reformat the s/r and r/r reports
In Bison we refer to "shift/reduce" conflicts, not "shift-reduce" (in
Bison 3.6.3 186 occurrences vs 15).  Enforce consistency on this.

Instead of "spending" a second line for each conflict to report the
lookaheads, put that on the same line as the type of conflict.  Also,
prefer "token" to "symbol".  Maybe we should even prefer "lookahead".
While at it, enable internationalization, with plurals where
appropriate.

As a consequence, instead of

    Shift-Reduce Conflict:
    6:    3 b: . %empty
    6:    6 d: c . A
    On Symbol: A

display

    Shift/reduce conflict on token A:
    6:    3 b: . %empty
    6:    6 d: c . A

* NEWS, doc/bison.texi, src/conflicts.c: Spell it "shift/reduce", not
"shift-reduce".
* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Reformat and internationalize
output.
* tests/counterexample.at: Adjust expectations.
2020-06-07 09:18:58 +02:00
Akim Demaille
6ed813c122 tests: fix expectations
Should have been part of 1ec93ca2a2.

* tests/counterexample.at: here.
2020-05-24 15:17:14 +02:00
Akim Demaille
1ec93ca2a2 cex: clean the display of conflicted symbols
Instead of `On Symbols: {b,c,}`, display `On Symbols: b, c`.

* src/counterexample.c (counterexample_report_reduce_reduce): We don't
need braces.
Use commas as a separator, not a terminator.
* tests/counterexample.at: Adjust.
2020-05-23 18:23:07 +02:00
Akim Demaille
e0cb91a922 cex: tests: be robust to variations in time limit reports
The CI has "failures" such as (253, "Null nonterminals"):

    @@ -21,7 +21,7 @@
     3:    3 b: . %empty
     3:    4 c: . %empty
     On Symbols: {A,}
    -time limit exceeded: 6.000000
    +time limit exceeded: 11.000000
     First  Example c  •  c  A  A  $end
     First  derivation  $accept ::=[ a ::=[ c  d ::=[ a ::=[ b ::=[ • ]  d ::=[ c  A  A ] ] ] ]  $end ]
     Second Example c  •  A  $end

* tests/counterexample.at (AT_BISON_CHECK_CEX): New.
Use it to neutralize differences in timeout values.
2020-05-22 07:52:27 +02:00
Vincent Imbimbo
482b370540 cex: fix stack overflow
* src/parse-simulation.c: Replace reference counting with
parse_state_retain everywhere.
(free_parse_state): Make this function iterative instead of
recursive. Long parse_state chains were causing stack exhaustion.

* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Vincent Imbimbo
66283fb625 cex: fix crash from zombie result
Fixes the SEGV in test 247 (counterexample.at:195): "S/R after first
token".

* src/counterexample.c: here.
* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Akim Demaille
93c849ef0d cex: fixes, and enable tests
* src/counterexample.c, src/derivation.c:
Do not output diagnostics on stdout, that's the job of stderr, and the
testsuite heavily depend on this.
Do not leave trailing spaces in the output.
* tests/counterexample.at: Use AT_KEYWORDS.
Specify the expected outputs.
* tests/local.mk: Add counterexample.at.
2020-05-22 07:52:27 +02:00
Vincent Imbimbo
dcb6c972a2 cex: add tests
* tests/counterexample.at: New.
2020-05-22 07:52:27 +02:00