[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] diagnostics: give m4 precise locations
From: |
Akim Demaille |
Subject: |
[PATCH 4/4] diagnostics: give m4 precise locations |
Date: |
Sat, 27 Apr 2019 18:15:56 +0200 |
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.
---
src/location.c | 44 +++++++++++++++++++++++++++-----------------
src/muscle-tab.c | 2 +-
tests/diagnostics.at | 37 ++++++++++++++++++++++++++++++++-----
3 files changed, 60 insertions(+), 23 deletions(-)
diff --git a/src/location.c b/src/location.c
index e2299c2e..6f10c78b 100644
--- a/src/location.c
+++ b/src/location.c
@@ -238,8 +238,8 @@ location_caret (location loc, const char *style, FILE *out)
int c = getc (caret_info.source);
if (c != EOF)
{
- /* Quote the file (at most first line in the case of multiline
- location). Indent by a single column. */
+ /* Quote the file (at most the first line in the case of
+ multiline locations). */
fprintf (out, "%5d | ", loc.start.line);
bool single_line = loc.start.line == loc.end.line;
/* Consider that single point location (with equal boundaries)
@@ -269,9 +269,9 @@ location_caret (location loc, const char *style, FILE *out)
putc ('^', out);
/* Underlining a multiline location ends with the first
line. */
- int len = loc.start.line != loc.end.line
- ? ftell (caret_info.source) - caret_info.offset
- : loc.end.column;
+ int len = single_line
+ ? loc.end.column
+ : ftell (caret_info.source) - caret_info.offset;
for (int i = loc.start.column + 1; i < len; ++i)
putc ('~', out);
end_use_class (style, out);
@@ -289,17 +289,27 @@ location_empty (location loc)
}
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
- * contain '.' or ':'. */
- char *delim = strrchr (loc_str, '.');
- aver (delim);
- *delim = '\0';
- bound->byte = bound->column = atoi (delim+1);
- delim = strrchr (loc_str, ':');
- aver (delim);
- *delim = '\0';
- bound->line = atoi (delim+1);
- bound->file = uniqstr_new (loc_str);
+ /* Must search in reverse since the file name field may contain '.'
+ or ':'. */
+ {
+ char *at = strrchr (str, '@');
+ aver (at);
+ *at = '\0';
+ bound->byte = atoi (at+1);
+ }
+ {
+ char *dot = strrchr (str, '.');
+ aver (dot);
+ *dot = '\0';
+ bound->column = atoi (dot+1);
+ }
+ {
+ char *colon = strrchr (str, ':');
+ aver (colon);
+ *colon = '\0';
+ bound->line = atoi (colon+1);
+ }
+ bound->file = uniqstr_new (str);
}
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index cd4beeb2..fbb80fc2 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -275,7 +275,7 @@ muscle_boundary_grow (char const *key, boundary bound)
{
obstack_sgrow (&muscle_obstack, "[[");
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);
muscle_grow (key, extension, "", "");
obstack_free (&muscle_obstack, extension);
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index 282d9b35..57f645a3 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -33,16 +33,18 @@ AT_BISON_OPTION_PUSHDEFS
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
# environment.
# 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([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_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>]
]])
+
+## ---------------------------------------------- ##
+## 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])
--
2.21.0