mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 10:13:03 +00:00
diagnostics: give m4 precise locations
Currently we pass only the columns based on the screen-width, which is important for the carets. But we don't pass the bytes-based columns, which is important for the colors. Pass both. * src/muscle-tab.c (muscle_boundary_grow): Also pass the byte-based column. * src/location.c (location_caret): Clarify. (boundary_set_from_string): Adjust to the new format. * tests/diagnostics.at (Tabulations and multibyte characters from M4): New.
This commit is contained in:
@@ -238,8 +238,8 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
int c = getc (caret_info.source);
|
int c = getc (caret_info.source);
|
||||||
if (c != EOF)
|
if (c != EOF)
|
||||||
{
|
{
|
||||||
/* Quote the file (at most first line in the case of multiline
|
/* Quote the file (at most the first line in the case of
|
||||||
location). Indent by a single column. */
|
multiline locations). */
|
||||||
fprintf (out, "%5d | ", loc.start.line);
|
fprintf (out, "%5d | ", loc.start.line);
|
||||||
bool single_line = loc.start.line == loc.end.line;
|
bool single_line = loc.start.line == loc.end.line;
|
||||||
/* Consider that single point location (with equal boundaries)
|
/* Consider that single point location (with equal boundaries)
|
||||||
@@ -269,9 +269,9 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
putc ('^', out);
|
putc ('^', out);
|
||||||
/* Underlining a multiline location ends with the first
|
/* Underlining a multiline location ends with the first
|
||||||
line. */
|
line. */
|
||||||
int len = loc.start.line != loc.end.line
|
int len = single_line
|
||||||
? ftell (caret_info.source) - caret_info.offset
|
? loc.end.column
|
||||||
: loc.end.column;
|
: ftell (caret_info.source) - caret_info.offset;
|
||||||
for (int i = loc.start.column + 1; i < len; ++i)
|
for (int i = loc.start.column + 1; i < len; ++i)
|
||||||
putc ('~', out);
|
putc ('~', out);
|
||||||
end_use_class (style, out);
|
end_use_class (style, out);
|
||||||
@@ -289,17 +289,29 @@ location_empty (location loc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
boundary_set_from_string (boundary *bound, char *loc_str)
|
boundary_set_from_string (boundary *bound, char *str)
|
||||||
{
|
{
|
||||||
/* Must search in reverse since the file name field may
|
/* Must search in reverse since the file name field may contain '.'
|
||||||
* contain '.' or ':'. */
|
or ':'. */
|
||||||
char *delim = strrchr (loc_str, '.');
|
char *at = strrchr (str, '@');
|
||||||
aver (delim);
|
if (at)
|
||||||
*delim = '\0';
|
{
|
||||||
bound->byte = bound->column = atoi (delim+1);
|
*at = '\0';
|
||||||
delim = strrchr (loc_str, ':');
|
bound->byte = atoi (at+1);
|
||||||
aver (delim);
|
}
|
||||||
*delim = '\0';
|
{
|
||||||
bound->line = atoi (delim+1);
|
char *dot = strrchr (str, '.');
|
||||||
bound->file = uniqstr_new (loc_str);
|
aver (dot);
|
||||||
|
*dot = '\0';
|
||||||
|
bound->column = atoi (dot+1);
|
||||||
|
if (!at)
|
||||||
|
bound->byte = bound->column;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char *colon = strrchr (str, ':');
|
||||||
|
aver (colon);
|
||||||
|
*colon = '\0';
|
||||||
|
bound->line = atoi (colon+1);
|
||||||
|
}
|
||||||
|
bound->file = uniqstr_new (str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ location_cmp (location a, location b)
|
|||||||
/* Whether this is the empty location. */
|
/* Whether this is the empty location. */
|
||||||
bool location_empty (location loc);
|
bool location_empty (location loc);
|
||||||
|
|
||||||
/* LOC_STR must be formatted as 'file:line.column', it will be modified. */
|
/* STR must be formatted as 'file:line.column@byte' or 'file:line.column',
|
||||||
void boundary_set_from_string (boundary *bound, char *loc_str);
|
it will be modified. */
|
||||||
|
void boundary_set_from_string (boundary *bound, char *str);
|
||||||
|
|
||||||
#endif /* ! defined LOCATION_H_ */
|
#endif /* ! defined LOCATION_H_ */
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ muscle_boundary_grow (char const *key, boundary bound)
|
|||||||
{
|
{
|
||||||
obstack_sgrow (&muscle_obstack, "[[");
|
obstack_sgrow (&muscle_obstack, "[[");
|
||||||
obstack_escape (&muscle_obstack, bound.file);
|
obstack_escape (&muscle_obstack, bound.file);
|
||||||
obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
|
obstack_printf (&muscle_obstack, ":%d.%d@@%d]]", bound.line, bound.column, bound.byte);
|
||||||
char const *extension = obstack_finish0 (&muscle_obstack);
|
char const *extension = obstack_finish0 (&muscle_obstack);
|
||||||
muscle_grow (key, extension, "", "");
|
muscle_grow (key, extension, "", "");
|
||||||
obstack_free (&muscle_obstack, extension);
|
obstack_free (&muscle_obstack, extension);
|
||||||
|
|||||||
@@ -33,16 +33,18 @@ AT_BISON_OPTION_PUSHDEFS
|
|||||||
|
|
||||||
AT_DATA_GRAMMAR([[input.y]], [$2])
|
AT_DATA_GRAMMAR([[input.y]], [$2])
|
||||||
|
|
||||||
AT_DATA([experr], [$4])
|
AT_DATA([experr.orig], [$4])
|
||||||
|
|
||||||
|
# When no style, same messages, but without style.
|
||||||
|
AT_CHECK([perl -p -e 's{</?\w+>}{}g' <experr.orig >experr])
|
||||||
# Cannot use AT_BISON_CHECK easily as we need to change the
|
# Cannot use AT_BISON_CHECK easily as we need to change the
|
||||||
# environment.
|
# environment.
|
||||||
# FIXME: Enhance AT_BISON_CHECK.
|
# FIXME: Enhance AT_BISON_CHECK.
|
||||||
AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --style=debug -Wall input.y], [$3], [], [experr])
|
|
||||||
|
|
||||||
# When no style, same messages, but without style.
|
|
||||||
AT_CHECK([perl -pi -e 's{</?\w+>}{}g' experr])
|
|
||||||
AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [$3], [], [experr])
|
AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [$3], [], [experr])
|
||||||
|
|
||||||
|
AT_CHECK([cp experr.orig experr])
|
||||||
|
AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --style=debug -Wall input.y], [$3], [], [experr])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -212,4 +214,29 @@ input.y:9.1-24: previous definition
|
|||||||
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
## ---------------------------------------------- ##
|
||||||
|
## Tabulations and multibyte characters from M4. ##
|
||||||
|
## ---------------------------------------------- ##
|
||||||
|
|
||||||
|
# Locations coming from m4 need the byte-column for diagnostics.
|
||||||
|
|
||||||
|
AT_TEST([[Locations from M4]],
|
||||||
|
[[%define api.prefix {sun}
|
||||||
|
%define api.prefix {🌞}
|
||||||
|
%%
|
||||||
|
exp:;
|
||||||
|
]],
|
||||||
|
[1],
|
||||||
|
[[input.y:10.1-35: <error>error:</error> %define variable 'api.prefix' redefined
|
||||||
|
10 | <error>%define api.prefix {🌞}</error>
|
||||||
|
| <error>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</error>
|
||||||
|
input.y:9.1-37: previous definition
|
||||||
|
9 | <note>%define api.prefix {sun}</note>
|
||||||
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
|
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||||
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m4_popdef([AT_TEST])
|
m4_popdef([AT_TEST])
|
||||||
|
|||||||
Reference in New Issue
Block a user