diff options
| -rw-r--r-- | src/LexLua.cxx | 65 | 
1 files changed, 48 insertions, 17 deletions
| diff --git a/src/LexLua.cxx b/src/LexLua.cxx index fc9607e25..b7920ef20 100644 --- a/src/LexLua.cxx +++ b/src/LexLua.cxx @@ -23,8 +23,6 @@  #include "Scintilla.h"  #include "SciLexer.h" -#define SCE_LUA_LAST_STYLE	SCE_LUA_WORD6 -  static inline bool IsAWordChar(const int ch) {  	return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');  } @@ -61,14 +59,16 @@ static void ColouriseLuaDoc(  	WordList &keywords5 = *keywordlists[4];  	WordList &keywords6 = *keywordlists[5]; -	// Must initialize the literal string nesting level, if we are inside such a string. +	int currentLine = styler.GetLine(startPos); +	// Initialize the literal string [[ ... ]] nesting level, if we are inside such a string.  	int literalStringLevel = 0;  	if (initStyle == SCE_LUA_LITERALSTRING) { -		literalStringLevel = 1; +		literalStringLevel = styler.GetLineState(currentLine - 1);  	} -	// We use states above the last one to indicate nesting level of literal strings -	if (initStyle > SCE_LUA_LAST_STYLE) { -		literalStringLevel = initStyle - SCE_LUA_LAST_STYLE + 1; +	// Initialize the block comment --[[ ... ]] nesting level, if we are inside such a comment +	int blockCommentLevel = 0; +	if (initStyle == SCE_LUA_COMMENT) { +		blockCommentLevel = styler.GetLineState(currentLine - 1);  	}  	// Do not leak onto next line @@ -78,9 +78,28 @@ static void ColouriseLuaDoc(  	StyleContext sc(startPos, length, initStyle, styler);  	if (startPos == 0 && sc.ch == '#') { +		// shbang line: # is a comment only if first char of the script  		sc.SetState(SCE_LUA_COMMENTLINE);  	}  	for (; sc.More(); sc.Forward()) { +		if (sc.atLineEnd) { +			// Update the line state, so it can be seen by next line +			currentLine = styler.GetLine(sc.currentPos); +			switch (sc.state) { +			case SCE_LUA_LITERALSTRING: +				// Inside a literal string, we set the line state +				styler.SetLineState(currentLine, literalStringLevel); +				break; +			case SCE_LUA_COMMENT: 	// Block comment +				// Inside a block comment, we set the line state +				styler.SetLineState(currentLine, blockCommentLevel); +				break; +			default: +				// Reset the line state +				styler.SetLineState(currentLine, 0); +				break; +			} +		}  		if (sc.atLineStart && (sc.state == SCE_LUA_STRING)) {  			// Prevent SCE_LUA_STRINGEOL from leaking back to previous line  			sc.SetState(SCE_LUA_STRING); @@ -88,7 +107,7 @@ static void ColouriseLuaDoc(  		// Handle string line continuation  		if ((sc.state == SCE_LUA_STRING || sc.state == SCE_LUA_CHARACTER) && -				sc.ch == '\\') { +		        sc.ch == '\\') {  			if (sc.chNext == '\n' || sc.chNext == '\r') {  				sc.Forward();  				if (sc.ch == '\r' && sc.chNext == '\n') { @@ -154,22 +173,31 @@ static void ColouriseLuaDoc(  				sc.ChangeState(SCE_LUA_STRINGEOL);  				sc.ForwardSetState(SCE_LUA_DEFAULT);  			} -		} else if (sc.state == SCE_LUA_LITERALSTRING || sc.state > SCE_LUA_LAST_STYLE) { +		} else if (sc.state == SCE_LUA_LITERALSTRING) {  			if (sc.Match('[', '[')) {  				literalStringLevel++; -				sc.SetState(SCE_LUA_LAST_STYLE + literalStringLevel - 1); +				sc.Forward(); +				sc.SetState(SCE_LUA_LITERALSTRING);  			} else if (sc.Match(']', ']') && literalStringLevel > 0) {  				literalStringLevel--;  				sc.Forward();  				if (literalStringLevel == 0) {  					sc.ForwardSetState(SCE_LUA_DEFAULT); -				} else if (literalStringLevel == 1) { -					sc.ForwardSetState(SCE_LUA_LITERALSTRING); -				} else { -					sc.ForwardSetState(SCE_LUA_LAST_STYLE + literalStringLevel - 1); +				} +			} +		} else if (sc.state == SCE_LUA_COMMENT) {	// Lua 5.0's block comment +			if (sc.Match('[', '[')) { +				blockCommentLevel++; +				sc.Forward(); +			} else if (sc.Match(']', ']') && blockCommentLevel > 0) { +				blockCommentLevel--; +				sc.Forward(); +				if (blockCommentLevel == 0) { +					sc.ForwardSetState(SCE_LUA_DEFAULT);  				}  			}  		} +  		// Determine if a new state should be entered.  		if (sc.state == SCE_LUA_DEFAULT) {  			if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { @@ -184,12 +212,16 @@ static void ColouriseLuaDoc(  				literalStringLevel = 1;  				sc.SetState(SCE_LUA_LITERALSTRING);  				sc.Forward(); +			} else if (sc.Match("--[[")) {	// Lua 5.0's block comment +				blockCommentLevel = 1; +				sc.SetState(SCE_LUA_COMMENT); +				sc.Forward(3);  			} else if (sc.Match('-', '-')) {  				sc.SetState(SCE_LUA_COMMENTLINE);  				sc.Forward(); -			} else if (sc.Match('$') && sc.atLineStart) { +			} else if (sc.atLineStart && sc.Match('$')) {  				sc.SetState(SCE_LUA_PREPROCESSOR);	// Obsolete since Lua 4.0, but still in old code -			}  else if (isLuaOperator(static_cast<char>(sc.ch))) { +			} else if (isLuaOperator(static_cast<char>(sc.ch))) {  				sc.SetState(SCE_LUA_OPERATOR);  			}  		} @@ -197,7 +229,6 @@ static void ColouriseLuaDoc(  	sc.Complete();  } -  static void FoldLuaDoc(unsigned int startPos, int length, int /* initStyle */, WordList *[],                         Accessor &styler) {  	unsigned int lengthDoc = startPos + length; | 
