diagnostics: use libtextstyle for colored output

Bruno Haible released libtextstyle, a library for colored output based
on CSS.  Let's use it to generate colored diagnostics, provided
libtextstyle is available.

See
https://lists.gnu.org/archive/html/bug-gnulib/2019-01/msg00176.html
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00073.html
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00084.html
https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00007.html

* bootstrap.conf (gnulib_modules): Use libtextstyle when possible.
* data/diagnostics.css: New.
* src/complain.c (begin_use_class, end_use_class, flush)
(severity_style, complain_init_color): New.
Use them.
* src/getargs.c (getargs_colors): New.
(getargs): Use it.
Skip --color and --style.
* src/location.h, src/location.c (location_print): Use a style.

* tests/bison.in: Force --color=yes when stderr is a tty.
* tests/local.at: Disable colors during the test suite.
* tests/input.at: Adjust expectations to the extra options passed on
the command line.
This commit is contained in:
Akim Demaille
2019-02-14 06:49:29 +01:00
parent 855fbf1c11
commit f6e38d7ac9
13 changed files with 203 additions and 25 deletions

View File

@@ -26,6 +26,14 @@ BISON_PKGDATADIR=$abs_top_srcdir/data
export BISON_PKGDATADIR
stderr=tmp-bison.$$
# If stderr is a tty, force --color=yes to simulate --color=auto
# although we save and modify stderr.
if test -t 2; then
set x --color=yes ${1+"$@"}
shift
fi
$PREBISON "$abs_top_builddir/src/bison" ${1+"$@"} 2>"$stderr"
status=$?

View File

@@ -1807,7 +1807,7 @@ start: %empty;
]])
AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
<command line>:2: previous definition
<command line>:3: previous definition
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
@@ -1820,7 +1820,7 @@ AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
%define var "gram"
^~~~~~~~~~~~~~~~~~
<command line>:3: previous definition
<command line>:4: previous definition
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
@@ -1829,8 +1829,8 @@ AT_DATA([[input-unused.y]],
start: %empty;
]])
AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
[[<command line>:2: error: %define variable 'unused-d' is not used
<command line>:3: error: %define variable 'unused-f' is not used
[[<command line>:3: error: %define variable 'unused-d' is not used
<command line>:4: error: %define variable 'unused-f' is not used
]])
AT_CLEANUP
@@ -2251,11 +2251,11 @@ start: %empty;
# parse.lac.* options are useless if LAC isn't actually activated.
AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
[[1]], [],
[[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
[[<command line>:3: error: %define variable 'parse.lac.es-capacity-initial' is not used
]])
AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
[[1]], [],
[[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
[[<command line>:3: error: %define variable 'parse.lac.memory-trace' is not used
]])
AT_CLEANUP
@@ -2326,8 +2326,8 @@ AT_BISON_CHECK([[$2 -Wno-deprecated input.y]], [[1]], [[]],
])
AT_TEST([%define api.prefix {foo} %name-prefix "bar"], [], [input.y:1.1-24])
AT_TEST([], [-Dapi.prefix={foo} -p bar], [<command line>:2])
AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}], [<command line>:2])
AT_TEST([], [-Dapi.prefix={foo} -p bar], [<command line>:3])
AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}], [<command line>:3])
AT_TEST([%define api.prefix {foo}], [-p bar], [input.y:1.1-24])
m4_popdef([AT_TEST])

View File

@@ -807,7 +807,7 @@ AT_BISON_CHECK_NO_XML($@)])
# --------------------------------------------------
# Low-level macro to run bison once.
m4_define([AT_BISON_CHECK_],
[AT_CHECK(AT_QUELL_VALGRIND[[ bison -fno-caret ]]$@)])
[AT_CHECK(AT_QUELL_VALGRIND[[ bison --color=no -fno-caret ]]$@)])
# AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
@@ -862,7 +862,7 @@ fi]dnl
# when a tortured grammar's XML is known to be too large for xsltproc to
# handle.
m4_define([AT_BISON_CHECK_NO_XML],
[AT_CHECK(m4_null_if([$2], [], [AT_QUELL_VALGRIND ])[[bison -fno-caret ]]$@)
[AT_CHECK(m4_null_if([$2], [], [AT_QUELL_VALGRIND ])[[bison --color=no -fno-caret ]]$@)
AT_BISON_CHECK_WARNINGS($@)])
# AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])