aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2011-08-05 11:14:43 +1000
committernyamatongwe <devnull@localhost>2011-08-05 11:14:43 +1000
commit1429e6853794fb0cf5c47d791145306652fbb746 (patch)
treef1c89da459413c135cd4f1d900dfee2b10b467fc
parenta1bfde560cca71dde47fcf48b03e230a1d9a7312 (diff)
downloadscintilla-mirror-1429e6853794fb0cf5c47d791145306652fbb746.tar.gz
Lua lexer update for Lua 5.2 beta. Feature #3386330.
(a) \* escapes in strings changed to \z (b) goto <label> highlighting for same line only (c) :: <label> :: highlighting for same line only From Kein-Hong Man.
-rw-r--r--include/SciLexer.h1
-rw-r--r--include/Scintilla.iface1
-rw-r--r--lexers/LexLua.cxx82
3 files changed, 78 insertions, 6 deletions
diff --git a/include/SciLexer.h b/include/SciLexer.h
index 1d5b69ede..c7d79aa2c 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -428,6 +428,7 @@
#define SCE_LUA_WORD6 17
#define SCE_LUA_WORD7 18
#define SCE_LUA_WORD8 19
+#define SCE_LUA_LABEL 20
#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 36ead0ece..92393cd66 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2779,6 +2779,7 @@ val SCE_LUA_WORD5=16
val SCE_LUA_WORD6=17
val SCE_LUA_WORD7=18
val SCE_LUA_WORD8=19
+val SCE_LUA_LABEL=20
# Lexical states for SCLEX_ERRORLIST
lex ErrorList=SCLEX_ERRORLIST SCE_ERR_
val SCE_ERR_DEFAULT=0
diff --git a/lexers/LexLua.cxx b/lexers/LexLua.cxx
index 1dc9d4058..0bf4aeea2 100644
--- a/lexers/LexLua.cxx
+++ b/lexers/LexLua.cxx
@@ -59,7 +59,7 @@ static void ColouriseLuaDoc(
// Accepts accented characters
CharacterSet setWordStart(CharacterSet::setAlpha, "_", 0x80, true);
- CharacterSet setWord(CharacterSet::setAlphaNum, "._", 0x80, true);
+ CharacterSet setWord(CharacterSet::setAlphaNum, "_", 0x80, true);
// Not exactly following number definition (several dots are seen as OK, etc.)
// but probably enough in most cases. [pP] is for hex floats.
CharacterSet setNumber(CharacterSet::setDigits, ".-+abcdefpABCDEFP");
@@ -71,7 +71,7 @@ static void ColouriseLuaDoc(
// Initialize long string [[ ... ]] or block comment --[[ ... ]] nesting level,
// if we are inside such a string. Block comment was introduced in Lua 5.0,
// blocks with separators [=[ ... ]=] in Lua 5.1.
- // Continuation of a string (\* whitespace escaping) is controlled by stringWs.
+ // Continuation of a string (\z whitespace escaping) is controlled by stringWs.
int nestLevel = 0;
int sepCount = 0;
int stringWs = 0;
@@ -130,6 +130,61 @@ static void ColouriseLuaDoc(
// Determine if the current state should terminate.
if (sc.state == SCE_LUA_OPERATOR) {
+ if (sc.ch == ':' && sc.chPrev == ':') { // :: <label> :: forward scan
+ sc.Forward();
+ int ln = 0, maxln = startPos + length - sc.currentPos;
+ int c;
+ while (ln < maxln) { // determine line extent
+ c = sc.GetRelative(ln);
+ if (c == '\r' || c == '\n')
+ break;
+ ln++;
+ }
+ maxln = ln; ln = 0;
+ while (ln < maxln) { // skip over spaces/tabs
+ if (!IsASpaceOrTab(sc.GetRelative(ln)))
+ break;
+ ln++;
+ }
+ int ws1 = ln;
+ if (setWordStart.Contains(sc.GetRelative(ln))) {
+ int i = 0;
+ char s[100];
+ while (ln < maxln) { // get potential label
+ c = sc.GetRelative(ln);
+ if (!setWord.Contains(c))
+ break;
+ if (i < 90)
+ s[i++] = c;
+ ln++;
+ }
+ s[i] = '\0'; int lbl = ln;
+ if (!keywords.InList(s)) {
+ while (ln < maxln) { // skip over spaces/tabs
+ if (!IsASpaceOrTab(sc.GetRelative(ln)))
+ break;
+ ln++;
+ }
+ int ws2 = ln - lbl;
+ if (sc.GetRelative(ln) == ':' && sc.GetRelative(ln + 1) == ':') {
+ // final :: found, complete valid label construct
+ sc.ChangeState(SCE_LUA_LABEL);
+ if (ws1) {
+ sc.SetState(SCE_LUA_DEFAULT);
+ sc.Forward(ws1);
+ }
+ sc.SetState(SCE_LUA_LABEL);
+ sc.Forward(lbl - ws1);
+ if (ws2) {
+ sc.SetState(SCE_LUA_DEFAULT);
+ sc.Forward(ws2);
+ }
+ sc.SetState(SCE_LUA_LABEL);
+ sc.Forward(2);
+ }
+ }
+ }
+ }
sc.SetState(SCE_LUA_DEFAULT);
} else if (sc.state == SCE_LUA_NUMBER) {
// We stop the number definition on non-numerical non-dot non-eEpP non-sign non-hexdigit char
@@ -140,11 +195,26 @@ static void ColouriseLuaDoc(
sc.SetState(SCE_LUA_DEFAULT);
}
} else if (sc.state == SCE_LUA_IDENTIFIER) {
- if (!setWord.Contains(sc.ch) || sc.Match('.', '.')) {
+ if (!(setWord.Contains(sc.ch) || sc.ch == '.') || sc.Match('.', '.')) {
char s[100];
sc.GetCurrent(s, sizeof(s));
if (keywords.InList(s)) {
sc.ChangeState(SCE_LUA_WORD);
+ if (strcmp(s, "goto") == 0) { // goto <label> forward scan
+ sc.SetState(SCE_LUA_DEFAULT);
+ while (IsASpaceOrTab(sc.ch))
+ sc.Forward();
+ if (setWordStart.Contains(sc.ch)) {
+ sc.SetState(SCE_LUA_LABEL);
+ sc.Forward();
+ while (setWord.Contains(sc.ch))
+ sc.Forward();
+ sc.GetCurrent(s, sizeof(s));
+ if (keywords.InList(s))
+ sc.ChangeState(SCE_LUA_WORD);
+ }
+ sc.SetState(SCE_LUA_DEFAULT);
+ }
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_LUA_WORD2);
} else if (keywords3.InList(s)) {
@@ -174,7 +244,7 @@ static void ColouriseLuaDoc(
if (sc.ch == '\\') {
if (setEscapeSkip.Contains(sc.chNext)) {
sc.Forward();
- } else if (sc.chNext == '*') {
+ } else if (sc.chNext == 'z') {
sc.Forward();
stringWs = 0x100;
}
@@ -192,7 +262,7 @@ static void ColouriseLuaDoc(
if (sc.ch == '\\') {
if (setEscapeSkip.Contains(sc.chNext)) {
sc.Forward();
- } else if (sc.chNext == '*') {
+ } else if (sc.chNext == 'z') {
sc.Forward();
stringWs = 0x100;
}
@@ -269,7 +339,7 @@ static void ColouriseLuaDoc(
}
}
- if (setWord.Contains(sc.chPrev)) {
+ if (setWord.Contains(sc.chPrev) || sc.chPrev == '.') {
char s[100];
sc.GetCurrent(s, sizeof(s));
if (keywords.InList(s)) {