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.
This commit is contained in:
Akim Demaille
2020-05-23 19:13:01 +02:00
parent 296e2f90ab
commit ae5edcc23b
5 changed files with 197 additions and 147 deletions

View File

@@ -103,21 +103,18 @@ static void
print_counterexample (counterexample *cex)
{
FILE *out = stderr;
if (cex->unifying)
fprintf (out, "Example ");
else
fprintf (out, "First Example ");
fprintf (out, "%-20s ", cex->unifying ? _("Example") : _("First example"));
derivation_print_leaves (cex->d1, out);
fprintf (out, "\nFirst derivation ");
fprintf (out, "%-20s ", _("First derivation"));
derivation_print (cex->d1, out);
if (!cex->unifying)
{
fprintf (out, "\nSecond Example ");
derivation_print_leaves (cex->d2, out);
}
fprintf (out, "\nSecond derivation ");
fprintf (out, "%-20s ", cex->unifying ? _("Example") : _("Second example"));
derivation_print_leaves (cex->d2, out);
fprintf (out, "%-20s ", _("Second derivation"));
derivation_print (cex->d2, out);
fputs ("\n\n", out);
fputc ('\n', out);
}
/*