diagnostics: fix styling issues

Single point locations (equal boundaries) are troublesome, and we were
incorrectly ending the style in their case.  Which results in an abort
in libtextstyle.

There is also a confusion between columns as displayed on the
screen (which take into account multibyte characters and tabulations),
and the number of bytes.  Counting the screen-column
incrementally (character by character) is uneasy (because of multibyte
characters), and I don't want to maintain a buffer of the current line
when displaying the diagnostic.  So I believe the simplest solution is
to track the byte number in addition to the screen column.

* src/location.h, src/location.c (boundary): Add the byte-column.
Adjust dependencies.
* src/getargs.c, src/scan-gram.l: Adjust.
* tests/diagnostics.at: Check zero-width locations.
This commit is contained in:
Akim Demaille
2019-04-20 18:25:21 +02:00
parent 520d474ec6
commit 1b70f687fa
8 changed files with 86 additions and 29 deletions

View File

@@ -28,11 +28,11 @@ AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]], [$2])
AT_DATA([experr], [$3])
AT_BISON_CHECK([-fcaret --style=debug -Wother input.y], [], [], [experr])
AT_BISON_CHECK([-fcaret --style=debug -Wall input.y], [], [], [experr])
# When no style, same messages, except the style.
AT_CHECK([perl -pi -e 's{</?\w+>}{}g' experr])
AT_BISON_CHECK([-fcaret -Wother input.y], [], [], [experr])
AT_BISON_CHECK([-fcaret -Wall input.y], [], [], [experr])
AT_BISON_OPTION_POPDEFS
@@ -48,7 +48,7 @@ AT_TEST([[Warnings]],
[[%token FOO FOO FOO
%token FOO FOO FOO
%%
exp:;
exp: %empty;
]],
[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
%token FOO <warning>FOO</warning> FOO
@@ -68,4 +68,43 @@ input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared [<warning>-W
]])
## ------------------------ ##
## Single point locations. ##
## ------------------------ ##
# Single point locations (equal boundaries) are troublesome: it's easy
# to mess up the opening/closing of style. They come from the parser,
# rules with empty rhs. Their position is therefore debatable
# (between the previous token and the next one).
AT_TEST([[Single point locations]],
[[%%
exp: a b c d e
a: {}
b:{
};
c:
d
:
e:
]],
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
a: <warning>{}</warning>
<warning>^~</warning>
input.y:12.3-13.1: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
b:<warning>{</warning>
<warning>^</warning>
input.y:14.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
c<warning>:</warning>
<warning>^</warning>
input.y:15.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
d
<warning>^</warning>
input.y:17.2: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
e<warning>:</warning>
<warning>^</warning>
]])
m4_popdef([AT_TEST])