zig-mode
zig-mode copied to clipboard
Multiline string ending with blank line breaks highlighting and indentation.
If a multiline string ends with just a newline, highlighting after it is borked:
PR #46 fixed a lot of multiline strings for me, but sometimes they are still broken:
This example was taken from zig/test/stage2/test.zig
. It seems that the syntax assigner is not aggressive enough and doesn't continue from the first backslash in some cases.
Another issue that seems to come from the multiline string handling is that ordinary string/codepoint literals beginning with \\
confuse it; for example:
const bad_str = "\\";
const foo = 1;
// syntax reset: ";
const bad_cp = '\\';
const blah = 2;
// syntax reset: ';
// `syntax-ppss' seems to completely miss the above comments
Comes out as:
(Warning: I don't actually know Zig yet, but zig check-ast
doesn't see any issues so hopefully this is a reasonable testcase?)
According to describe-char
, the first \
in each literal has syntax |
, presumably from the syntax-table
property. I think the syntax based fontification sees the quotation mark starting the literal, ignores the first backslash because it's of class |
(string fence), then considers the second one with class \
as escaping the quote that should end the literal.
If the first \
had been left with its normal syntax, I believe it would have been considered to escape the second one, allowing the terminating quote to do its job.
I guess the string is considered to start AFTER (not at) the quotation mark, and it's necessary to check (nth 5 (syntax-ppss))
to distinguish multiline literals from those using quotation marks?