ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
179 stars 64 forks source link

Fix lexing of nested comments; remove unused variable #258

Closed mgusg closed 1 month ago

mgusg commented 2 months ago

Fix a bug which caused improper lexing of nested block comments. Add a regression test for block comments and single-line comments. Remove unused variable visibleChars in LexerABL::Lex.

nyamatongwe commented 2 months ago

The test requires a SciTE.properties file in the same directory to specify the lexer to test and turn on folding. Something similar to

lexer.*.p=abl
fold=1

Removing visibleChars means that the local function IsSpaceEquiv is no longer called and should be removed to avoid warnings.

../lexers/LexProgress.cxx:51:9: warning: 'bool {anonymous}::IsSpaceEquiv(int)' defined but not used [-Wunused-function]
   51 |    bool IsSpaceEquiv(int state) {
      |         ^~~~~~~~~~~~

cppcheck shows a new warning for the look back loop. It may be possible to simplify this code.

lexilla\lexers\LexProgress.cxx:271:14: warning: Condition 'checkIsSentenceStart' is always true [knownConditionTrueFalse]
         if (checkIsSentenceStart && st != SCE_ABL_COMMENT && st != SCE_ABL_LINECOMMENT && st != SCE_ABL_CHARACTER  && st != SCE_ABL_STRING ) {
             ^
lexilla\lexers\LexProgress.cxx:264:27: note: Assuming that condition 'checkIsSentenceStart' is not redundant
      while (back >= 0 && checkIsSentenceStart) {
                          ^
lexilla\lexers\LexProgress.cxx:271:14: note: Condition 'checkIsSentenceStart' is always true
         if (checkIsSentenceStart && st != SCE_ABL_COMMENT && st != SCE_ABL_LINECOMMENT && st != SCE_ABL_CHARACTER  && st != SCE_ABL_STRING ) {
             ^
mgusg commented 2 months ago

Thanks for the feedback. I added the missing SciTE.properties file and resolved the issues reported by cppcheck.

nyamatongwe commented 2 months ago

In SciTE.properties you likely want the keyword 'DISPLAY' to be lowercase so that these are lexed to SCE_ABL_WORD (2) instead of SCE_ABL_IDENTIFIER (7). This lexer implements case-insensitive keywords by converting words to lowercase then searching in a list. This will never match 'DISPLAY'.

mgusg commented 2 months ago

I changed the keyword to lowercase and updated the .styled file. Thank you for the thorough review.