aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2012-12-30 20:28:05 +0100
committerColomban Wendling <ban@herbesfolles.org>2012-12-30 20:28:05 +0100
commitb5264a5fea7966b102085b5b36882c47fa2ea6cd (patch)
tree1746abfe7a8d09f888dc8bbff6ca848684ef1228
parentf3b24db7919e15689a534d3225f982f746cc9bd5 (diff)
downloadscintilla-mirror-b5264a5fea7966b102085b5b36882c47fa2ea6cd.tar.gz
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 "]".
-rw-r--r--lexers/LexCPP.cxx17
1 files changed, 11 insertions, 6 deletions
diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx
index 834c273fa..87482176d 100644
--- a/lexers/LexCPP.cxx
+++ b/lexers/LexCPP.cxx
@@ -471,6 +471,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,
bool continuationLine = false;
bool isIncludePreprocessor = false;
bool isStringInPreprocessor = false;
+ bool inRERange = false;
int lineCurrent = styler.GetLine(startPos);
if ((MaskActive(initStyle) == SCE_C_PREPROCESSOR) ||
@@ -544,6 +545,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,
visibleChars = 0;
lastWordWasUUID = false;
isIncludePreprocessor = false;
+ inRERange = false;
if (preproc.IsInactive()) {
activitySet = activeFlag;
sc.SetState(sc.state | activitySet);
@@ -748,16 +750,18 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,
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();
- }
+ } else if (sc.ch == '\\' && (sc.chNext != '\n' && sc.chNext != '\r')) {
+ // Gobble up the escaped character
+ sc.Forward();
+ } else if (sc.ch == '[') {
+ inRERange = true;
+ } else if (sc.ch == ']') {
+ inRERange = false;
}
break;
case SCE_C_STRINGEOL:
@@ -838,6 +842,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,
&& (!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();