From b81229e1f93999c77887422c0795407154876823 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 20 Jul 2020 07:03:39 +0200 Subject: [PATCH] cex: improve readability of the subsections Now that the derivation is no longer printed on one line, aligning the example and the derivation is no longer useful. It can actually be harmful, as it makes the overall structure less clear. * src/derivation.h, src/derivation.c (derivation_print_leaves): Remove the `prefix` argument. * src/counterexample.c (print_counterexample): Put the example next to its label. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust. --- src/counterexample.c | 8 ++--- src/derivation.c | 3 +- src/derivation.h | 2 +- tests/conflicts.at | 16 ++++----- tests/counterexample.at | 80 ++++++++++++++++++++--------------------- tests/diagnostics.at | 20 +++++------ tests/report.at | 24 ++++++------- 7 files changed, 76 insertions(+), 77 deletions(-) diff --git a/src/counterexample.c b/src/counterexample.c index 06ebcd6c..7df75d64 100644 --- a/src/counterexample.c +++ b/src/counterexample.c @@ -116,9 +116,9 @@ static void print_counterexample (const counterexample *cex, FILE *out, const char *prefix) { const bool flat = getenv ("YYFLAT"); - fprintf (out, " %s%-20s ", + fprintf (out, flat ? " %s%-20s " : " %s%s: ", prefix, cex->unifying ? _("Example") : _("First example")); - derivation_print_leaves (cex->d1, out, prefix); + derivation_print_leaves (cex->d1, out); fprintf (out, flat ? " %s%-20s " : " %s%s", prefix, cex->shift_reduce ? _("Shift derivation") : _("First derivation")); derivation_print (cex->d1, out, prefix); @@ -128,9 +128,9 @@ print_counterexample (const counterexample *cex, FILE *out, const char *prefix) // to see the differences. if (!cex->unifying || is_styled (stderr)) { - fprintf (out, " %s%-20s ", + fprintf (out, flat ? " %s%-20s " : " %s%s: ", prefix, cex->unifying ? _("Example") : _("Second example")); - derivation_print_leaves (cex->d2, out, prefix); + derivation_print_leaves (cex->d2, out); } fprintf (out, flat ? " %s%-20s " : " %s%s", prefix, cex->shift_reduce ? _("Reduce derivation") : _("Second derivation")); diff --git a/src/derivation.c b/src/derivation.c index 5ad5a1c8..1e0ff4b7 100644 --- a/src/derivation.c +++ b/src/derivation.c @@ -428,10 +428,9 @@ derivation_print_flat (const derivation *deriv, FILE *out, const char *prefix) } void -derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix) +derivation_print_leaves (const derivation *deriv, FILE *out) { int counter = 0; - fputs (prefix, out); derivation_print_flat_impl ((derivation *)deriv, out, true, &counter, ""); fputc ('\n', out); } diff --git a/src/derivation.h b/src/derivation.h index 62676368..4dfba945 100644 --- a/src/derivation.h +++ b/src/derivation.h @@ -64,7 +64,7 @@ static inline derivation *derivation_new_leaf (symbol_number sym) // Number of symbols. size_t derivation_size (const derivation *deriv); void derivation_print (const derivation *deriv, FILE *out, const char *prefix); -void derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix); +void derivation_print_leaves (const derivation *deriv, FILE *out); void derivation_free (derivation *deriv); void derivation_retain (derivation *deriv); diff --git a/tests/conflicts.at b/tests/conflicts.at index 187085c3..1cfae5b1 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -864,7 +864,7 @@ State 5 shift/reduce conflict on token OP: 1 exp: exp OP exp . 1 exp: exp . OP exp - Example exp OP exp . OP exp + Example: exp OP exp . OP exp Shift derivation exp `-> exp OP exp @@ -1212,7 +1212,7 @@ State 1 reduce/reduce conflict on token $end: 3 num: '0' . 4 id: '0' . - Example '0' . + Example: '0' . First derivation exp `-> num @@ -1767,12 +1767,12 @@ State 4 shift/reduce conflict on token 'a': 10 reported_conflicts: . %empty 8 reported_conflicts: . 'a' - First example resolved_conflict . 'a' 'a' + First example: resolved_conflict . 'a' 'a' Shift derivation start `-> resolved_conflict reported_conflicts 'a' `-> . 'a' - Second example resolved_conflict . 'a' + Second example: resolved_conflict . 'a' Reduce derivation start `-> resolved_conflict reported_conflicts 'a' @@ -1781,12 +1781,12 @@ State 4 shift/reduce conflict on token 'a': 10 reported_conflicts: . %empty 9 reported_conflicts: . 'a' - First example resolved_conflict . 'a' 'a' + First example: resolved_conflict . 'a' 'a' Shift derivation start `-> resolved_conflict reported_conflicts 'a' `-> . 'a' - Second example resolved_conflict . 'a' + Second example: resolved_conflict . 'a' Reduce derivation start `-> resolved_conflict reported_conflicts 'a' @@ -1806,7 +1806,7 @@ State 5 reduce/reduce conflict on token 'a': 8 reported_conflicts: 'a' . 9 reported_conflicts: 'a' . - Example 'a' . + Example: 'a' . First derivation reported_conflicts `-> 'a' . @@ -1996,7 +1996,7 @@ AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0, reduce/reduce conflict on token 'c': 12 empty_c2: . %empty 13 empty_c3: . %empty - Example . 'c' + Example: . 'c' First derivation start `-> empty_c2 'c' diff --git a/tests/counterexample.at b/tests/counterexample.at index f371ad14..97c72401 100644 --- a/tests/counterexample.at +++ b/tests/counterexample.at @@ -55,7 +55,7 @@ y: A | A B; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example A . B C + Example: A . B C Shift derivation s `-> y c @@ -95,7 +95,7 @@ bc: B bc C | B C; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example A . B C + Example: A . B C Shift derivation s `-> ac @@ -107,7 +107,7 @@ input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] `-> a bc `-> A . `-> B C input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example A A . B B C C + Example: A A . B B C C Shift derivation s `-> ac @@ -157,7 +157,7 @@ xby: B | X xby Y; AT_BISON_CHECK_CEX( [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example A . B + Example: A . B Shift derivation s `-> A xby @@ -168,14 +168,14 @@ input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] `-> A x `-> B y `-> . `-> %empty input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - First example A X . B Y $end + First example: A X . B Y $end Shift derivation $accept `-> s $end `-> A xby `-> X xby Y `-> . B - Second example A X . B y $end + Second example: A X . B y $end Reduce derivation $accept `-> s $end @@ -220,14 +220,14 @@ bc: B C; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token C [-Wcounterexamples] - First example B . C $end + First example: B . C $end Shift derivation $accept `-> g $end `-> x `-> bc `-> B . C - Second example B . C D $end + Second example: B . C D $end Reduce derivation $accept `-> g $end @@ -265,14 +265,14 @@ y: A A B; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] - First example A . A B $end + First example: A . A B $end Shift derivation $accept `-> s $end `-> t `-> y `-> A . A B - Second example A . A $end + Second example: A . A $end Reduce derivation $accept `-> s $end @@ -314,7 +314,7 @@ y: Y; AT_BISON_CHECK_CEX( [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] - Example b . A X X Y + Example: b . A X X Y Shift derivation a `-> s @@ -326,13 +326,13 @@ input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] `-> b . `-> A x xy `-> X `-> X Y input.y: warning: shift/reduce conflict on token X [-Wcounterexamples] - First example A X . X + First example: A X . X Shift derivation a `-> t `-> A xx `-> X . X - Second example X . X xy + Second example: X . X xy Reduce derivation a `-> x t @@ -372,7 +372,7 @@ b : A | b; AT_BISON_CHECK_CEX( [[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr] input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] - Example A b . + Example: A b . First derivation a `-> A b . @@ -409,13 +409,13 @@ b: D; AT_BISON_CHECK_CEX( [[input.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: reduce/reduce conflict on tokens A, C [-Wcounterexamples] - First example D . A $end + First example: D . A $end First derivation $accept `-> s $end `-> a A `-> D . - Second example B D . A $end + Second example: B D . A $end Second derivation $accept `-> s $end @@ -452,13 +452,13 @@ AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] time limit exceeded: XXX - First example H i . J K $end + First example: H i . J K $end Shift derivation $accept `-> a $end `-> H i `-> i . J K - Second example H i . J $end + Second example: H i . J $end Reduce derivation $accept `-> s $end @@ -499,7 +499,7 @@ b: A B C | A B D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example N A . B C + Example: N A . B C Shift derivation s `-> n @@ -511,7 +511,7 @@ input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] `-> N a B `-> A . input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] - Example N N A . B D C + Example: N N A . B D C Shift derivation s `-> n @@ -562,7 +562,7 @@ C : A c A; AT_BISON_CHECK_CEX( [[input.y: warning: 4 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples] - Example B . b c + Example: B . b c First derivation S `-> B C @@ -576,7 +576,7 @@ input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples] `-> A b A `-> . `-> %empty input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples] - Example C . c b + Example: C . c b First derivation S `-> C B @@ -622,13 +622,13 @@ AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: 6 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] - First example . c A A $end + First example: . c A A $end First derivation $accept `-> a $end `-> b d `-> . `-> c A A - Second example . c A A $end + Second example: . c A A $end Second derivation $accept `-> a $end @@ -636,7 +636,7 @@ input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] `-> . `-> c A A input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] time limit exceeded: XXX - First example b . c A A $end + First example: b . c A A $end First derivation $accept `-> a $end @@ -644,7 +644,7 @@ time limit exceeded: XXX `-> a `-> b d `-> . `-> c A A - Second example b . A $end + Second example: b . A $end Second derivation $accept `-> a $end @@ -653,7 +653,7 @@ time limit exceeded: XXX `-> . input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] time limit exceeded: XXX - First example c . c A A $end + First example: c . c A A $end First derivation $accept `-> a $end @@ -661,7 +661,7 @@ time limit exceeded: XXX `-> a `-> b d `-> . `-> c A A - Second example c . A $end + Second example: c . A $end Second derivation $accept `-> a $end @@ -670,12 +670,12 @@ time limit exceeded: XXX `-> . input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] time limit exceeded: XXX - First example b c . A + First example: b c . A Shift derivation a `-> b d `-> c . A - Second example b c . c A A $end + Second example: b c . c A A $end Reduce derivation $accept `-> a $end @@ -686,7 +686,7 @@ time limit exceeded: XXX `-> b d `-> . `-> c A A input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] - First example b c . c A A $end + First example: b c . c A A $end First derivation $accept `-> a $end @@ -696,7 +696,7 @@ input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] `-> a `-> b d `-> . `-> c A A - Second example b c . A $end + Second example: b c . A $end Second derivation $accept `-> a $end @@ -706,12 +706,12 @@ input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] `-> c A `-> . input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] - First example b c . A + First example: b c . A Shift derivation a `-> b d `-> c . A - Second example b c . A $end + Second example: b c . A $end Reduce derivation $accept `-> a $end @@ -721,7 +721,7 @@ input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] `-> c A `-> . input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] - Example b d . + Example: b d . First derivation a `-> b d . @@ -730,7 +730,7 @@ input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] `-> b d `-> d . input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] - Example c d . + Example: c d . First derivation a `-> c d . @@ -810,7 +810,7 @@ i: %empty | i J; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] - Example H i J . J J + Example: H i J . J J Shift derivation s `-> a J @@ -854,7 +854,7 @@ d: D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] - Example A a . D + Example: A a . D Shift derivation s `-> A a d @@ -896,13 +896,13 @@ d: D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] - First example A a . D $end + First example: A a . D $end Shift derivation $accept `-> s $end `-> A a d `-> . D - Second example A a . D E $end + Second example: A a . D E $end Reduce derivation $accept `-> s $end diff --git a/tests/diagnostics.at b/tests/diagnostics.at index ffec2928..d92e8bf4 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -536,45 +536,45 @@ exp [1], [[input.y: error: shift/reduce conflicts: 4 found, 0 expected input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] - Example exp "+" exp "+" exp + Example: exp "+" exp "+" exp Shift derivation exp exp "+" exp exp "+" exp - Example exp "+" exp "+" exp + Example: exp "+" exp "+" exp Reduce derivation exp exp "+" exp exp "+" exp input.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples] - Example "if" exp "then" "if" exp "then" exp "else" exp + Example: "if" exp "then" "if" exp "then" exp "else" exp Shift derivation exp "if" exp "then" exp "if" exp "then" exp "else" exp - Example "if" exp "then" "if" exp "then" exp "else" exp + Example: "if" exp "then" "if" exp "then" exp "else" exp Reduce derivation exp "if" exp "then" exp "else" exp "if" exp "then" exp input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] - Example "if" exp "then" exp "+" exp + Example: "if" exp "then" exp "+" exp Shift derivation exp "if" exp "then" exp exp "+" exp - Example "if" exp "then" exp "+" exp + Example: "if" exp "then" exp "+" exp Reduce derivation exp exp "+" exp "if" exp "then" exp input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] - Example "if" exp "then" exp "else" exp "+" exp + Example: "if" exp "then" exp "else" exp "+" exp Shift derivation exp "if" exp "then" exp "else" exp exp "+" exp - Example "if" exp "then" exp "else" exp "+" exp + Example: "if" exp "then" exp "else" exp "+" exp Reduce derivation exp exp "+" exp @@ -618,7 +618,7 @@ input.y:31.4: warning: empty rule without %empty [-W | %empty input.y: error: reduce/reduce conflicts: 1 found, 0 expected input.y: warning: reduce/reduce conflict on token "X" [-Wcounterexamples] - Example "X" "X" "quuux" "X" + Example: "X" "X" "quuux" "X" First derivation exp x1 e1 foo1 x1 @@ -628,7 +628,7 @@ input.y: warning: reduce/reduce conflict on token "X" [x2"quuux" x3 "X" - Example "X" "X" "quuux" "X" + Example: "X" "X" "quuux" "X" Second derivation exp y1 e2 bar1 y1 diff --git a/tests/report.at b/tests/report.at index 645c3b57..8d0a210b 100644 --- a/tests/report.at +++ b/tests/report.at @@ -1538,7 +1538,7 @@ AT_CHECK([LC_ALL="$locale" bison -fno-caret -o input.cc -rall -Wcex --graph=inpu [[input.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] - Example exp "+" exp • "⊕" exp + Example: exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp @@ -1548,7 +1548,7 @@ input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] ↳ exp "⊕" exp ↳ exp "+" exp • input.y: warning: reduce/reduce conflict on tokens $end, "+", "⊕" [-Wcounterexamples] - Example exp "+" exp • + Example: exp "+" exp • First derivation exp ↳ exp "+" exp • @@ -1556,7 +1556,7 @@ input.y: warning: reduce/reduce conflict on tokens $end, "+", "⊕" [-Wcounterex exp ↳ exp "+" exp • input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] - Example exp "+" exp • "⊕" exp + Example: exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp @@ -1566,7 +1566,7 @@ input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] ↳ exp "⊕" exp ↳ exp "+" exp • input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] - Example exp "⊕" exp • "⊕" exp + Example: exp "⊕" exp • "⊕" exp Shift derivation exp ↳ exp "⊕" exp @@ -1576,7 +1576,7 @@ input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] ↳ exp "⊕" exp ↳ exp "⊕" exp • input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] - Example exp "⊕" exp • "+" exp + Example: exp "⊕" exp • "+" exp Shift derivation exp ↳ exp "⊕" exp @@ -1586,7 +1586,7 @@ input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] ↳ exp "+" exp ↳ exp "⊕" exp • input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] - Example exp "⊕" exp • "+" exp + Example: exp "⊕" exp • "+" exp Shift derivation exp ↳ exp "⊕" exp @@ -1742,7 +1742,7 @@ State 7 shift/reduce conflict on token "⊕": 2 exp: exp "+" exp • 1 exp: exp • "⊕" exp - Example exp "+" exp • "⊕" exp + Example: exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp @@ -1755,7 +1755,7 @@ State 7 reduce/reduce conflict on tokens $end, "+", "⊕": 2 exp: exp "+" exp • 3 exp: exp "+" exp • - Example exp "+" exp • + Example: exp "+" exp • First derivation exp ↳ exp "+" exp • @@ -1766,7 +1766,7 @@ State 7 shift/reduce conflict on token "⊕": 3 exp: exp "+" exp • 1 exp: exp • "⊕" exp - Example exp "+" exp • "⊕" exp + Example: exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp @@ -1795,7 +1795,7 @@ State 8 shift/reduce conflict on token "⊕": 1 exp: exp "⊕" exp • 1 exp: exp • "⊕" exp - Example exp "⊕" exp • "⊕" exp + Example: exp "⊕" exp • "⊕" exp Shift derivation exp ↳ exp "⊕" exp @@ -1808,7 +1808,7 @@ State 8 shift/reduce conflict on token "+": 1 exp: exp "⊕" exp • 2 exp: exp • "+" exp - Example exp "⊕" exp • "+" exp + Example: exp "⊕" exp • "+" exp Shift derivation exp ↳ exp "⊕" exp @@ -1821,7 +1821,7 @@ State 8 shift/reduce conflict on token "+": 1 exp: exp "⊕" exp • 3 exp: exp • "+" exp - Example exp "⊕" exp • "+" exp + Example: exp "⊕" exp • "+" exp Shift derivation exp ↳ exp "⊕" exp