aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexers/LexCPP.cxx
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2010-09-09 11:18:35 +1000
committernyamatongwe <devnull@localhost>2010-09-09 11:18:35 +1000
commit60dc3f3d7456813a45aa02d4edec4cbabe967676 (patch)
treeada8b6b68b9643c28760ceb2d7d4f2288727bad0 /lexers/LexCPP.cxx
parent2603138d18befea1768d8c8e64fca0cdc68a9cc7 (diff)
downloadscintilla-mirror-60dc3f3d7456813a45aa02d4edec4cbabe967676.tar.gz
Fix for bug #3062287 JavaScript lexer: recognize regexes following return keyword.
Diffstat (limited to 'lexers/LexCPP.cxx')
-rw-r--r--lexers/LexCPP.cxx30
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);