diff options
-rw-r--r-- | include/SciLexer.h | 5 | ||||
-rw-r--r-- | include/Scintilla.iface | 5 | ||||
-rw-r--r-- | src/LexLua.cxx | 89 |
3 files changed, 61 insertions, 38 deletions
diff --git a/include/SciLexer.h b/include/SciLexer.h index 622840995..d87af9faa 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -247,6 +247,11 @@ #define SCE_LUA_OPERATOR 10 #define SCE_LUA_IDENTIFIER 11 #define SCE_LUA_STRINGEOL 12 +#define SCE_LUA_WORD2 13 +#define SCE_LUA_WORD3 14 +#define SCE_LUA_WORD4 15 +#define SCE_LUA_WORD5 16 +#define SCE_LUA_WORD6 17 #define SCE_ERR_DEFAULT 0 #define SCE_ERR_PYTHON 1 #define SCE_ERR_GCC 2 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 51686f184..0a2bcd569 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1557,6 +1557,11 @@ val SCE_LUA_PREPROCESSOR=9 val SCE_LUA_OPERATOR=10 val SCE_LUA_IDENTIFIER=11 val SCE_LUA_STRINGEOL=12 +val SCE_LUA_WORD2=13 +val SCE_LUA_WORD3=14 +val SCE_LUA_WORD4=15 +val SCE_LUA_WORD5=16 +val SCE_LUA_WORD6=17 # Lexical states for SCLEX_ERRORLIST val SCE_ERR_DEFAULT=0 val SCE_ERR_PYTHON=1 diff --git a/src/LexLua.cxx b/src/LexLua.cxx index 2791d98ad..747a3d588 100644 --- a/src/LexLua.cxx +++ b/src/LexLua.cxx @@ -4,6 +4,7 @@ ** ** Written by Paul Winwood. ** Folder by Alexey Yutkin. + ** Modified by Marcos E. Wurzius **/ #include <stdlib.h> @@ -35,37 +36,19 @@ inline bool isLuaOperator(char ch) { return false; } -static void classifyWordLua(unsigned int start, - unsigned int end, - WordList &keywords, - Accessor &styler) { - char s[100]; - bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.'); - - for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; - s[i + 1] = '\0'; - } - - char chAttr = SCE_LUA_IDENTIFIER; - - if (wordIsNumber) - chAttr = SCE_LUA_NUMBER; - else { - if (keywords.InList(s)) { - chAttr = SCE_LUA_WORD; - } - } - styler.ColourTo(end, chAttr); -} static void ColouriseLuaDoc(unsigned int startPos, int length, int initStyle, - WordList *keywordlists[], + WordList *keywordLists[], Accessor &styler) { - WordList &keywords = *keywordlists[0]; + WordList &keywords = *keywordLists[0]; + WordList &keywords2 = *keywordLists[1]; + WordList &keywords3 = *keywordLists[2]; + WordList &keywords4 = *keywordLists[3]; + WordList &keywords5 = *keywordLists[4]; + WordList &keywords6 = *keywordLists[5]; styler.StartAt(startPos); styler.GetLine(startPos); @@ -119,8 +102,7 @@ static void ColouriseLuaDoc(unsigned int startPos, } else if (ch == '$' && firstChar) { styler.ColourTo(i - 1, state); state = SCE_LUA_PREPROCESSOR; - } else if (ch == '#' && firstChar) // Should be only on the first line of the file! Cannot be tested here - { + } else if (ch == '#' && firstChar) { // Should be only on the first line of the file! Cannot be tested here styler.ColourTo(i - 1, state); state = SCE_LUA_COMMENTLINE; } else if (isLuaOperator(ch)) { @@ -131,9 +113,40 @@ static void ColouriseLuaDoc(unsigned int startPos, state = SCE_LUA_WORD; } } else if (state == SCE_LUA_WORD) { - if (!iswordchar(ch)) { - classifyWordLua(styler.GetStartSegment(), i - 1, keywords, styler); + if (!iswordchar(ch) || (ch == '.')) { + char s[100]; + unsigned int start = styler.GetStartSegment(); + unsigned int end = i - 1; + bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.'); + + for (unsigned int n = 0; n < end - start + 1 && n < 30; n++) { + s[n] = styler[start + n]; + s[n + 1] = '\0'; + } + + char chAttr = SCE_LUA_IDENTIFIER; + + if (wordIsNumber) { + chAttr = SCE_LUA_NUMBER; + } else { + if (keywords.InList(s)) { + chAttr = SCE_LUA_WORD; + } else if (keywords2.InList(s)) { + chAttr = SCE_LUA_WORD2; + } else if (keywords3.InList(s)) { + chAttr = SCE_LUA_WORD3 ; + } else if (keywords4.InList(s)) { + chAttr = SCE_LUA_WORD4 ; + } else if (keywords5.InList(s)) { + chAttr = SCE_LUA_WORD5 ; + } else if (keywords6.InList(s)) { + chAttr = SCE_LUA_WORD6 ; + } + } + styler.ColourTo(end, chAttr); + state = SCE_LUA_DEFAULT; + if (ch == '[' && chNext == '[') { literalString = 1; state = SCE_LUA_LITERALSTRING; @@ -148,10 +161,6 @@ static void ColouriseLuaDoc(unsigned int startPos, } else if (isLuaOperator(ch)) { styler.ColourTo(i, SCE_LUA_OPERATOR); } - } else if (ch == '.' && chNext == '.') { - classifyWordLua(styler.GetStartSegment(), i - 1, keywords, styler); - styler.ColourTo(i, SCE_LUA_OPERATOR); - state = SCE_LUA_DEFAULT; } } else { if (state == SCE_LUA_LITERALSTRING) { @@ -227,6 +236,7 @@ static void ColouriseLuaDoc(unsigned int startPos, styler.ColourTo(lengthDoc - 1, state); } + static void FoldLuaDoc(unsigned int startPos, int length, int /* initStyle */, WordList *[], Accessor &styler) { unsigned int lengthDoc = startPos + length; @@ -244,19 +254,21 @@ static void FoldLuaDoc(unsigned int startPos, int length, int /* initStyle */, W styleNext = styler.StyleAt(i + 1); bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); if (style == SCE_LUA_WORD) - if ( ch == 'e' || ch == 't' || ch == 'd' || ch == 'f') { + if ( ch == 'i' || ch == 'e' || ch == 't' || ch == 'd' || ch == 'f') { for (unsigned int j = 0; j < 8; j++) { - if (!iswordchar(styler[i + j])) break; + if (!iswordchar(styler[i + j])) + break; s[j] = styler[i + j]; s[j + 1] = '\0'; } - if ((strcmp(s, "then") == 0) || (strcmp(s, "do") == 0) + if ((strcmp(s, "if") == 0) || (strcmp(s, "do") == 0) || (strcmp(s, "function") == 0)) levelCurrent++; - if (strcmp(s, "end") == 0) levelCurrent--; - } + if ((strcmp(s, "end") == 0) || (strcmp(s, "elseif") == 0)) + levelCurrent--; + } if (atEOL) { int lev = levelPrev; if (visibleChars == 0) @@ -274,6 +286,7 @@ static void FoldLuaDoc(unsigned int startPos, int length, int /* initStyle */, W visibleChars++; } // Fill in the real level of the next line, keeping the current flags as they will be filled in later + int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; styler.SetLevel(lineCurrent, levelPrev | flagsNext); } |