zig-mode icon indicating copy to clipboard operation
zig-mode copied to clipboard

Multiline string ending with blank line breaks highlighting and indentation.

Open nmichaels opened this issue 5 years ago • 2 comments

If a multiline string ends with just a newline, highlighting after it is borked:

image

nmichaels avatar Jan 09 '20 17:01 nmichaels

PR #46 fixed a lot of multiline strings for me, but sometimes they are still broken:

image

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.

joachimschmidt557 avatar Oct 22 '20 20:10 joachimschmidt557

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:

Screenshot_20231104-153631

(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?

SamB avatar Nov 04 '23 20:11 SamB