diff options
| author | nyamatongwe <unknown> | 2000-11-26 01:32:57 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2000-11-26 01:32:57 +0000 | 
| commit | dcf614b69ebfebbd9dd10e8ba3cf36f3029a196f (patch) | |
| tree | 68dd386441912b9733eec915ce3084ffb1783201 /src | |
| parent | b06ccad8c14068ed9d3f37b5f6b4fa6e5ce3c7f9 (diff) | |
| download | scintilla-mirror-dcf614b69ebfebbd9dd10e8ba3cf36f3029a196f.tar.gz | |
Patches from Philippe to improve Lua lexer, handle '\' continuation
at end of line inside strings and to allow 5 digit line numbers when
printing.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Editor.cxx | 2 | ||||
| -rw-r--r-- | src/LexCPP.cxx | 2 | ||||
| -rw-r--r-- | src/LexLua.cxx | 484 | 
3 files changed, 241 insertions, 247 deletions
| diff --git a/src/Editor.cxx b/src/Editor.cxx index de4783cb3..03f09f390 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1405,7 +1405,7 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) {  	int lineNumberWidth = 0;  	if (lineNumberIndex >= 0) {  		lineNumberWidth = surface->WidthText(vsPrint.styles[STYLE_LINENUMBER].font, -		                                     "9999" lineNumberPrintSpace, 4 + strlen(lineNumberPrintSpace)); +		                                     "99999" lineNumberPrintSpace, 5 + strlen(lineNumberPrintSpace));  		vsPrint.ms[lineNumberIndex].width = lineNumberWidth;  	} diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx index bf70b0c81..014b844a7 100644 --- a/src/LexCPP.cxx +++ b/src/LexCPP.cxx @@ -216,7 +216,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo  				} else if (ch == '\"') {  					styler.ColourTo(i, state);  					state = SCE_C_DEFAULT; -				} else if (chNext == '\r' || chNext == '\n') { +				} else if ((chNext == '\r' || chNext == '\n') && (chPrev != '\\')) {  					styler.ColourTo(i-1, SCE_C_STRINGEOL);  					state = SCE_C_STRINGEOL;  				} diff --git a/src/LexLua.cxx b/src/LexLua.cxx index e6da7668d..e737c5fbb 100644 --- a/src/LexLua.cxx +++ b/src/LexLua.cxx @@ -1,5 +1,5 @@  // LexLua.cxx - lexer for Lua language -// Written by Paul Winwood  +// Written by Paul Winwood  #include <stdlib.h>  #include <string.h> @@ -16,36 +16,50 @@  #include "Scintilla.h"  #include "SciLexer.h" +inline bool isLuaOperator(char ch) { +	if (isalnum(ch)) +		return false; +	// '.' left out as it is used to make up numbers +	if (ch == '*' || ch == '/' ||ch == '-' || ch == '+' || +		ch == '(' || ch == ')' || ch == '=' || +		ch == '{' || ch == '}' || ch == '~' || +		ch == '[' || ch == ']' || ch == ';' || +		ch == '<' || ch == '>' || ch == ',' || +		ch == '^' || ch == '.' ) +			return true; +	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'; -    } +	{ +	    s[i] = styler[start + i]; +	    s[i + 1] = '\0'; +	}      char chAttr = SCE_LUA_IDENTIFIER; -     +      if (wordIsNumber) -        chAttr = SCE_LUA_NUMBER; +	    chAttr = SCE_LUA_NUMBER;      else -    { -        if (keywords.InList(s)) -        { -            chAttr = SCE_LUA_WORD; -        } -    } +	{ +	    if (keywords.InList(s)) +		{ +		    chAttr = SCE_LUA_WORD; +		} +	}      styler.ColourTo(end, chAttr);  } -static void ColouriseLuaDoc(unsigned int startPos,  -                            int          length,  -                            int          initStyle,  -                            WordList    *keywordlists[], -                            Accessor    &styler) +static void ColouriseLuaDoc(unsigned int startPos, +						    int 		 length, +						    int 		 initStyle, +						    WordList    *keywordlists[], +						    Accessor    &styler)  {      WordList &keywords = *keywordlists[0]; @@ -62,236 +76,216 @@ static void ColouriseLuaDoc(unsigned int startPos,      styler.StartSegment(startPos);      for (unsigned int i = startPos; i <= lengthDoc; i++) -    { -        char ch = chNext; -        chNext = styler.SafeGetCharAt(i + 1); +	{ +	    char ch = chNext; +	    chNext = styler.SafeGetCharAt(i + 1); -        if (styler.IsLeadByte(ch)) -        { -            chNext = styler.SafeGetCharAt(i + 2); -            chPrev = ' '; -            i += 1; -            continue; -        } +	    if (styler.IsLeadByte(ch)) +		{ +		    chNext = styler.SafeGetCharAt(i + 2); +		    chPrev = ' '; +		    i += 1; +		    continue; +		} -        if (state == SCE_LUA_STRINGEOL) -        { -            if (ch != '\r' && ch != '\n') -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_DEFAULT; -            } -        } +	    if (state == SCE_LUA_STRINGEOL) +		{ +		    if (ch != '\r' && ch != '\n') +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_DEFAULT; +			} +		} -        if (state == SCE_LUA_LITERALSTRING && ch == '[' && chNext == '[') -        { -            literalString++; -        } -        else -        if (state == SCE_LUA_DEFAULT) -        { -            if (ch == '-' && chNext == '-') -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_COMMENTLINE; -            } -            else -            if (ch == '[' && chNext == '[') -            { -                state = SCE_LUA_LITERALSTRING; -                literalString = 1; -            } -            else -            if (iswordstart(ch)) -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_WORD; -            } -            else -            if (ch == '\"') -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_STRING; -            } -            else -            if (ch == '\'') -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_CHARACTER; -            } -            else -            if (ch == '$' && firstChar) -            { -                styler.ColourTo(i-1, state); -                state = SCE_LUA_PREPROCESSOR; -            } -            else -            if (isoperator(ch)) -            { -                styler.ColourTo(i-1, state); -                styler.ColourTo(i, SCE_LUA_OPERATOR); -            } -        } -        else -        if (state == SCE_LUA_WORD) -        { -            if (!iswordchar(ch)) -            { -                classifyWordLua(styler.GetStartSegment(), i - 1, keywords, styler); -                state = SCE_LUA_DEFAULT; -                if (ch == '[' && chNext == '[') -                { -                    literalString = 1; -                    state = SCE_LUA_LITERALSTRING; -                } -                else -                if (ch == '-' && chNext == '-') -                { -                    state = SCE_LUA_COMMENTLINE; -                } -                else -                if (ch == '\"') -                { -                    state = SCE_LUA_STRING; -                } -                else -                if (ch == '\'') -                { -                    state = SCE_LUA_CHARACTER; -                } -                else -                if (ch == '$' && firstChar) -                { -                    state = SCE_LUA_PREPROCESSOR; -                } -                else -                if (isoperator(ch)) -                { -                    styler.ColourTo(i, SCE_LUA_OPERATOR); -                } -            } -        } -        else -        { -            if (state == SCE_LUA_LITERALSTRING) -            { -                if (ch == ']' && (chPrev == ']') && (--literalString == 0)) -                { -                    styler.ColourTo(i, state); -                    state = SCE_LUA_DEFAULT; -                } -            } -            else -            if (state == SCE_LUA_PREPROCESSOR) -            { -                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) -                { -                    styler.ColourTo(i-1, state); -                    state = SCE_LUA_DEFAULT; -                } -            } -            else -            if (state == SCE_LUA_COMMENTLINE) -            { -                if (ch == '\r' || ch == '\n') -                { -                    styler.ColourTo(i-1, state); -                    state = SCE_LUA_DEFAULT; -                } -            } -            else -            if (state == SCE_LUA_STRING) -            { -                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) -                { -                    styler.ColourTo(i-1, state); -                    state = SCE_LUA_STRINGEOL; -                } -                else -                if (ch == '\\') -                { -                    if (chNext == '\"' || chNext == '\\') -                    { -                        i++; -                        ch = chNext; -                        chNext = styler.SafeGetCharAt(i + 1); -                    } -                } -                else -                if (ch == '\"') -                { -                    styler.ColourTo(i, state); -                    state = SCE_LUA_DEFAULT; -                    i++; -                    ch = chNext; -                    chNext = styler.SafeGetCharAt(i + 1); -                } -            } -            else -            if (state == SCE_LUA_CHARACTER) -            { -                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) -                { -                    styler.ColourTo(i-1, state); -                    state = SCE_LUA_STRINGEOL; -                } -                else -                if (ch == '\\') -                { -                    if (chNext == '\'' || chNext == '\\') -                    { -                        i++; -                        ch = chNext; -                        chNext = styler.SafeGetCharAt(i + 1); -                    } -                } -                else -                if (ch == '\'') -                { -                    styler.ColourTo(i, state); -                    state = SCE_LUA_DEFAULT; -                    i++; -                    ch = chNext; -                    chNext = styler.SafeGetCharAt(i + 1); -                } -            } +	    if (state == SCE_LUA_LITERALSTRING && ch == '[' && chNext == '[') +		{ +		    literalString++; +		} +	    else if (state == SCE_LUA_DEFAULT) +		{ +		    if (ch == '-' && chNext == '-') +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_COMMENTLINE; +			} +		    else if (ch == '[' && chNext == '[') +			{ +			    state = SCE_LUA_LITERALSTRING; +			    literalString = 1; +			} +		    else if (ch == '\"') +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_STRING; +			} +		    else if (ch == '\'') +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_CHARACTER; +			} +		    else if (ch == '$' && firstChar) +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_PREPROCESSOR; +			} +		    else if (isLuaOperator(ch)) +			{ +			    styler.ColourTo(i-1, state); +			    styler.ColourTo(i, SCE_LUA_OPERATOR); +			} +		    else if (iswordstart(ch)) +			{ +			    styler.ColourTo(i-1, state); +			    state = SCE_LUA_WORD; +			} +		} +	    else if (state == SCE_LUA_WORD) +		{ +		    if (!iswordchar(ch)) +			{ +			    classifyWordLua(styler.GetStartSegment(), i - 1, keywords, styler); +			    state = SCE_LUA_DEFAULT; +			    if (ch == '[' && chNext == '[') +				{ +				    literalString = 1; +				    state = SCE_LUA_LITERALSTRING; +				} +			    else if (ch == '-' && chNext == '-') +				{ +				    state = SCE_LUA_COMMENTLINE; +				} +			    else if (ch == '\"') +				{ +				    state = SCE_LUA_STRING; +				} +			    else if (ch == '\'') +				{ +				    state = SCE_LUA_CHARACTER; +				} +			    else if (ch == '$' && firstChar) +				{ +				    state = SCE_LUA_PREPROCESSOR; +				} +			    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) +			{ +			    if (ch == ']' && (chPrev == ']') && (--literalString == 0)) +				{ +				    styler.ColourTo(i, state); +				    state = SCE_LUA_DEFAULT; +				} +			} +		    else if (state == SCE_LUA_PREPROCESSOR) +			{ +			    if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +				{ +				    styler.ColourTo(i-1, state); +				    state = SCE_LUA_DEFAULT; +				} +			} +		    else if (state == SCE_LUA_COMMENTLINE) +			{ +			    if (ch == '\r' || ch == '\n') +				{ +				    styler.ColourTo(i-1, state); +				    state = SCE_LUA_DEFAULT; +				} +			} +		    else if (state == SCE_LUA_STRING) +			{ +			    if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +				{ +				    styler.ColourTo(i-1, state); +				    state = SCE_LUA_STRINGEOL; +				} +			    else if (ch == '\\') +				{ +				    if (chNext == '\"' || chNext == '\\') +					{ +					    i++; +					    ch = chNext; +					    chNext = styler.SafeGetCharAt(i + 1); +					} +				} +			    else if (ch == '\"') +				{ +				    styler.ColourTo(i, state); +				    state = SCE_LUA_DEFAULT; +				    i++; +				    ch = chNext; +				    chNext = styler.SafeGetCharAt(i + 1); +				} +			} +		    else if (state == SCE_LUA_CHARACTER) +			{ +			    if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +				{ +				    styler.ColourTo(i-1, state); +				    state = SCE_LUA_STRINGEOL; +				} +			    else if (ch == '\\') +				{ +				    if (chNext == '\'' || chNext == '\\') +					{ +					    i++; +					    ch = chNext; +					    chNext = styler.SafeGetCharAt(i + 1); +					} +				} +			    else if (ch == '\'') +				{ +				    styler.ColourTo(i, state); +				    state = SCE_LUA_DEFAULT; +				    i++; +				    ch = chNext; +				    chNext = styler.SafeGetCharAt(i + 1); +				} +			} -            if (state == SCE_LUA_DEFAULT) -            {     -                if (ch == '-' && chNext == '-') -                { -                    state = SCE_LUA_COMMENTLINE; -                } -                else -                if (ch == '\"') -                { -                    state = SCE_LUA_STRING; -                } -                else -                if (ch == '\'') -                { -                    state = SCE_LUA_CHARACTER; -                } -                else -                if (ch == '$' && firstChar) -                { -                    state = SCE_LUA_PREPROCESSOR; -                } -                else -                if (iswordstart(ch)) -                { -                    state = SCE_LUA_WORD; -                } -                else -                if (isoperator(ch)) -                { -                    styler.ColourTo(i, SCE_LUA_OPERATOR); -                } -            } -        } -        chPrev = ch; -        firstChar = (ch == '\r' || ch == '\n'); -    } +		    if (state == SCE_LUA_DEFAULT) +			{ +			    if (ch == '-' && chNext == '-') +				{ +				    state = SCE_LUA_COMMENTLINE; +				} +			    else if (ch == '\"') +				{ +				    state = SCE_LUA_STRING; +				} +			    else if (ch == '\'') +				{ +				    state = SCE_LUA_CHARACTER; +				} +			    else if (ch == '$' && firstChar) +				{ +				    state = SCE_LUA_PREPROCESSOR; +				} +			    else if (iswordstart(ch)) +				{ +				    state = SCE_LUA_WORD; +				} +			    else if (isLuaOperator(ch)) +				{ +				    styler.ColourTo(i, SCE_LUA_OPERATOR); +				} +			} +		} +	    chPrev = ch; +	    firstChar = (ch == '\r' || ch == '\n'); +	}      styler.ColourTo(lengthDoc - 1, state);  } | 
