aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/LexHTML.cxx
diff options
context:
space:
mode:
authornyamatongwe <unknown>2005-11-29 23:27:02 +0000
committernyamatongwe <unknown>2005-11-29 23:27:02 +0000
commited21e9ef1a1454459034e511cce06a3085ab7a91 (patch)
tree97549fd70adc2bbcac37fc33f245dd48d09a1bab /src/LexHTML.cxx
parentb4d13bcf84be6ac80156338b14b99b606a53790e (diff)
downloadscintilla-mirror-ed21e9ef1a1454459034e511cce06a3085ab7a91.tar.gz
Patch from Kein-Hong Man improves regular expression detection
when disambiguating character on previous line or separated from '/' by a comment. Includes trailing lowercase regex flags in the regex style.
Diffstat (limited to 'src/LexHTML.cxx')
-rw-r--r--src/LexHTML.cxx29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx
index b822852a5..a268c2b0d 100644
--- a/src/LexHTML.cxx
+++ b/src/LexHTML.cxx
@@ -2,7 +2,7 @@
/** @file LexHTML.cxx
** Lexer for HTML.
**/
-// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
+// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
@@ -503,12 +503,28 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
char chPrev = ' ';
char ch = ' ';
char chPrevNonWhite = ' ';
+ // look back to set chPrevNonWhite properly for better regex colouring
+ if (scriptLanguage == eScriptJS && startPos > 0) {
+ int back = startPos;
+ int style = 0;
+ while (--back) {
+ style = styler.StyleAt(back);
+ if (style < SCE_HJ_DEFAULT || style > SCE_HJ_COMMENTDOC)
+ // includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE
+ break;
+ }
+ if (style == SCE_HJ_SYMBOLS) {
+ chPrevNonWhite = styler.SafeGetCharAt(back);
+ }
+ }
+
styler.StartSegment(startPos);
const int lengthDoc = startPos + length;
for (int i = startPos; i < lengthDoc; i++) {
const char chPrev2 = chPrev;
chPrev = ch;
- if (ch != ' ' && ch != '\t')
+ if (!isspacechar(ch) && state != SCE_HJ_COMMENT &&
+ state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC)
chPrevNonWhite = ch;
ch = styler[i];
char chNext = styler.SafeGetCharAt(i + 1);
@@ -1236,12 +1252,14 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
if (ch == '/' && chPrev == '*') {
styler.ColourTo(i, StateToPrint);
state = SCE_HJ_DEFAULT;
+ ch = ' ';
}
break;
case SCE_HJ_COMMENTLINE:
if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, statePrintForState(SCE_HJ_COMMENTLINE, inScriptType));
state = SCE_HJ_DEFAULT;
+ ch = ' ';
}
break;
case SCE_HJ_DOUBLESTRING:
@@ -1289,6 +1307,13 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
break;
case SCE_HJ_REGEX:
if (ch == '\r' || ch == '\n' || ch == '/') {
+ if (ch == '/') {
+ while (chNext < 0x80 && islower(chNext)) { // gobble regex flags
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
styler.ColourTo(i, StateToPrint);
state = SCE_HJ_DEFAULT;
} else if (ch == '\\') {