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

@@ -49,15 +49,21 @@ typedef struct
*/
int column;
/* If nonnegative, (origin-0) bytes number in the current line.
Never displayed, used when printing error messages with colors to
know where colors start and ends. */
int byte;
} boundary;
/* Set the position of \a a. */
/* Set the position of \a p. */
static inline void
boundary_set (boundary *b, const char *f, int l, int c)
boundary_set (boundary *p, const char *f, int l, int c, int b)
{
b->file = f;
b->line = l;
b->column = c;
p->file = f;
p->line = l;
p->column = c;
p->byte = b;
}
/* Return -1, 0, 1, depending whether a is before, equal, or
@@ -95,7 +101,7 @@ typedef struct
# define GRAM_LTYPE location
# define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
# define EMPTY_LOCATION_INIT {{NULL, 0, 0, 0}, {NULL, 0, 0, 0}}
extern location const empty_location;
/* Set *LOC and adjust scanner cursor to account for token TOKEN of