diff options
| author | nyamatongwe <devnull@localhost> | 2010-09-09 11:18:35 +1000 | 
|---|---|---|
| committer | nyamatongwe <devnull@localhost> | 2010-09-09 11:18:35 +1000 | 
| commit | 60dc3f3d7456813a45aa02d4edec4cbabe967676 (patch) | |
| tree | ada8b6b68b9643c28760ceb2d7d4f2288727bad0 /lexers/LexCPP.cxx | |
| parent | 2603138d18befea1768d8c8e64fca0cdc68a9cc7 (diff) | |
| download | scintilla-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.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); | 
