aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2000-10-27 10:29:04 +0000
committernyamatongwe <unknown>2000-10-27 10:29:04 +0000
commit6a6fde901d11a1b6116746c79f922f4c4cd519ba (patch)
treed321bf3a03d9a1d0b024576dcea8f3ea6e8cce71 /src
parentce7274acfc26685f5061b5b513103da3875680e6 (diff)
downloadscintilla-mirror-6a6fde901d11a1b6116746c79f922f4c4cd519ba.tar.gz
Added support for JavaScript regular expressions.
Diffstat (limited to 'src')
-rw-r--r--src/LexCPP.cxx22
-rw-r--r--src/LexHTML.cxx32
2 files changed, 50 insertions, 4 deletions
diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx
index b6358ab33..bf70b0c81 100644
--- a/src/LexCPP.cxx
+++ b/src/LexCPP.cxx
@@ -37,6 +37,10 @@ static bool classifyWordCpp(unsigned int start, unsigned int end, WordList &keyw
return wordIsUUID;
}
+static bool isOKBeforeRE(char ch) {
+ return (ch == '(') || (ch == '=') || (ch == ',');
+}
+
static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
Accessor &styler) {
@@ -55,6 +59,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
state = SCE_C_DEFAULT;
char chPrev = ' ';
char chNext = styler[startPos];
+ char chPrevNonWhite = ' ';
unsigned int lengthDoc = startPos + length;
int visibleChars = 0;
styler.StartSegment(startPos);
@@ -117,6 +122,9 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
} else if (ch == '/' && chNext == '/') {
styler.ColourTo(i-1, state);
state = SCE_C_COMMENTLINE;
+ } else if (ch == '/' && isOKBeforeRE(chPrevNonWhite)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_REGEX;
} else if (ch == '\"') {
styler.ColourTo(i-1, state);
state = SCE_C_STRING;
@@ -226,6 +234,18 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
styler.ColourTo(i, state);
state = SCE_C_DEFAULT;
}
+ } else if (state == SCE_C_REGEX) {
+ if (ch == '\r' || ch == '\n' || ch == '/') {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ } else if (ch == '\\') {
+ // Gobble up the quoted character
+ if (chNext == '\\' || chNext == '/') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
} else if (state == SCE_C_VERBATIM) {
if (ch == '\"') {
if (chNext == '\"') {
@@ -247,6 +267,8 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
}
}
chPrev = ch;
+ if (ch != ' ' && ch != '\t')
+ chPrevNonWhite = ch;
}
styler.ColourTo(lengthDoc - 1, state);
diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx
index 7868b47fc..ca52f490d 100644
--- a/src/LexHTML.cxx
+++ b/src/LexHTML.cxx
@@ -71,7 +71,7 @@ static int ScriptOfState(int state) {
scriptLanguage = eScriptPython;
} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
scriptLanguage = eScriptVBS;
- } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_STRINGEOL)) {
+ } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
scriptLanguage = eScriptJS;
} else if ((state >= SCE_HPHP_DEFAULT) && (state <= SCE_HPHP_COMMENTLINE)) {
scriptLanguage = eScriptPHP;
@@ -90,7 +90,7 @@ static int statePrintForState(int state, int inScriptType) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON);
} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS);
- } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_STRINGEOL)) {
+ } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS);
} else {
StateToPrint = state;
@@ -106,7 +106,7 @@ static int stateForPrintState(int StateToPrint) {
state = StateToPrint - SCE_HA_PYTHON;
} else if ((StateToPrint >= SCE_HBA_START) && (StateToPrint <= SCE_HBA_STRINGEOL)) {
state = StateToPrint - SCE_HA_VBS;
- } else if ((StateToPrint >= SCE_HJA_START) && (StateToPrint <= SCE_HJA_STRINGEOL)) {
+ } else if ((StateToPrint >= SCE_HJA_START) && (StateToPrint <= SCE_HJA_REGEX)) {
state = StateToPrint - SCE_HA_JS;
} else {
state = StateToPrint;
@@ -295,6 +295,10 @@ static bool isLineEnd(char ch) {
return ch == '\r' || ch == '\n';
}
+static bool isOKBeforeRE(char ch) {
+ return (ch == '(') || (ch == '=') || (ch == ',');
+}
+
static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
Accessor &styler) {
@@ -338,11 +342,14 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
char chPrev = ' ';
char ch = ' ';
+ char chPrevNonWhite = ' ';
styler.StartSegment(startPos);
int lengthDoc = startPos + length;
for (int i = startPos; i < lengthDoc; i++) {
char chPrev2 = chPrev;
chPrev = ch;
+ if (ch != ' ' && ch != '\t')
+ chPrevNonWhite = ch;
ch = styler[i];
char chNext = styler.SafeGetCharAt(i + 1);
char chNext2 = styler.SafeGetCharAt(i + 2);
@@ -709,6 +716,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
} else if (ch == '/' && chNext == '/') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
+ } else if (ch == '/' && isOKBeforeRE(chPrevNonWhite)) {
+ styler.ColourTo(i - 1, StateToPrint);
+ state = SCE_HJ_REGEX;
} else if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_DOUBLESTRING;
@@ -820,6 +830,19 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HJ_DEFAULT;
}
break;
+ case SCE_HJ_REGEX:
+ if (ch == '\r' || ch == '\n' || ch == '/') {
+ styler.ColourTo(i, StateToPrint);
+ state = SCE_HJ_DEFAULT;
+ } else if (ch == '\\') {
+ // Gobble up the quoted character
+ if (chNext == '\\' || chNext == '/') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
+ break;
case SCE_HB_DEFAULT:
case SCE_HB_START:
if (iswordstart(ch)) {
@@ -1129,7 +1152,8 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
} else if (iswordstart(ch)) {
state = SCE_HJ_WORD;
} else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HJ_SYMBOLS);
+ styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
+ //styler.ColourTo(i, SCE_HJ_SYMBOLS);
}
}
}