[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/4] diagnostics: fix locations coming from M4
From: |
Akim Demaille |
Subject: |
[PATCH 3/4] diagnostics: fix locations coming from M4 |
Date: |
Sat, 27 Apr 2019 18:15:55 +0200 |
Locations issued from M4 need the byte-based column for the
diagnostics to work properly. Currently they were unassigned, which
typically resulted in partially non-colored diagnostics.
* src/location.c (boundary_set_from_string): Fix the parsed location.
* src/muscle-tab.c (muscle_percent_define_default): Set the byte values.
* tests/diagnostics.at (Locations from M4): New.
---
src/location.c | 2 +-
src/muscle-tab.c | 8 +++++---
tests/diagnostics.at | 39 ++++++++++++++++++++++++++++++++-------
3 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/src/location.c b/src/location.c
index 2c56e0cf..e2299c2e 100644
--- a/src/location.c
+++ b/src/location.c
@@ -296,7 +296,7 @@ boundary_set_from_string (boundary *bound, char *loc_str)
char *delim = strrchr (loc_str, '.');
aver (delim);
*delim = '\0';
- bound->column = atoi (delim+1);
+ bound->byte = bound->column = atoi (delim+1);
delim = strrchr (loc_str, ':');
aver (delim);
*delim = '\0';
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index a8cec20e..cd4beeb2 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -710,9 +710,11 @@ muscle_percent_define_default (char const *variable, char
const *value)
{
uniqstr loc_name = muscle_name (variable, "loc");
location loc;
- loc.start.file = loc.end.file = "<default value>";
- loc.start.line = loc.end.line = -1;
- loc.start.column = loc.end.column = -1;
+ loc.start.file = "<default value>";
+ loc.start.line = -1;
+ loc.start.column = -1;
+ loc.start.byte = -1;
+ loc.end = loc.start;
muscle_insert (loc_name, "");
muscle_location_grow (loc_name, loc);
}
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index 773982ff..282d9b35 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -18,8 +18,8 @@
AT_BANNER([[Diagnostics.]])
-# AT_TEST([TITLE], [GRAMMAR], [OUTPUT-WITH-STYLE])
-# ------------------------------------------------
+# AT_TEST($1: TITLE, $2: GRAMMAR, $3: EXIT-STATUS, $4: OUTPUT-WITH-STYLE)
+# -----------------------------------------------------------------------
m4_pushdef([AT_TEST],
[
AT_SETUP([$1])
@@ -33,15 +33,15 @@ AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]], [$2])
-AT_DATA([experr], [$3])
+AT_DATA([experr], [$4])
# 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], [],
[], [experr])
+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], [], [], [experr])
+AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [$3], [], [experr])
AT_BISON_OPTION_POPDEFS
@@ -59,6 +59,7 @@ AT_TEST([[Warnings]],
%%
exp: %empty;
]],
+[0],
[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared
[<warning>-Wother</warning>]
9 | %token FOO <warning>FOO</warning> FOO
| <warning>^~~</warning>
@@ -97,6 +98,7 @@ d
:
e:
]],
+[0],
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty
[<warning>-Wempty-rule</warning>]
11 | a: <warning>{}</warning>
| <warning>^~</warning>
@@ -135,6 +137,7 @@ f: { 42 }
g: { "฿¥$€₦" }
h: { 🐃 }
]],
+[0],
[[input.y:11.4-17: <warning>warning:</warning> empty rule without %empty
[<warning>-Wempty-rule</warning>]
11 | a: <warning>{ }</warning>
| <warning>^~~~~~~~~~~~~~</warning>
@@ -163,9 +166,9 @@ input.y: <warning>warning:</warning> fix-its can be
applied. Rerun with option
]])
-## -------------- ##
+## --------------- ##
## Special files. ##
-## -------------- ##
+## --------------- ##
# Don't try to quote special files.
# http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html
@@ -178,6 +181,7 @@ a: {}
#line 1 "/dev/stdout"
b: {}
]],
+[0],
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty
[<warning>-Wempty-rule</warning>]
11 | a: <warning>{}</warning>
| <warning>^~</warning>
@@ -186,5 +190,26 @@ b: {}
]])
+## ------------------- ##
+## Locations from M4. ##
+## ------------------- ##
+
+# Locations coming from m4 need the byte-column for diagnostics.
+
+AT_TEST([[Locations from M4]],
+[[%define api.prefix {foo}
+%define api.prefix {bar}
+%%
+exp:;
+]],
+[1],
+[[input.y:10.1-24: <error>error:</error> %define variable 'api.prefix'
redefined
+ 10 | <error>%define api.prefix {bar}</error>
+ | <error>^~~~~~~~~~~~~~~~~~~~~~~~</error>
+input.y:9.1-24: previous definition
+ 9 | <note>%define api.prefix {foo}</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