diff options
author | nyamatongwe <devnull@localhost> | 2005-11-29 23:27:02 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2005-11-29 23:27:02 +0000 |
commit | 83bb994a8224e7522ce1a7879c3b1c45f0358d26 (patch) | |
tree | 97549fd70adc2bbcac37fc33f245dd48d09a1bab | |
parent | 59e22670668008e778778c30432e0c75bdf11d37 (diff) | |
download | scintilla-mirror-83bb994a8224e7522ce1a7879c3b1c45f0358d26.tar.gz |
Patch from Kein-Hong Man improves regular expression detection
when disambiguating character on previous line or separated from
'/' by a comment.
Includes trailing lowercase regex flags in the regex style.
-rw-r--r-- | src/LexCPP.cxx | 39 | ||||
-rw-r--r-- | src/LexHTML.cxx | 29 |
2 files changed, 56 insertions, 12 deletions
diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx index cd2755243..40f3a60bd 100644 --- a/src/LexCPP.cxx +++ b/src/LexCPP.cxx @@ -36,10 +36,17 @@ static inline bool IsAWordStart(int ch) { } static inline bool IsADoxygenChar(int ch) { - return (islower(ch) || ch == '$' || ch == '@' || - ch == '\\' || ch == '&' || ch == '<' || - ch == '>' || ch == '#' || ch == '{' || - ch == '}' || ch == '[' || ch == ']'); + return (ch < 0x80 && islower(ch)) || ch == '$' || ch == '@' || + ch == '\\' || ch == '&' || ch == '<' || + ch == '>' || ch == '#' || ch == '{' || + ch == '}' || ch == '[' || ch == ']'; +} + +static bool IsSpaceEquiv(int state) { + return (state <= SCE_C_COMMENTDOC) || + // including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE + (state == SCE_C_COMMENTLINEDOC) || (state == SCE_C_COMMENTDOCKEYWORD) || + (state == SCE_C_COMMENTDOCKEYWORDERROR); } static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], @@ -74,6 +81,16 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo } } + // look back to set chPrevNonWhite properly for better regex colouring + if (startPos > 0) { + int back = startPos; + while (--back && IsSpaceEquiv(styler.StyleAt(back))) + ; + if (styler.StyleAt(back) == SCE_C_OPERATOR) { + chPrevNonWhite = styler.SafeGetCharAt(back); + } + } + StyleContext sc(startPos, length, initStyle, styler); for (; sc.More(); sc.Forward()) { @@ -86,7 +103,6 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo } // Reset states to begining of colourise so no surprises // if different sets of lines lexed. - chPrevNonWhite = ' '; visibleChars = 0; lastWordWasUUID = false; } @@ -224,7 +240,10 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo if (sc.atLineStart) { sc.SetState(SCE_C_DEFAULT); } else if (sc.ch == '/') { - sc.ForwardSetState(SCE_C_DEFAULT); + sc.Forward(); + while ((sc.ch < 0x80) && islower(sc.ch)) + sc.Forward(); // gobble regex flags + sc.SetState(SCE_C_DEFAULT); } else if (sc.ch == '\\') { // Gobble up the quoted character if (sc.chNext == '\\' || sc.chNext == '/') { @@ -305,7 +324,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo } } - if (!IsASpace(sc.ch)) { + if (!IsASpace(sc.ch) && !IsSpaceEquiv(sc.state)) { chPrevNonWhite = sc.ch; visibleChars++; } @@ -316,9 +335,9 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo static bool IsStreamCommentStyle(int style) { return style == SCE_C_COMMENT || - style == SCE_C_COMMENTDOC || - style == SCE_C_COMMENTDOCKEYWORD || - style == SCE_C_COMMENTDOCKEYWORDERROR; + style == SCE_C_COMMENTDOC || + style == SCE_C_COMMENTDOCKEYWORD || + style == SCE_C_COMMENTDOCKEYWORDERROR; } // Store both the current line's fold level and the next lines in the diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx index b822852a5..a268c2b0d 100644 --- a/src/LexHTML.cxx +++ b/src/LexHTML.cxx @@ -2,7 +2,7 @@ /** @file LexHTML.cxx ** Lexer for HTML. **/ -// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org> +// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org> // The License.txt file describes the conditions under which this software may be distributed. #include <stdlib.h> @@ -503,12 +503,28 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty char chPrev = ' '; char ch = ' '; char chPrevNonWhite = ' '; + // look back to set chPrevNonWhite properly for better regex colouring + if (scriptLanguage == eScriptJS && startPos > 0) { + int back = startPos; + int style = 0; + while (--back) { + style = styler.StyleAt(back); + if (style < SCE_HJ_DEFAULT || style > SCE_HJ_COMMENTDOC) + // includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE + break; + } + if (style == SCE_HJ_SYMBOLS) { + chPrevNonWhite = styler.SafeGetCharAt(back); + } + } + styler.StartSegment(startPos); const int lengthDoc = startPos + length; for (int i = startPos; i < lengthDoc; i++) { const char chPrev2 = chPrev; chPrev = ch; - if (ch != ' ' && ch != '\t') + if (!isspacechar(ch) && state != SCE_HJ_COMMENT && + state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC) chPrevNonWhite = ch; ch = styler[i]; char chNext = styler.SafeGetCharAt(i + 1); @@ -1236,12 +1252,14 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty if (ch == '/' && chPrev == '*') { styler.ColourTo(i, StateToPrint); state = SCE_HJ_DEFAULT; + ch = ' '; } break; case SCE_HJ_COMMENTLINE: if (ch == '\r' || ch == '\n') { styler.ColourTo(i - 1, statePrintForState(SCE_HJ_COMMENTLINE, inScriptType)); state = SCE_HJ_DEFAULT; + ch = ' '; } break; case SCE_HJ_DOUBLESTRING: @@ -1289,6 +1307,13 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty break; case SCE_HJ_REGEX: if (ch == '\r' || ch == '\n' || ch == '/') { + if (ch == '/') { + while (chNext < 0x80 && islower(chNext)) { // gobble regex flags + i++; + ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + } + } styler.ColourTo(i, StateToPrint); state = SCE_HJ_DEFAULT; } else if (ch == '\\') { |