diagnostics: beware of zero-width characters

Currenly we rely on (visual) width of the characters to decide where
to open and close the styling of the quoted lines.  This breaks when
we deal with zero-width characters: we cannot just rely on (visual)
columns, we need to know whether we are before, inside, or after the
highlighted portion.

* src/location.c (location_caret): col_end: no longer add 1, "regular"
characters have a width of 1, only 0-width characters have 0-width.
opened: replace with 'state', a three-valued enum.
Don't reopen the style if we already did.
* tests/diagnostics.at (Zero-width characters): New.
This commit is contained in:
Akim Demaille
2020-03-07 12:59:09 +01:00
parent e21ff47f5d
commit b638603477
3 changed files with 45 additions and 23 deletions

View File

@@ -42,16 +42,14 @@ typedef struct
/* If positive, the column (starting at 1) just after the boundary.
This is neither a byte count, nor a character count; it is a
column count. If this is INT_MAX, the column number has
(visual) column count. If this is INT_MAX, the column number has
overflowed.
Meaningless and not displayed if nonpositive.
*/
Meaningless and not displayed if nonpositive. */
int column;
/* If nonnegative, the byte number (starting at 0) in the current line.
Never displayed, used when printing error messages with colors to
know where colors start and end. */
/* If nonnegative, the byte number (starting at 0) in the current
line. Not displayed (unless --trace=location). */
int byte;
} boundary;