scintillua icon indicating copy to clipboard operation
scintillua copied to clipboard

lexer/rest.lua wrong handling of multiple line comments

Open mcepl opened this issue 4 months ago • 1 comments

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

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

mcepl avatar Feb 14 '24 19:02 mcepl

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)

orbitalquark avatar Feb 15 '24 02:02 orbitalquark