orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
624 stars 38 forks source link

Bash lexer issue with escaping # ( \# ) #511

Closed oOosys closed 4 months ago

oOosys commented 4 months ago

issue_bashLexer

Note: SciTE does it the right way ...

orbitalquark commented 4 months ago

Thanks for the report. I'll fix this when I get the chance.

oOosys commented 4 months ago

... Thanks for the reply. No urge in fixing ... if it were very important to me I would have sure already provided a fix myself. Just wanted to mention this issue for the sake of it.

orbitalquark commented 4 months ago

Fixed in https://github.com/orbitalquark/scintillua/commit/f971ac5e7ac411309038edf5e9fce135490ad559

oOosys commented 4 months ago

OK ... it works like a charm :) and it was so easy to fix, that it can't be called a bug or issue but a simple oversight in first place, so it appears a bit strange that it wasn't over the years yet reported.

May you please explain a bit the mechanism used in this fix? It appears to demonstrate how to include exceptions from a rule triggered by a pattern by specifying a prefix one with -B('CharacterOrStringOrAnyRegex?') to the pattern to_eol('CharacterOrStringOrAnyRegex?'):

lex:add_rule('comment', lex:tag(lexer.COMMENT, -B('\\') * lexer.to_eol('#')))

I mean learning how things work by fixing issues is a much better way to make progress in understanding the underlying mechanisms than reading the manuals ...

orbitalquark commented 4 months ago

It's kind of like regex look-behind. LPeg matches '#' (in lexer.to_eol('#')), but only if it's not preceded by a '\' character.