diff options
author | nyamatongwe <unknown> | 2010-09-09 11:18:35 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2010-09-09 11:18:35 +1000 |
commit | 8f0402d382bf34b074fbda1898321eb3b8851801 (patch) | |
tree | 0e6e76a79ab0aab7c1312cc50572833d2fc03c51 /lexers/LexCPP.cxx | |
parent | 02d51bfa77118e379d026e82c3a855dc260c9a72 (diff) | |
download | scintilla-mirror-8f0402d382bf34b074fbda1898321eb3b8851801.tar.gz |
Fix for bug #3062287 JavaScript lexer: recognize regexes following return keyword.
Diffstat (limited to 'lexers/LexCPP.cxx')
-rw-r--r-- | lexers/LexCPP.cxx | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index 0698ed920..bbcd0e3aa 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -67,6 +67,29 @@ static bool FollowsPostfixOperator(StyleContext &sc, LexAccessor &styler) { return false; } +static bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { + // Don't look at styles, so no need to flush. + int pos = (int) sc.currentPos; + int currentLine = styler.GetLine(pos); + int lineStartPos = styler.LineStart(currentLine); + char ch; + while (--pos > lineStartPos) { + ch = styler.SafeGetCharAt(pos); + if (ch != ' ' && ch != '\t') { + break; + } + } + const char *retBack = "nruter"; + const char *s = retBack; + while (*s + && pos >= lineStartPos + && styler.SafeGetCharAt(pos) == *s) { + s++; + pos--; + } + return !*s; +} + static std::string GetRestOfLine(LexAccessor &styler, int start, bool allowSpace) { std::string restOfLine; int i =0; @@ -701,8 +724,11 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, sc.SetState(SCE_C_COMMENTLINEDOC|activitySet); else sc.SetState(SCE_C_COMMENTLINE|activitySet); - } else if (sc.ch == '/' && setOKBeforeRE.Contains(chPrevNonWhite) && - (!setCouldBePostOp.Contains(chPrevNonWhite) || !FollowsPostfixOperator(sc, styler))) { + } else if (sc.ch == '/' + && (setOKBeforeRE.Contains(chPrevNonWhite) + || followsReturnKeyword(sc, styler)) + && (!setCouldBePostOp.Contains(chPrevNonWhite) + || !FollowsPostfixOperator(sc, styler))) { sc.SetState(SCE_C_REGEX|activitySet); // JavaScript's RegEx } else if (sc.ch == '\"') { sc.SetState(SCE_C_STRING|activitySet); |