# HG changeset patch
# User Colomban Wendling <ban@herbesfolles.org>
# Date 1351286542 -7200
# Branch local
# Node ID ad54e1b89e4f5e70b425913db63b7b42f5545d29
# Parent  6b39e2e39a86c1a7b23e438951e36437729f6ead
Fix parsing of JavaScript regular expressions containing a delimiter in a range

Regular expression "/[/]/" is valid, the second "/" being escaped by the
character range ("[]").  Also, escape any \-prefixed character, including
"[" and "]".

diff -r 6b39e2e39a86 -r ad54e1b89e4f lexers/LexCPP.cxx
--- a/lexers/LexCPP.cxx	Fri Oct 26 23:15:58 2012 +0200
+++ b/lexers/LexCPP.cxx	Fri Oct 26 23:22:22 2012 +0200
@@ -468,6 +468,7 @@
 	bool continuationLine = false;
 	bool isIncludePreprocessor = false;
 	bool isStringInPreprocessor = false;
+	bool inRERange = false;
 
 	int lineCurrent = styler.GetLine(startPos);
 	if ((MaskActive(initStyle) == SCE_C_PREPROCESSOR) ||
@@ -745,16 +746,18 @@
 			case SCE_C_REGEX:
 				if (sc.atLineStart) {
 					sc.SetState(SCE_C_DEFAULT|activitySet);
-				} else if (sc.ch == '/') {
+				} else if (! inRERange && sc.ch == '/') {
 					sc.Forward();
 					while ((sc.ch < 0x80) && islower(sc.ch))
 						sc.Forward();    // gobble regex flags
 					sc.SetState(SCE_C_DEFAULT|activitySet);
 				} else if (sc.ch == '\\') {
 					// Gobble up the quoted character
-					if (sc.chNext == '\\' || sc.chNext == '/') {
-						sc.Forward();
-					}
+					sc.Forward();
+				} else if (sc.ch == '[') {
+					inRERange = true;
+				} else if (sc.ch == ']') {
+					inRERange = false;
 				}
 				break;
 			case SCE_C_STRINGEOL:
@@ -835,6 +838,7 @@
 				   && (!setCouldBePostOp.Contains(chPrevNonWhite)
 				       || !FollowsPostfixOperator(sc, styler))) {
 				sc.SetState(SCE_C_REGEX|activitySet);	// JavaScript's RegEx
+				inRERange = false;
 			} else if (sc.ch == '\"') {
 				if (sc.chPrev == 'R') {
 					styler.Flush();
