orbitalquark / scintillua

Scintillua enables Scintilla lexers to be written in Lua, particularly using LPeg. It can also be used as a standalone Lua library for syntax highlighting support.
https://orbitalquark.github.io/scintillua
MIT License
53 stars 22 forks source link

lexer/rest.lua wrong handling of multiple line comments #107

Open mcepl opened 9 months ago

mcepl commented 9 months ago

Talking about rST files, this is a wrong highlighting of a “commented out” paragraph.

screenshot-2023-11-02_22-11-1698961336

orbitalquark commented 9 months ago

Thanks for the report. The reST lexer really needs a refactor, and I'm not even sure significant newlines can be lexed properly since Scintillua doesn't always backtrack over newlines.

Does the following diff work for you? If it does, I can commit it. It doesn't work for me, but I'm using a GUI editor that typically starts lexing on newlines and doesn't always lex chunks as you'd expect.

--- lexers/lexer.lua
+++ lexers/lexer.lua
@@ -111,11 +111,11 @@
 lex:add_style('substitution', lexer.styles.variable)

 -- Comments.
 local line_comment = lexer.to_eol(prefix)
 local bprefix = any_indent * '..'
 local block_comment = bprefix * lexer.newline * indented_block
-lex:add_rule('comment', #bprefix * token(lexer.COMMENT, starts_line(line_comment + block_comment)))
+lex:add_rule('comment', #bprefix * token(lexer.COMMENT, starts_line(block_comment + line_comment)))

 -- Section titles (2 or more characters).
 local adornment_chars = lpeg.C(S('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'))
 local adornment = lpeg.C(adornment_chars^2 * any_indent) * (lexer.newline + -1)