ziglang / zig-mode

Zig mode for Emacs
GNU General Public License v3.0
163 stars 54 forks source link

Multiline string ending with blank line breaks highlighting and indentation. #22

Closed nmichaels closed 4 months ago

nmichaels commented 4 years ago

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

image

joachimschmidt557 commented 3 years ago

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.

SamB commented 9 months ago

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?