aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/LexCPP.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/LexCPP.cxx')
-rw-r--r--src/LexCPP.cxx39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx
index cd2755243..40f3a60bd 100644
--- a/src/LexCPP.cxx
+++ b/src/LexCPP.cxx
@@ -36,10 +36,17 @@ static inline bool IsAWordStart(int ch) {
}
static inline bool IsADoxygenChar(int ch) {
- return (islower(ch) || ch == '$' || ch == '@' ||
- ch == '\\' || ch == '&' || ch == '<' ||
- ch == '>' || ch == '#' || ch == '{' ||
- ch == '}' || ch == '[' || ch == ']');
+ return (ch < 0x80 && islower(ch)) || ch == '$' || ch == '@' ||
+ ch == '\\' || ch == '&' || ch == '<' ||
+ ch == '>' || ch == '#' || ch == '{' ||
+ ch == '}' || ch == '[' || ch == ']';
+}
+
+static bool IsSpaceEquiv(int state) {
+ return (state <= SCE_C_COMMENTDOC) ||
+ // including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE
+ (state == SCE_C_COMMENTLINEDOC) || (state == SCE_C_COMMENTDOCKEYWORD) ||
+ (state == SCE_C_COMMENTDOCKEYWORDERROR);
}
static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
@@ -74,6 +81,16 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
}
}
+ // look back to set chPrevNonWhite properly for better regex colouring
+ if (startPos > 0) {
+ int back = startPos;
+ while (--back && IsSpaceEquiv(styler.StyleAt(back)))
+ ;
+ if (styler.StyleAt(back) == SCE_C_OPERATOR) {
+ chPrevNonWhite = styler.SafeGetCharAt(back);
+ }
+ }
+
StyleContext sc(startPos, length, initStyle, styler);
for (; sc.More(); sc.Forward()) {
@@ -86,7 +103,6 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
}
// Reset states to begining of colourise so no surprises
// if different sets of lines lexed.
- chPrevNonWhite = ' ';
visibleChars = 0;
lastWordWasUUID = false;
}
@@ -224,7 +240,10 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
if (sc.atLineStart) {
sc.SetState(SCE_C_DEFAULT);
} else if (sc.ch == '/') {
- sc.ForwardSetState(SCE_C_DEFAULT);
+ sc.Forward();
+ while ((sc.ch < 0x80) && islower(sc.ch))
+ sc.Forward(); // gobble regex flags
+ sc.SetState(SCE_C_DEFAULT);
} else if (sc.ch == '\\') {
// Gobble up the quoted character
if (sc.chNext == '\\' || sc.chNext == '/') {
@@ -305,7 +324,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
}
}
- if (!IsASpace(sc.ch)) {
+ if (!IsASpace(sc.ch) && !IsSpaceEquiv(sc.state)) {
chPrevNonWhite = sc.ch;
visibleChars++;
}
@@ -316,9 +335,9 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo
static bool IsStreamCommentStyle(int style) {
return style == SCE_C_COMMENT ||
- style == SCE_C_COMMENTDOC ||
- style == SCE_C_COMMENTDOCKEYWORD ||
- style == SCE_C_COMMENTDOCKEYWORDERROR;
+ style == SCE_C_COMMENTDOC ||
+ style == SCE_C_COMMENTDOCKEYWORD ||
+ style == SCE_C_COMMENTDOCKEYWORDERROR;
}
// Store both the current line's fold level and the next lines in the