aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2000-03-16 11:43:39 +0000
committernyamatongwe <devnull@localhost>2000-03-16 11:43:39 +0000
commit01cd695dc8d693c39500f24adf689d08d77d39da (patch)
tree3837357cf607234f40e4b4705c24da1e40ba0758 /src
parent8c214e65f503275192e2f3f9dea97fbb65a38254 (diff)
downloadscintilla-mirror-01cd695dc8d693c39500f24adf689d08d77d39da.tar.gz
Split up KeyWords.cxx into 7 individual lexer files Lex*.cxx.
Fixed setting up of second view to get right document length. Changed Python lexer to handle empty lines immediately after fold line and last line of document.
Diffstat (limited to 'src')
-rw-r--r--src/Accessor.cxx58
-rw-r--r--src/Document.cxx12
-rw-r--r--src/Document.h2
-rw-r--r--src/Editor.cxx23
-rw-r--r--src/Editor.h2
-rw-r--r--src/KeyWords.cxx2544
-rw-r--r--src/LexCPP.cxx240
-rw-r--r--src/LexHTML.cxx1139
-rw-r--r--src/LexOthers.cxx200
-rw-r--r--src/LexPerl.cxx488
-rw-r--r--src/LexPython.cxx254
-rw-r--r--src/LexSQL.cxx158
-rw-r--r--src/LexVB.cxx118
-rw-r--r--src/ScintillaBase.cxx5
14 files changed, 2704 insertions, 2539 deletions
diff --git a/src/Accessor.cxx b/src/Accessor.cxx
index 60c5968c5..f080742bd 100644
--- a/src/Accessor.cxx
+++ b/src/Accessor.cxx
@@ -4,6 +4,7 @@
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
+#include <ctype.h>
#include <stdio.h>
#include "Platform.h"
@@ -12,6 +13,17 @@
#include "Accessor.h"
#include "Scintilla.h"
+bool Accessor::InternalIsLeadByte(char ch) {
+#if PLAT_GTK
+ // TODO: support DBCS under GTK+
+ return false;
+#elif PLAT_WIN
+ return IsDBCSLeadByteEx(codePage, ch);
+#elif PLAT_WX
+ return false;
+#endif
+}
+
void Accessor::Fill(int position) {
if (lenDoc == -1)
lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0);
@@ -106,3 +118,49 @@ void StylingContext::Flush() {
validLen = 0;
}
}
+
+int StylingContext::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
+ int end = Length();
+ int spaceFlags = 0;
+
+ // Determines the indentation level of the current line and also checks for consistent
+ // indentation compared to the previous line.
+ // Indentation is judged consistent when the indentation whitespace of each line lines
+ // the same or the indentation of one line is a prefix of the other.
+
+ int pos = LineStart(line);
+ char ch = (*this)[pos];
+ int indent = 0;
+ bool inPrevPrefix = line > 0;
+ int posPrev = inPrevPrefix ? LineStart(line-1) : 0;
+ while ((ch == ' ' || ch == '\t') && (pos < end)) {
+ if (inPrevPrefix) {
+ char chPrev = (*this)[posPrev++];
+ if (chPrev == ' ' || chPrev == '\t') {
+ if (chPrev != ch)
+ spaceFlags |= wsInconsistent;
+ } else {
+ inPrevPrefix = false;
+ }
+ }
+ if (ch == ' ') {
+ spaceFlags |= wsSpace;
+ indent++;
+ } else { // Tab
+ spaceFlags |= wsTab;
+ if (spaceFlags & wsSpace)
+ spaceFlags |= wsSpaceTab;
+ indent = (indent / 8 + 1) * 8;
+ }
+ ch = (*this)[++pos];
+ }
+
+ *flags = spaceFlags;
+ indent += SC_FOLDLEVELBASE;
+ // if completely empty line or the start of a comment...
+ if (isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) )
+ return indent | SC_FOLDLEVELWHITEFLAG;
+ else
+ return indent;
+}
+
diff --git a/src/Document.cxx b/src/Document.cxx
index 8238ea758..b50b9691a 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -149,7 +149,10 @@ int Document::GetLastChild(int lineParent, int level) {
level = GetLevel(lineParent) & SC_FOLDLEVELNUMBERMASK;
int maxLine = LinesTotal();
int lineMaxSubord = lineParent;
- while ((lineMaxSubord < maxLine-1) && IsSubordinate(level, GetLevel(lineMaxSubord+1))) {
+ while (lineMaxSubord < maxLine-1) {
+ EnsureStyledTo(LineStart(lineMaxSubord+2));
+ if (!IsSubordinate(level, GetLevel(lineMaxSubord+1)))
+ break;
lineMaxSubord++;
}
if (lineMaxSubord > lineParent) {
@@ -696,6 +699,13 @@ void Document::SetStyles(int length, char *styles) {
}
}
+bool Document::EnsureStyledTo(int pos) {
+ // Ask the watchers to style, and stop as soon as one responds.
+ for (int i = 0; pos > GetEndStyled() && i < lenWatchers; i++)
+ watchers[i].watcher->NotifyStyleNeeded(this, watchers[i].userData, pos);
+ return pos <= GetEndStyled();
+}
+
bool Document::AddWatcher(DocWatcher *watcher, void *userData) {
for (int i = 0; i < lenWatchers; i++) {
if ((watchers[i].watcher == watcher) &&
diff --git a/src/Document.h b/src/Document.h
index d97d59078..59215c75a 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -160,6 +160,7 @@ public:
void SetStyleFor(int length, char style);
void SetStyles(int length, char *styles);
int GetEndStyled() { return endStyled; }
+ bool EnsureStyledTo(int pos);
int SetLineState(int line, int state) { return cb.SetLineState(line, state); }
int GetLineState(int line) { return cb.GetLineState(line); }
@@ -217,6 +218,7 @@ public:
virtual void NotifySavePoint(Document *doc, void *userData, bool atSavePoint) = 0;
virtual void NotifyModified(Document *doc, DocModification mh, void *userData) = 0;
virtual void NotifyDeleted(Document *doc, void *userData) = 0;
+ virtual void NotifyStyleNeeded(Document *doc, void *userData, int endPos) = 0;
};
#endif
diff --git a/src/Editor.cxx b/src/Editor.cxx
index a606671dd..7f9ce5980 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -991,10 +991,9 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
ypos += screenLinePaintFirst * vs.lineHeight;
int yposScreen = screenLinePaintFirst * vs.lineHeight;
- if (endPosPaint > pdoc->GetEndStyled()) {
- // Notify container to do some more styling
- NotifyStyleNeeded(endPosPaint);
- }
+ // Ensure we are styled as far as we are painting.
+ pdoc->EnsureStyledTo(endPosPaint);
+
if (needUpdateUI) {
NotifyUpdateUI();
needUpdateUI = false;
@@ -1009,7 +1008,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
}
if (paintState == paintAbandoned) {
- // Either NotifyStyleNeeded or NotifyUpdateUI noticed that painting is needed
+ // Either styling or NotifyUpdateUI noticed that painting is needed
// outside the current painting rectangle
//Platform::DebugPrintf("Abandoning paint\n");
return;
@@ -1212,10 +1211,9 @@ long Editor::FormatRange(bool draw, FORMATRANGE *pfr) {
if (linePrintLast < pdoc->LinesTotal())
endPosPrint = pdoc->LineStart(linePrintLast + 1);
- if (endPosPrint > pdoc->GetEndStyled()) {
- // Notify container to do some more styling
- NotifyStyleNeeded(endPosPrint);
- }
+ // Ensure we are styled to where we are formatting.
+ pdoc->EnsureStyledTo(endPosPrint);
+
int xStart = vsPrint.fixedColumnWidth + pfr->rc.left + lineNumberWidth;
int ypos = pfr->rc.top;
int line = linePrintStart;
@@ -1436,6 +1434,10 @@ void Editor::NotifyStyleNeeded(int endStyleNeeded) {
NotifyParent(scn);
}
+void Editor::NotifyStyleNeeded(Document*, void *, int endStyleNeeded) {
+ NotifyStyleNeeded(endStyleNeeded);
+}
+
void Editor::NotifyChar(char ch) {
SCNotification scn;
scn.nmhdr.code = SCN_CHARADDED;
@@ -1903,6 +1905,7 @@ int Editor::KeyCommand(UINT iMessage) {
case SCI_DELWORDRIGHT: {
int endWord = pdoc->NextWordStart(currentPos, 1);
pdoc->DeleteChars(currentPos, endWord - currentPos);
+ MovePositionTo(currentPos);
}
break;
}
@@ -2591,7 +2594,7 @@ void Editor::SetDocPointer(Document *document) {
pdoc->AddRef();
// Reset the contraction state to fully shown.
cs.Clear();
- cs.InsertLines(0, pdoc->LinesTotal());
+ cs.InsertLines(0, pdoc->LinesTotal()-1);
pdoc->AddWatcher(this, 0);
Redraw();
diff --git a/src/Editor.h b/src/Editor.h
index 4ff334767..46fc52d94 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -218,6 +218,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
void NotifyModified(Document *document, DocModification mh, void *userData);
void NotifyDeleted(Document *document, void *userData);
+ void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
+
#ifdef MACRO_SUPPORT
void NotifyMacroRecord(UINT iMessage, WPARAM wParam, LPARAM lParam);
diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx
index cf5b3c0d6..bc7882367 100644
--- a/src/KeyWords.cxx
+++ b/src/KeyWords.cxx
@@ -17,2535 +17,27 @@
#include "Scintilla.h"
#include "SciLexer.h"
-inline bool IsLeadByte(int codePage, char ch) {
-#if PLAT_GTK
- // TODO: support DBCS under GTK+
- return false;
-#elif PLAT_WIN
- return codePage && IsDBCSLeadByteEx(codePage, ch);
-#elif PLAT_WX
- return false;
-#endif
-}
-
-inline bool iswordchar(char ch) {
- return isalnum(ch) || ch == '.' || ch == '_';
-}
-
-inline bool iswordstart(char ch) {
- return isalnum(ch) || ch == '_';
-}
-
-enum { wsSpace = 1, wsTab = 2, wsSpaceTab = 4, wsInconsistent=8};
-
-typedef bool (*PFNIsCommentLeader)(StylingContext &styler, int pos, int len);
-
-static int IndentAmount(StylingContext &styler, int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader = 0) {
- int end = styler.Length();
- int spaceFlags = 0;
-
- // Determines the indentation level of the current line and also checks for consistent
- // indentation compared to the previous line.
- // Indentation is judged consistent when the indentation whitespace of each line lines
- // the same or the indentation of one line is a prefix of the other.
-
- int pos = styler.LineStart(line);
- char ch = styler[pos];
- int indent = 0;
- bool inPrevPrefix = line > 0;
- int posPrev = inPrevPrefix ? styler.LineStart(line-1) : 0;
- while ((ch == ' ' || ch == '\t') && (pos < end)) {
- if (inPrevPrefix) {
- char chPrev = styler[posPrev++];
- if (chPrev == ' ' || chPrev == '\t') {
- if (chPrev != ch)
- spaceFlags |= wsInconsistent;
- } else {
- inPrevPrefix = false;
- }
- }
- if (ch == ' ') {
- spaceFlags |= wsSpace;
- indent++;
- } else { // Tab
- spaceFlags |= wsTab;
- if (spaceFlags & wsSpace)
- spaceFlags |= wsSpaceTab;
- indent = (indent / 8 + 1) * 8;
- }
- ch = styler[++pos];
- }
-
- *flags = spaceFlags;
- indent += SC_FOLDLEVELBASE;
- // if completely empty line or the start of a comment...
- if ( isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(styler, pos, end-pos)) )
- return indent | SC_FOLDLEVELWHITEFLAG;
- else
- return indent;
-}
-
-inline bool isoperator(char ch) {
- if (isalnum(ch))
- return false;
- // '.' left out as it is used to make up numbers
- if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
- ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
- ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
- ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
- ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
- ch == '?' || ch == '!' || ch == '.' || ch == '~')
- return true;
- return false;
-}
-
-static void classifyWordCpp(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_C_IDENTIFIER;
- if (wordIsNumber)
- chAttr = SCE_C_NUMBER;
- else {
- if (keywords.InList(s))
- chAttr = SCE_C_WORD;
- }
- styler.ColourTo(end, chAttr);
-}
-
-static void ColouriseCppDoc(int codePage, int startPos, int length,
- int initStyle, WordList &keywords, StylingContext &styler) {
-
- bool fold = styler.GetPropSet().GetInt("fold");
- int lineCurrent = styler.GetLine(startPos);
- int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
- int levelCurrent = levelPrev;
-
- int state = initStyle;
- char chPrev = ' ';
- char chNext = styler[startPos];
- unsigned int lengthDoc = startPos + length;
- int visChars = 0;
- styler.StartSegment(startPos);
- for (unsigned int i = startPos; i <= lengthDoc; i++) {
- char ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
-
- if ((fold) && ((ch == '\r' && chNext != '\n') || (ch == '\n'))) {
- int lev = levelPrev;
- if (visChars == 0)
- lev |= SC_FOLDLEVELWHITEFLAG;
- if ((levelCurrent > levelPrev) && (visChars > 0))
- lev |= SC_FOLDLEVELHEADERFLAG;
- styler.SetLevel(lineCurrent, lev);
- lineCurrent++;
- visChars = 0;
- levelPrev = levelCurrent;
- }
- if (!isspace(ch))
- visChars++;
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chNext = styler.SafeGetCharAt(i + 2);
- chPrev = ' ';
- i += 1;
- continue;
- }
-
- if (state == SCE_C_STRINGEOL) {
- if (ch != '\r' && ch != '\n') {
- styler.ColourTo(i-1, state);
- state = SCE_C_DEFAULT;
- }
- }
- if (state == SCE_C_DEFAULT) {
- if (iswordstart(ch)) {
- styler.ColourTo(i-1, state);
- state = SCE_C_WORD;
- } else if (ch == '/' && chNext == '*') {
- styler.ColourTo(i-1, state);
- if (styler.SafeGetCharAt(i + 2) == '*')
- state = SCE_C_COMMENTDOC;
- else
- state = SCE_C_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- styler.ColourTo(i-1, state);
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i-1, state);
- state = SCE_C_STRING;
- } else if (ch == '\'') {
- styler.ColourTo(i-1, state);
- state = SCE_C_CHARACTER;
- } else if (ch == '#') {
- styler.ColourTo(i-1, state);
- state = SCE_C_PREPROCESSOR;
- } else if (isoperator(ch)) {
- styler.ColourTo(i-1, state);
- styler.ColourTo(i, SCE_C_OPERATOR);
- if ((ch == '{') || (ch == '}')) {
- levelCurrent += (ch == '{') ? 1 : -1;
- }
- }
- } else if (state == SCE_C_WORD) {
- if (!iswordchar(ch)) {
- classifyWordCpp(styler.GetStartSegment(), i - 1, keywords, styler);
- state = SCE_C_DEFAULT;
- if (ch == '/' && chNext == '*') {
- if (styler.SafeGetCharAt(i + 2) == '*')
- state = SCE_C_COMMENTDOC;
- else
- state = SCE_C_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_C_STRING;
- } else if (ch == '\'') {
- state = SCE_C_CHARACTER;
- } else if (ch == '#') {
- state = SCE_C_PREPROCESSOR;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_C_OPERATOR);
- if ((ch == '{') || (ch == '}')) {
- levelCurrent += (ch == '{') ? 1 : -1;
- }
- }
- }
- } else {
- if (state == SCE_C_PREPROCESSOR) {
- if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
- styler.ColourTo(i-1, state);
- state = SCE_C_DEFAULT;
- }
- } else if (state == SCE_C_COMMENT) {
- if (ch == '/' && chPrev == '*') {
- if (((i > styler.GetStartSegment() + 2) || (
- (initStyle == SCE_C_COMMENT) &&
- (styler.GetStartSegment() == startPos)))) {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- }
- }
- } else if (state == SCE_C_COMMENTDOC) {
- if (ch == '/' && chPrev == '*') {
- if (((i > styler.GetStartSegment() + 3) || (
- (initStyle == SCE_C_COMMENTDOC) &&
- (styler.GetStartSegment() == startPos)))) {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- }
- }
- } else if (state == SCE_C_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i-1, state);
- state = SCE_C_DEFAULT;
- }
- } else if (state == SCE_C_STRING) {
- if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
- styler.ColourTo(i-1, state);
- state = SCE_C_STRINGEOL;
- } else if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (state == SCE_C_CHARACTER) {
- if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
- styler.ColourTo(i-1, state);
- state = SCE_C_STRINGEOL;
- } else if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- }
- if (state == SCE_C_DEFAULT) { // One of the above succeeded
- if (ch == '/' && chNext == '*') {
- if (styler.SafeGetCharAt(i + 2) == '*')
- state = SCE_C_COMMENTDOC;
- else
- state = SCE_C_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_C_STRING;
- } else if (ch == '\'') {
- state = SCE_C_CHARACTER;
- } else if (ch == '#') {
- state = SCE_C_PREPROCESSOR;
- } else if (iswordstart(ch)) {
- state = SCE_C_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_C_OPERATOR);
- if ((ch == '{') || (ch == '}')) {
- levelCurrent += (ch == '{') ? 1 : -1;
- }
- }
- }
- }
- chPrev = ch;
- }
- styler.ColourTo(lengthDoc - 1, state);
-
- // Fill in the real level of the next line, keeping the current flags as they will be filled in later
- if (fold) {
- int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
- //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
- styler.SetLevel(lineCurrent, levelPrev | flagsNext);
-
- }
-}
-
-inline bool isPerlOperator(char ch) {
- if (isalnum(ch))
- return false;
- // '.' left out as it is used to make up numbers
- if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || ch == '\\' ||
- ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
- ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
- ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
- ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
- ch == '?' || ch == '!' || ch == '.' || ch == '~')
- return true;
- return false;
-}
-
-static int classifyWordPerl(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_PL_IDENTIFIER;
- if (wordIsNumber)
- chAttr = SCE_PL_NUMBER;
- else {
- if (keywords.InList(s))
- chAttr = SCE_PL_WORD;
- }
- styler.ColourTo(end, chAttr);
- return chAttr;
-}
-
-static bool isEndVar(char ch) {
- return !isalnum(ch) && ch != '#' && ch != '$' &&
- ch != '_' && ch != '\'';
-}
-
-static bool isMatch(StylingContext &styler, int lengthDoc, int pos, const char *val) {
- if ((pos + static_cast<int>(strlen(val))) >= lengthDoc) {
- return false;
- }
- while (*val) {
- if (*val != styler[pos++]) {
- return false;
- }
- val++;
- }
- return true;
-}
-
-static bool isOKQuote(char ch) {
- if (isalnum(ch))
- return false;
- if (isspace(ch))
- return false;
- if (iscntrl(ch))
- return false;
- return true;
-}
-
-static char opposite(char ch) {
- if (ch == '(')
- return ')';
- if (ch == '[')
- return ']';
- if (ch == '{')
- return '}';
- if (ch == '<')
- return '>';
- return ch;
-}
-
-static void ColourisePerlDoc(int codePage, int startPos, int length, int initStyle,
- WordList &keywords, StylingContext &styler) {
- char sooked[100];
- int quotes = 0;
- char quoteDown = 'd';
- char quoteUp = 'd';
- int quoteRep = 1;
- int sookedpos = 0;
- bool preferRE = true;
- sooked[sookedpos] = '\0';
- int state = initStyle;
- int lengthDoc = startPos + length;
- // If in a long distance lexical state, seek to the beginning to find quote characters
- if (state == SCE_PL_HERE || state == SCE_PL_REGEX ||
- state == SCE_PL_REGSUBST || state == SCE_PL_LONGQUOTE) {
- while ((startPos > 1) && (styler.StyleAt(startPos - 1) == state)) {
- startPos--;
- }
- state = SCE_PL_DEFAULT;
- }
- styler.StartAt(startPos);
- char chPrev = ' ';
- char chNext = styler[startPos];
- styler.StartSegment(startPos);
- for (int i = startPos; i <= lengthDoc; i++) {
- char ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- char chNext2 = styler.SafeGetCharAt(i + 2);
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chNext = styler.SafeGetCharAt(i + 2);
- chPrev = ' ';
- i += 1;
- continue;
- }
-
- if (state == SCE_PL_DEFAULT) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- if (ch == 's' && !isalnum(chNext)) {
- state = SCE_PL_REGSUBST;
- quotes = 0;
- quoteUp = '\0';
- quoteDown = '\0';
- quoteRep = 2;
- } else if (ch == 'm' && !isalnum(chNext)) {
- state = SCE_PL_REGEX;
- quotes = 0;
- quoteUp = '\0';
- quoteDown = '\0';
- quoteRep = 1;
- } else if (ch == 't' && chNext == 'r' && !isalnum(chNext2)) {
- state = SCE_PL_REGSUBST;
- quotes = 0;
- quoteUp = '\0';
- quoteDown = '\0';
- quoteRep = 2;
- i++;
- chNext = chNext2;
- } else if (ch == 'q' && (chNext == 'q' || chNext == 'r' || chNext == 'w' || chNext == 'x') && !isalnum(chNext2)) {
- state = SCE_PL_LONGQUOTE;
- i++;
- chNext = chNext2;
- quotes = 0;
- quoteUp = '\0';
- quoteDown = '\0';
- quoteRep = 1;
- } else {
- state = SCE_PL_WORD;
- preferRE = false;
- }
- } else if (ch == '#') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_STRING;
- } else if (ch == '\'') {
- if (chPrev == '&') {
- // Archaic call
- styler.ColourTo(i, state);
- } else {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_CHARACTER;
- }
- } else if (ch == '`') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_BACKTICKS;
- } else if (ch == '$') {
- preferRE = false;
- styler.ColourTo(i - 1, state);
- if (isalnum(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
- state = SCE_PL_SCALAR;
- } else if (chNext != '{' && chNext != '[') {
- styler.ColourTo(i, SCE_PL_SCALAR);
- i++;
- ch = ' ';
- chNext = ' ';
- } else {
- styler.ColourTo(i, SCE_PL_SCALAR);
- }
- } else if (ch == '@') {
- preferRE = false;
- styler.ColourTo(i - 1, state);
- if (isalpha(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
- state = SCE_PL_ARRAY;
- } else if (chNext != '{' && chNext != '[') {
- styler.ColourTo(i, SCE_PL_ARRAY);
- i++;
- ch = ' ';
- } else {
- styler.ColourTo(i, SCE_PL_ARRAY);
- }
- } else if (ch == '%') {
- preferRE = false;
- styler.ColourTo(i - 1, state);
- if (isalpha(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
- state = SCE_PL_HASH;
- } else if (chNext != '{' && chNext != '[') {
- styler.ColourTo(i, SCE_PL_HASH);
- i++;
- ch = ' ';
- } else {
- styler.ColourTo(i, SCE_PL_HASH);
- }
- } else if (ch == '*') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_SYMBOLTABLE;
- } else if (ch == '/' && preferRE) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_REGEX;
- quoteUp = '/';
- quoteDown = '/';
- quotes = 1;
- quoteRep = 1;
- } else if (ch == '<' && chNext == '<') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_HERE;
- i++;
- ch = chNext;
- chNext = chNext2;
- quotes = 0;
- sookedpos = 0;
- sooked[sookedpos] = '\0';
- } else if (ch == '=' && isalpha(chNext)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_POD;
- quotes = 0;
- sookedpos = 0;
- sooked[sookedpos] = '\0';
- } else if (isPerlOperator(ch)) {
- if (ch == ')' || ch == ']')
- preferRE = false;
- else
- preferRE = true;
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_PL_OPERATOR);
- }
- } else if (state == SCE_PL_WORD) {
- if (!iswordchar(ch) && ch != '\'') { // Archaic Perl has quotes inside names
- if (isMatch(styler, lengthDoc, styler.GetStartSegment(), "__DATA__")) {
- styler.ColourTo(i, SCE_PL_DATASECTION);
- state = SCE_PL_DATASECTION;
- } else if (isMatch(styler, lengthDoc, styler.GetStartSegment(), "__END__")) {
- styler.ColourTo(i, SCE_PL_DATASECTION);
- state = SCE_PL_DATASECTION;
- } else {
- if (classifyWordPerl(styler.GetStartSegment(), i - 1, keywords, styler) == SCE_PL_WORD)
- preferRE = true;
- state = SCE_PL_DEFAULT;
- if (ch == '#') {
- state = SCE_PL_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_PL_STRING;
- } else if (ch == '\'') {
- state = SCE_PL_CHARACTER;
- } else if (ch == '<' && chNext == '<') {
- state = SCE_PL_HERE;
- quotes = 0;
- sookedpos = 0;
- sooked[sookedpos] = '\0';
- } else if (isPerlOperator(ch)) {
- if (ch == ')' || ch == ']')
- preferRE = false;
- else
- preferRE = true;
- styler.ColourTo(i, SCE_PL_OPERATOR);
- state = SCE_PL_DEFAULT;
- }
- }
- }
- } else {
- if (state == SCE_PL_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_HERE) {
- if (isalnum(ch) && quotes < 2) {
- sooked[sookedpos++] = ch;
- sooked[sookedpos] = '\0';
- if (quotes == 0)
- quotes = 1;
- } else {
- quotes++;
- }
-
- if (quotes > 1 && isMatch(styler, lengthDoc, i, sooked)) {
- styler.ColourTo(i + sookedpos - 1, SCE_PL_HERE);
- state = SCE_PL_DEFAULT;
- i += sookedpos;
- chNext = ' ';
- }
- } else if (state == SCE_PL_STRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (state == SCE_PL_CHARACTER) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (state == SCE_PL_BACKTICKS) {
- if (ch == '`') {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (state == SCE_PL_POD) {
- if (ch == '=') {
- if (isMatch(styler, lengthDoc, i, "=cut")) {
- styler.ColourTo(i - 1 + 4, state);
- i += 4;
- state = SCE_PL_DEFAULT;
- chNext = ' ';
- ch = ' ';
- }
- }
- } else if (state == SCE_PL_SCALAR) {
- if (isEndVar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_ARRAY) {
- if (isEndVar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_HASH) {
- if (isEndVar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_SYMBOLTABLE) {
- if (isEndVar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_REF) {
- if (isEndVar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_PL_DEFAULT;
- }
- } else if (state == SCE_PL_REGEX) {
- if (!quoteUp && !isspace(ch)) {
- quoteUp = ch;
- quoteDown = opposite(ch);
- quotes++;
- } else {
- if (ch == quoteDown && chPrev != '\\') {
- quotes--;
- if (quotes == 0) {
- quoteRep--;
- if (quoteUp == quoteDown) {
- quotes++;
- }
- }
- if (!isalpha(chNext)) {
- if (quoteRep <= 0) {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- ch = ' ';
- }
- }
- } else if (ch == quoteUp && chPrev != '\\') {
- quotes++;
- } else if (!isalpha(chNext)) {
- if (quoteRep <= 0) {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- ch = ' ';
- }
- }
- }
- } else if (state == SCE_PL_REGSUBST) {
- if (!quoteUp && !isspace(ch)) {
- quoteUp = ch;
- quoteDown = opposite(ch);
- quotes++;
- } else {
- if (ch == quoteDown && chPrev != '\\') {
- quotes--;
- if (quotes == 0) {
- quoteRep--;
- }
- if (!isalpha(chNext)) {
- if (quoteRep <= 0) {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- ch = ' ';
- }
- }
- if (quoteUp == quoteDown) {
- quotes++;
- }
- } else if (ch == quoteUp && chPrev != '\\') {
- quotes++;
- } else if (!isalpha(chNext)) {
- if (quoteRep <= 0) {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- ch = ' ';
- }
- }
- }
- } else if (state == SCE_PL_LONGQUOTE) {
- if (!quoteDown && !isspace(ch)) {
- quoteUp = ch;
- quoteDown = opposite(quoteUp);
- quotes++;
- } else if (ch == quoteDown) {
- quotes--;
- if (quotes == 0) {
- quoteRep--;
- if (quoteRep <= 0) {
- styler.ColourTo(i, state);
- state = SCE_PL_DEFAULT;
- ch = ' ';
- }
- if (quoteUp == quoteDown) {
- quotes++;
- }
- }
- } else if (ch == quoteUp) {
- quotes++;
- }
- }
-
- if (state == SCE_PL_DEFAULT) { // One of the above succeeded
- if (ch == '#') {
- state = SCE_PL_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_PL_STRING;
- } else if (ch == '\'') {
- state = SCE_PL_CHARACTER;
- } else if (iswordstart(ch)) {
- state = SCE_PL_WORD;
- preferRE = false;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_PL_OPERATOR);
- }
- }
- }
- chPrev = ch;
- }
- styler.ColourTo(lengthDoc, state);
-}
-
-
-static int classifyWordVB(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = tolower(styler[start + i]);
- s[i + 1] = '\0';
- }
- char chAttr = SCE_C_DEFAULT;
- if (wordIsNumber)
- chAttr = SCE_C_NUMBER;
- else {
- if (keywords.InList(s)) {
- chAttr = SCE_C_WORD;
- if (strcmp(s, "rem") == 0)
- chAttr = SCE_C_COMMENTLINE;
- }
- }
- styler.ColourTo(end, chAttr);
- if (chAttr == SCE_C_COMMENTLINE)
- return SCE_C_COMMENTLINE;
- else
- return SCE_C_DEFAULT;
-}
-
-static void ColouriseVBDoc(int codePage, int startPos, int length, int initStyle,
- WordList &keywords, StylingContext &styler) {
- int state = initStyle;
- char chNext = styler[startPos];
- styler.StartSegment(startPos);
- int lengthDoc = startPos + length;
- for (int i = startPos; i < lengthDoc; i++) {
- char ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chNext = styler.SafeGetCharAt(i + 2);
- i += 1;
- continue;
- }
-
- if (state == SCE_C_DEFAULT) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_C_WORD;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_STRING;
- }
- } else if (state == SCE_C_WORD) {
- if (!iswordchar(ch)) {
- state = classifyWordVB(styler.GetStartSegment(), i - 1, keywords, styler);
- if (state == SCE_C_DEFAULT) {
- if (ch == '\'') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_C_STRING;
- }
- }
- }
- } else {
- if (state == SCE_C_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_DEFAULT;
- }
- } else if (state == SCE_C_STRING) {
- // VB doubles quotes to preserve them
- if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- }
- if (state == SCE_C_DEFAULT) { // One of the above succeeded
- if (ch == '\'') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_C_STRING;
- } else if (iswordstart(ch)) {
- state = SCE_C_WORD;
- }
- }
- }
- }
- styler.ColourTo(lengthDoc, state);
-}
-
-static void classifyWordPy(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]);
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_P_IDENTIFIER;
- if (0 == strcmp(prevWord, "class"))
- chAttr = SCE_P_CLASSNAME;
- else if (0 == strcmp(prevWord, "def"))
- chAttr = SCE_P_DEFNAME;
- else if (wordIsNumber)
- chAttr = SCE_P_NUMBER;
- else if (keywords.InList(s))
- chAttr = SCE_P_WORD;
- styler.ColourTo(end, chAttr);
- strcpy(prevWord, s);
-}
-
-static bool IsPyComment(StylingContext &styler, int pos, int len) {
- return len>0 && styler[pos]=='#';
-}
-
-static void ColourisePyDoc(int codePage, int startPos, int length, int initStyle, WordList &keywords, StylingContext &styler) {
- //Platform::DebugPrintf("Python coloured\n");
- bool fold = styler.GetPropSet().GetInt("fold");
- int whingeLevel = styler.GetPropSet().GetInt("tab.timmy.whinge.level");
- char prevWord[200];
- prevWord[0] = '\0';
- if (length == 0)
- return ;
- int lineCurrent = styler.GetLine(startPos);
- int spaceFlags = 0;
- // TODO: Need to check previous line for indentation for both folding and bad indentation
- int indentCurrent = IndentAmount(styler, lineCurrent, &spaceFlags, IsPyComment);
-
- int state = initStyle & 31;
- char chPrev = ' ';
- char chPrev2 = ' ';
- char chNext = styler[startPos];
- char chNext2 = styler[startPos];
- styler.StartSegment(startPos);
- int lengthDoc = startPos + length;
- bool atStartLine = true;
- for (int i = startPos; i <= lengthDoc; i++) {
-
- if (atStartLine) {
- if (whingeLevel == 1) {
- styler.SetFlags((spaceFlags & wsInconsistent) ? 64 : 0, state);
- } else if (whingeLevel == 2) {
- styler.SetFlags((spaceFlags & wsSpaceTab) ? 64 : 0, state);
- } else if (whingeLevel == 3) {
- styler.SetFlags((spaceFlags & wsSpace) ? 64 : 0, state);
- } else if (whingeLevel == 4) {
- styler.SetFlags((spaceFlags & wsTab) ? 64 : 0, state);
- }
- atStartLine = false;
- }
-
- char ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- chNext2 = styler.SafeGetCharAt(i + 2);
-
- if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
- if ((state == SCE_P_DEFAULT) || (state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE)) {
- // Perform colourisation of white space and triple quoted strings at end of each line to allow
- // tab marking to work inside white space and triple quoted strings
- styler.ColourTo(i, state);
- }
-
- int lev = indentCurrent;
- int indentNext = IndentAmount(styler, lineCurrent + 1, &spaceFlags, IsPyComment);
- if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
- // Only non whitespace lines can be headers
- if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK)) {
- lev |= SC_FOLDLEVELHEADERFLAG;
- }
- }
- indentCurrent = indentNext;
- if (fold) {
- styler.SetLevel(lineCurrent, lev);
- }
- lineCurrent++;
- atStartLine = true;
- }
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chNext = styler.SafeGetCharAt(i + 2);
- chPrev = ' ';
- chPrev2 = ' ';
- i += 1;
- continue;
- }
-
- if (state == SCE_P_STRINGEOL) {
- if (ch != '\r' && ch != '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_P_DEFAULT;
- }
- }
- if (state == SCE_P_DEFAULT) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_P_WORD;
- } else if (ch == '#') {
- styler.ColourTo(i - 1, state);
- state = chNext == '#' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_P_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_P_STRING;
- }
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_P_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_P_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_P_OPERATOR);
- }
- } else if (state == SCE_P_WORD) {
- if (!iswordchar(ch)) {
- classifyWordPy(styler.GetStartSegment(), i - 1, keywords, styler, prevWord);
- state = SCE_P_DEFAULT;
- if (ch == '#') {
- state = chNext == '#' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE;
- } else if (ch == '\"') {
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_P_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_P_STRING;
- }
- } else if (ch == '\'') {
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_P_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_P_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_P_OPERATOR);
- }
- }
- } else {
- if (state == SCE_P_COMMENTLINE || state == SCE_P_COMMENTBLOCK) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_P_DEFAULT;
- }
- } else if (state == SCE_P_STRING) {
- if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
- styler.ColourTo(i - 1, state);
- state = SCE_P_STRINGEOL;
- } else if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_P_DEFAULT;
- }
- } else if (state == SCE_P_CHARACTER) {
- if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
- styler.ColourTo(i - 1, state);
- state = SCE_P_STRINGEOL;
- } else if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, state);
- state = SCE_P_DEFAULT;
- }
- } else if (state == SCE_P_TRIPLE) {
- if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
- styler.ColourTo(i, state);
- state = SCE_P_DEFAULT;
- }
- } else if (state == SCE_P_TRIPLEDOUBLE) {
- if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
- styler.ColourTo(i, state);
- state = SCE_P_DEFAULT;
- }
- }
- }
- chPrev2 = chPrev;
- chPrev = ch;
- }
- if (state == SCE_P_WORD) {
- classifyWordPy(styler.GetStartSegment(), lengthDoc, keywords, styler, prevWord);
- } else {
- styler.ColourTo(lengthDoc, state);
- }
-}
-
-static void ColouriseBatchLine(char *lineBuffer, int endLine, StylingContext &styler) {
- if (0 == strncmp(lineBuffer, "REM", 3)) {
- styler.ColourTo(endLine, 1);
- } else if (0 == strncmp(lineBuffer, "rem", 3)) {
- styler.ColourTo(endLine, 1);
- } else if (0 == strncmp(lineBuffer, "SET", 3)) {
- styler.ColourTo(endLine, 2);
- } else if (0 == strncmp(lineBuffer, "set", 3)) {
- styler.ColourTo(endLine, 2);
- } else if (lineBuffer[0] == ':') {
- styler.ColourTo(endLine, 3);
- } else {
- styler.ColourTo(endLine, 0);
- }
-}
-
-static void ColouriseBatchDoc(int startPos, int length, int, StylingContext &styler) {
- char lineBuffer[1024];
- styler.StartSegment(startPos);
- unsigned int linePos = 0;
- for (int i = startPos; i < startPos + length; i++) {
- lineBuffer[linePos++] = styler[i];
- if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
- ColouriseBatchLine(lineBuffer, i, styler);
- linePos = 0;
- }
- }
- if (linePos > 0)
- ColouriseBatchLine(lineBuffer, startPos + length, styler);
-}
-
-enum { eScriptNone, eScriptJS, eScriptVBS, eScriptPython };
-static int segIsScriptingIndicator(StylingContext &styler, unsigned int start, unsigned int end, int prevValue) {
- char s[100];
- s[0] = '\0';
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = tolower(styler[start + i]);
- s[i + 1] = '\0';
- }
-Platform::DebugPrintf("Scripting indicator [%s]\n", s);
- if (strstr(s, "vbs"))
- return eScriptVBS;
- if (strstr(s, "pyth"))
- return eScriptPython;
- if (strstr(s, "javas"))
- return eScriptJS;
- if (strstr(s, "jscr"))
- return eScriptJS;
-
- return prevValue;
-}
-
-static void classifyAttribHTML(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.') ||
- (styler[start] == '-') || (styler[start] == '#');
- char chAttr = SCE_H_ATTRIBUTEUNKNOWN;
- if (wordIsNumber) {
- chAttr = SCE_H_NUMBER;
- } else {
- char s[100];
- s[0] = '\0';
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = tolower(styler[start + i]);
- s[i + 1] = '\0';
- }
- if (keywords.InList(s))
- chAttr = SCE_H_ATTRIBUTE;
- }
- styler.ColourTo(end, chAttr);
-}
-
-static int classifyTagHTML(unsigned int start, unsigned int end,
- WordList &keywords, StylingContext &styler) {
- char s[100];
- // Copy after the '<'
- unsigned int i = 0;
- for (unsigned int cPos=start; cPos <= end && i < 30; cPos++) {
- char ch = styler[cPos];
- if (ch != '<')
- s[i++] = tolower(ch);
- }
- s[i] = '\0';
- char chAttr = SCE_H_TAGUNKNOWN;
- if (s[0] == '!' && s[1] == '-' && s[2] == '-') { //Comment
- chAttr = SCE_H_COMMENT;
- } else if (s[0] == '/') { // Closing tag
- if (keywords.InList(s + 1))
- chAttr = SCE_H_TAG;
- } else {
- if (keywords.InList(s)) {
- chAttr = SCE_H_TAG;
- if (0 == strcmp(s, "script"))
- chAttr = SCE_H_SCRIPT;
- }
- }
- styler.ColourTo(end, chAttr);
- return chAttr;
-}
-
-static void classifyWordHTJS(unsigned int start, unsigned int end,
- WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HJ_WORD;
- if (wordIsNumber)
- chAttr = SCE_HJ_NUMBER;
- else {
- if (keywords.InList(s))
- chAttr = SCE_HJ_KEYWORD;
- }
- styler.ColourTo(end, chAttr);
-}
-
-static void classifyWordHTJSA(unsigned int start, unsigned int end,
- WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HJA_WORD;
- if (wordIsNumber)
- chAttr = SCE_HJA_NUMBER;
- else {
- if (keywords.InList(s))
- chAttr = SCE_HJA_KEYWORD;
- }
- styler.ColourTo(end, chAttr);
-}
-
-static int classifyWordHTVB(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = tolower(styler[start + i]);
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HB_IDENTIFIER;
- if (wordIsNumber)
- chAttr = SCE_HB_NUMBER;
- else {
- if (keywords.InList(s)) {
- chAttr = SCE_HB_WORD;
- if (strcmp(s, "rem") == 0)
- chAttr = SCE_HB_COMMENTLINE;
- }
- }
- styler.ColourTo(end, chAttr);
- if (chAttr == SCE_HB_COMMENTLINE)
- return SCE_HB_COMMENTLINE;
- else
- return SCE_HB_DEFAULT;
-}
-
-static int classifyWordHTVBA(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = tolower(styler[start + i]);
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HBA_IDENTIFIER;
- if (wordIsNumber)
- chAttr = SCE_HBA_NUMBER;
- else {
- if (keywords.InList(s)) {
- chAttr = SCE_HBA_WORD;
- if (strcmp(s, "rem") == 0)
- chAttr = SCE_HBA_COMMENTLINE;
- }
- }
- styler.ColourTo(end, chAttr);
- if (chAttr == SCE_HBA_COMMENTLINE)
- return SCE_HBA_COMMENTLINE;
- else
- return SCE_HBA_DEFAULT;
-}
-
-static void classifyWordHTPy(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]);
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HP_IDENTIFIER;
- if (0 == strcmp(prevWord, "class"))
- chAttr = SCE_HP_CLASSNAME;
- else if (0 == strcmp(prevWord, "def"))
- chAttr = SCE_HP_DEFNAME;
- else if (wordIsNumber)
- chAttr = SCE_HP_NUMBER;
- else if (keywords.InList(s))
- chAttr = SCE_HP_WORD;
- styler.ColourTo(end, chAttr);
- strcpy(prevWord, s);
-}
-
-static void classifyWordHTPyA(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]);
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = styler[start + i];
- s[i + 1] = '\0';
- }
- char chAttr = SCE_HPA_IDENTIFIER;
- if (0 == strcmp(prevWord, "class"))
- chAttr = SCE_HPA_CLASSNAME;
- else if (0 == strcmp(prevWord, "def"))
- chAttr = SCE_HPA_DEFNAME;
- else if (wordIsNumber)
- chAttr = SCE_HPA_NUMBER;
- else if (keywords.InList(s))
- chAttr = SCE_HPA_WORD;
- styler.ColourTo(end, chAttr);
- strcpy(prevWord, s);
-}
-
-inline bool ishtmlwordchar(char ch) {
- return isalnum(ch) || ch == '.' || ch == '-' || ch == '_' || ch == ':' || ch == '!' || ch == '#';
-}
-
-static bool InTagState(int state) {
- return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN ||
- state == SCE_H_SCRIPT ||
- state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN ||
- state == SCE_H_NUMBER || state == SCE_H_OTHER ||
- state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING;
-}
-
-static bool isLineEnd(char ch) {
- return ch == '\r' || ch == '\n';
-}
-
-static void ColouriseHyperTextDoc(int codePage, int startPos, int length,
- int initStyle, WordList &keywords, WordList &keywords2, WordList &keywords3, WordList &keywords4,
- StylingContext &styler) {
-
- styler.StartAt(startPos, 127);
- bool lastTagWasScript = false;
- char prevWord[200];
- prevWord[0] = '\0';
- int scriptLanguage = eScriptJS;
- int state = initStyle;
- // If inside a tag, it may be a script tage, so reread from the start to ensure any language tas are seen
- if (InTagState(state)) {
- while ((startPos > 1) && (InTagState(styler.StyleAt(startPos - 1)))) {
- startPos--;
- }
- state = SCE_H_DEFAULT;
- }
- styler.StartAt(startPos, 127);
-
- int lineState = eScriptVBS;
- int lineCurrent = styler.GetLine(startPos);
- if (lineCurrent > 0)
- lineState = styler.GetLineState(lineCurrent);
- int defaultScript = lineState &0xff;
- int beforeASP = (lineState >> 8) &0xff;
- int inASP = (lineState >> 16) &0xff;
-
- char chPrev = ' ';
- char chPrev2 = ' ';
- styler.StartSegment(startPos);
- int lengthDoc = startPos + length;
- for (int i = startPos; i <= lengthDoc; i++) {
- char ch = styler[i];
- char chNext = styler.SafeGetCharAt(i + 1);
- char chNext2 = styler.SafeGetCharAt(i + 2);
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chPrev2 = ' ';
- chPrev = ' ';
- i += 1;
- continue;
- }
+LexerModule *LexerModule::base = 0;
- if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
- // New line -> record any line state onto /next/ line
- lineCurrent++;
- styler.SetLineState(lineCurrent,
- defaultScript | (beforeASP << 8) | (inASP << 16));
- }
-
- // Handle ASP even within other constructs as it is a preprocessor
- if ((ch == '<') && (chNext == '%')) {
- beforeASP = state;
- styler.ColourTo(i - 1, state);
- if (chNext2 == '@') {
- styler.ColourTo(i + 2, SCE_H_ASP);
- state = SCE_H_ASPAT;
- i+=2;
- } else {
- if (defaultScript == eScriptVBS)
- state = SCE_HBA_START;
- else if (defaultScript == eScriptPython)
- state = SCE_HPA_START;
- else
- state = SCE_HJA_START;
- if (chNext2 == '=') {
- styler.ColourTo(i + 2, SCE_H_ASP);
- i+=2;
- } else {
- styler.ColourTo(i + 1, SCE_H_ASP);
- i++;
- }
- }
- inASP = 1;
- continue;
- }
- if (inASP && (ch == '%') && (chNext == '>')) {
- if (state == SCE_H_ASPAT)
- defaultScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i-1, defaultScript);
- // Bounce out of any ASP mode
- if (state == SCE_HJA_WORD) {
- classifyWordHTJSA(styler.GetStartSegment(), i - 1, keywords2, styler);
- } else if (state == SCE_HBA_WORD) {
- classifyWordHTVBA(styler.GetStartSegment(), i - 1, keywords3, styler);
- } else if (state == SCE_HPA_WORD) {
- classifyWordHTPyA(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
- } else {
- styler.ColourTo(i - 1, state);
- }
- //if (state == SCE_H_ASPAT)
- // styler.ColourTo(i+1, SCE_H_ASPAT);
- //else
- styler.ColourTo(i+1, SCE_H_ASP);
- i++;
- state = beforeASP;
- beforeASP = SCE_H_DEFAULT;
- inASP = 0;
- continue;
- }
-
- if (state == SCE_H_DEFAULT) {
- if (ch == '<') {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- if (chNext == '?') {
- styler.ColourTo(i + 1, SCE_H_XMLSTART);
- i++;
- ch = chNext;
- }
- } else if (ch == '&') {
- styler.ColourTo(i - 1, SCE_H_DEFAULT);
- state = SCE_H_ENTITY;
- }
- } else if (state == SCE_H_COMMENT) {
- if ((ch == '>') && (chPrev == '-')) {
- styler.ColourTo(i, state);
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_H_ENTITY) {
- if (ch == ';') {
- styler.ColourTo(i, state);
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_H_TAGUNKNOWN) {
- if (!ishtmlwordchar(ch) && ch != '/' && ch != '-') {
- int eClass = classifyTagHTML(styler.GetStartSegment(), i - 1, keywords, styler);
- lastTagWasScript = eClass == SCE_H_SCRIPT;
- if (lastTagWasScript) {
- scriptLanguage = eScriptJS;
- eClass = SCE_H_TAG;
- }
- if (ch == '>') {
- styler.ColourTo(i, SCE_H_TAG);
- if (lastTagWasScript) {
- if (scriptLanguage == eScriptVBS)
- state = SCE_HB_START;
- else if (scriptLanguage == eScriptPython)
- state = SCE_HP_START;
- else
- state = SCE_HJ_START;
- } else {
- state = SCE_H_DEFAULT;
- }
- } else {
- if (eClass == SCE_H_COMMENT) {
- state = SCE_H_COMMENT;
- } else {
- state = SCE_H_OTHER;
- }
- }
- }
- } else if (state == SCE_H_ATTRIBUTE) {
- if (!ishtmlwordchar(ch) && ch != '/' && ch != '-') {
- if (lastTagWasScript)
- scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i-1, scriptLanguage);
- classifyAttribHTML(styler.GetStartSegment(), i - 1, keywords, styler);
- if (ch == '>') {
- styler.ColourTo(i, SCE_H_TAG);
- if (lastTagWasScript) {
- if (scriptLanguage == eScriptVBS)
- state = SCE_HB_START;
- else if (scriptLanguage == eScriptPython)
- state = SCE_HP_START;
- else
- state = SCE_HJ_START;
- } else {
- state = SCE_H_DEFAULT;
- }
- } else {
- state = SCE_H_OTHER;
- }
- }
- } else if (state == SCE_H_ASP) {
- if ((ch == '>') && (chPrev == '%')) {
- styler.ColourTo(i, state);
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_H_ASPAT) {
- if ((ch == '>') && (chPrev == '%')) {
- styler.ColourTo(i, state);
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_H_OTHER) {
- if (ch == '>') {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_H_TAG);
- if (lastTagWasScript) {
- if (scriptLanguage == eScriptVBS)
- state = SCE_HB_START;
- else if (scriptLanguage == eScriptPython)
- state = SCE_HP_START;
- else
- state = SCE_HJ_START;
- } else {
- state = SCE_H_DEFAULT;
- }
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_H_DOUBLESTRING;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_H_SINGLESTRING;
- } else if (ch == '/' && chNext == '>') {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_TAGEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- } else if (ch == '?' && chNext == '>') {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_XMLEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- } else if (ishtmlwordchar(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_ATTRIBUTE;
- }
- } else if (state == SCE_H_DOUBLESTRING) {
- if (ch == '\"') {
- if (lastTagWasScript)
- scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
- styler.ColourTo(i, SCE_H_DOUBLESTRING);
- state = SCE_H_OTHER;
- }
- } else if (state == SCE_H_SINGLESTRING) {
- if (ch == '\'') {
- if (lastTagWasScript)
- scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
- styler.ColourTo(i, SCE_H_SINGLESTRING);
- state = SCE_H_OTHER;
- }
- } else if (state == SCE_HJ_DEFAULT || state == SCE_HJ_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_WORD;
- } else if (ch == '/' && chNext == '*') {
- styler.ColourTo(i - 1, state);
- if (chNext2 == '*')
- state = SCE_HJ_COMMENTDOC;
- else
- state = SCE_HJ_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_DOUBLESTRING;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_SINGLESTRING;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HJ_SYMBOLS);
- state = SCE_HJ_DEFAULT;
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HJ_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_DEFAULT;
- }
- }
- } else if (state == SCE_HJ_WORD) {
- if (!iswordchar(ch)) {
- classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler);
- //styler.ColourTo(i - 1, eHTJSKeyword);
- state = SCE_HJ_DEFAULT;
- if (ch == '/' && chNext == '*') {
- if (chNext2 == '*')
- state = SCE_HJ_COMMENTDOC;
- else
- state = SCE_HJ_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_HJ_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_HJ_DOUBLESTRING;
- } else if (ch == '\'') {
- state = SCE_HJ_SINGLESTRING;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HJ_SYMBOLS);
- state = SCE_HJ_DEFAULT;
- }
- }
- } else if (state == SCE_HJ_COMMENT) {
- if (ch == '/' && chPrev == '*') {
- state = SCE_HJ_DEFAULT;
- styler.ColourTo(i, SCE_HJ_COMMENT);
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_TAGEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_HJ_COMMENTDOC) {
- if (ch == '/' && chPrev == '*') {
- state = SCE_HJ_DEFAULT;
- styler.ColourTo(i, SCE_HJ_COMMENTDOC);
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_TAGEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_HJ_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, SCE_HJ_COMMENTLINE);
- state = SCE_HJ_DEFAULT;
- } else if ((ch == '<') && (chNext == '/')) {
- // Common to hide end script tag in comment
- styler.ColourTo(i - 1, SCE_HJ_COMMENTLINE);
- state = SCE_H_TAGUNKNOWN;
- }
- } else if (state == SCE_HJ_DOUBLESTRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, SCE_HJ_DOUBLESTRING);
- state = SCE_HJ_DEFAULT;
- i++;
- ch = chNext;
- } else if (isLineEnd(ch)) {
- styler.ColourTo(i-1, state);
- state = SCE_HJ_STRINGEOL;
- }
- } else if (state == SCE_HJ_SINGLESTRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, SCE_HJ_SINGLESTRING);
- state = SCE_HJ_DEFAULT;
- i++;
- ch = chNext;
- } else if (isLineEnd(ch)) {
- styler.ColourTo(i-1, state);
- state = SCE_HJ_STRINGEOL;
- }
- } else if (state == SCE_HJ_STRINGEOL) {
- if (!isLineEnd(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJ_DEFAULT;
- } else if (!isLineEnd(chNext)) {
- styler.ColourTo(i, state);
- state = SCE_HJ_DEFAULT;
- }
- } else if (state == SCE_HJA_DEFAULT || state == SCE_HJA_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_WORD;
- } else if (ch == '/' && chNext == '*') {
- styler.ColourTo(i - 1, state);
- if (chNext2 == '*')
- state = SCE_HJA_COMMENTDOC;
- else
- state = SCE_HJA_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_DOUBLESTRING;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_SINGLESTRING;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HJA_SYMBOLS);
- state = SCE_HJA_DEFAULT;
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HJA_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_DEFAULT;
- }
- }
- } else if (state == SCE_HJA_WORD) {
- if (!iswordchar(ch)) {
- classifyWordHTJSA(styler.GetStartSegment(), i - 1, keywords2, styler);
- //styler.ColourTo(i - 1, eHTJSKeyword);
- state = SCE_HJA_DEFAULT;
- if (ch == '/' && chNext == '*') {
- if (chNext2 == '*')
- state = SCE_HJA_COMMENTDOC;
- else
- state = SCE_HJA_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_HJA_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_HJA_DOUBLESTRING;
- } else if (ch == '\'') {
- state = SCE_HJA_SINGLESTRING;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HJA_SYMBOLS);
- state = SCE_HJA_DEFAULT;
- }
- }
- } else if (state == SCE_HJA_COMMENT) {
- if (ch == '/' && chPrev == '*') {
- state = SCE_HJA_DEFAULT;
- styler.ColourTo(i, SCE_HJA_COMMENT);
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_TAGEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_HJA_COMMENTDOC) {
- if (ch == '/' && chPrev == '*') {
- state = SCE_HJA_DEFAULT;
- styler.ColourTo(i, SCE_HJA_COMMENTDOC);
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i + 1, SCE_H_TAGEND);
- i++;
- ch = chNext;
- state = SCE_H_DEFAULT;
- }
- } else if (state == SCE_HJA_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, SCE_HJA_COMMENTLINE);
- state = SCE_HJA_DEFAULT;
- } else if ((ch == '<') && (chNext == '/')) {
- // Common to hide end script tag in comment
- styler.ColourTo(i - 1, SCE_HJA_COMMENTLINE);
- state = SCE_H_TAGUNKNOWN;
- }
- } else if (state == SCE_HJA_DOUBLESTRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, SCE_HJA_DOUBLESTRING);
- state = SCE_HJA_DEFAULT;
- i++;
- ch = chNext;
- } else if (isLineEnd(ch)) {
- styler.ColourTo(i-1, state);
- state = SCE_HJA_STRINGEOL;
- }
- } else if (state == SCE_HJA_SINGLESTRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, SCE_HJA_SINGLESTRING);
- state = SCE_HJA_DEFAULT;
- i++;
- ch = chNext;
- } else if (isLineEnd(ch)) {
- styler.ColourTo(i-1, state);
- state = SCE_HJA_STRINGEOL;
- }
- } else if (state == SCE_HJA_STRINGEOL) {
- if (!isLineEnd(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HJA_DEFAULT;
- } else if (!isLineEnd(chNext)) {
- styler.ColourTo(i, state);
- state = SCE_HJA_DEFAULT;
- }
- } else if (state == SCE_HB_DEFAULT || state == SCE_HB_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_WORD;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_STRING;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HB_DEFAULT);
- state = SCE_HB_DEFAULT;
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HB_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_DEFAULT;
- }
- }
- } else if (state == SCE_HB_WORD) {
- if (!iswordchar(ch)) {
- state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler);
- if (state == SCE_HB_DEFAULT) {
- if (ch == '\"') {
- state = SCE_HB_STRING;
- } else if (ch == '\'') {
- state = SCE_HB_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HB_DEFAULT);
- state = SCE_HB_DEFAULT;
- }
- }
- }
- } else if (state == SCE_HB_STRING) {
- if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HB_DEFAULT;
- i++;
- ch = chNext;
- } else if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i-1, state);
- state = SCE_HB_STRINGEOL;
- }
- } else if (state == SCE_HB_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_DEFAULT;
- } else if ((ch == '<') && (chNext == '/')) {
- // Common to hide end script tag in comment
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- }
- } else if (state == SCE_HB_STRINGEOL) {
- if (!isLineEnd(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HB_DEFAULT;
- } else if (!isLineEnd(chNext)) {
- styler.ColourTo(i, state);
- state = SCE_HB_DEFAULT;
- }
- } else if (state == SCE_HBA_DEFAULT || state == SCE_HBA_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_WORD;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_STRING;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HBA_DEFAULT);
- state = SCE_HBA_DEFAULT;
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HBA_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_DEFAULT;
- }
- }
- } else if (state == SCE_HBA_WORD) {
- if (!iswordchar(ch)) {
- state = classifyWordHTVBA(styler.GetStartSegment(), i - 1, keywords3, styler);
- if (state == SCE_HBA_DEFAULT) {
- if (ch == '\"') {
- state = SCE_HBA_STRING;
- } else if (ch == '\'') {
- state = SCE_HBA_COMMENTLINE;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HBA_DEFAULT);
- state = SCE_HBA_DEFAULT;
- }
- }
- }
- } else if (state == SCE_HBA_STRING) {
- if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HBA_DEFAULT;
- i++;
- ch = chNext;
- } else if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i-1, state);
- state = SCE_HBA_STRINGEOL;
- }
- } else if (state == SCE_HBA_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_DEFAULT;
- } else if ((ch == '<') && (chNext == '/')) {
- // Common to hide end script tag in comment
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- }
- } else if (state == SCE_HBA_STRINGEOL) {
- if (!isLineEnd(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HBA_DEFAULT;
- } else if (!isLineEnd(chNext)) {
- styler.ColourTo(i, state);
- state = SCE_HBA_DEFAULT;
- }
- } else if (state == SCE_HP_DEFAULT || state == SCE_HP_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HP_WORD;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HP_COMMENTLINE;
- } else if (ch == '#') {
- styler.ColourTo(i - 1, state);
- state = SCE_HP_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_HP_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HP_STRING;
- }
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_HP_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HP_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HP_OPERATOR);
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HP_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HP_DEFAULT;
- }
- }
- } else if (state == SCE_HP_WORD) {
- if (!iswordchar(ch)) {
- classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
- state = SCE_HP_DEFAULT;
- if (ch == '#') {
- state = SCE_HP_COMMENTLINE;
- } else if (ch == '\"') {
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_HP_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HP_STRING;
- }
- } else if (ch == '\'') {
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_HP_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HP_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HP_OPERATOR);
- }
- }
- } else if (state == SCE_HP_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_HP_DEFAULT;
- }
- } else if (state == SCE_HP_STRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HP_DEFAULT;
- }
- } else if (state == SCE_HP_CHARACTER) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, state);
- state = SCE_HP_DEFAULT;
- }
- } else if (state == SCE_HP_TRIPLE) {
- if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
- styler.ColourTo(i, state);
- state = SCE_HP_DEFAULT;
- }
- } else if (state == SCE_HP_TRIPLEDOUBLE) {
- if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HP_DEFAULT;
- }
- } else if (state == SCE_HPA_DEFAULT || state == SCE_HPA_START) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_HPA_WORD;
- } else if ((ch == '<') && (chNext == '/')) {
- styler.ColourTo(i - 1, state);
- state = SCE_H_TAGUNKNOWN;
- } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
- styler.SafeGetCharAt(i + 3) == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_HPA_COMMENTLINE;
- } else if (ch == '#') {
- styler.ColourTo(i - 1, state);
- state = SCE_HPA_COMMENTLINE;
- } else if (ch == '\"') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_HPA_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HPA_STRING;
- }
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_HPA_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HPA_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_HPA_OPERATOR);
- } else if ((ch == ' ') || (ch == '\t')) {
- if (state == SCE_HPA_START) {
- styler.ColourTo(i - 1, state);
- state = SCE_HPA_DEFAULT;
- }
- }
- } else if (state == SCE_HPA_WORD) {
- if (!iswordchar(ch)) {
- classifyWordHTPyA(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
- state = SCE_HPA_DEFAULT;
- if (ch == '#') {
- state = SCE_HPA_COMMENTLINE;
- } else if (ch == '\"') {
- if (chNext == '\"' && chNext2 == '\"') {
- i += 2;
- state = SCE_HPA_TRIPLEDOUBLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HPA_STRING;
- }
- } else if (ch == '\'') {
- if (chNext == '\'' && chNext2 == '\'') {
- i += 2;
- state = SCE_HPA_TRIPLE;
- ch = ' ';
- chPrev = ' ';
- chNext = styler.SafeGetCharAt(i + 1);
- } else {
- state = SCE_HPA_CHARACTER;
- }
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HPA_OPERATOR);
- }
- }
- } else if (state == SCE_HPA_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_HPA_DEFAULT;
- }
- } else if (state == SCE_HPA_STRING) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HPA_DEFAULT;
- }
- } else if (state == SCE_HPA_CHARACTER) {
- if (ch == '\\') {
- if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
- i++;
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- } else if (ch == '\'') {
- styler.ColourTo(i, state);
- state = SCE_HPA_DEFAULT;
- }
- } else if (state == SCE_HPA_TRIPLE) {
- if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
- styler.ColourTo(i, state);
- state = SCE_HPA_DEFAULT;
- }
- } else if (state == SCE_HPA_TRIPLEDOUBLE) {
- if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
- styler.ColourTo(i, state);
- state = SCE_HPA_DEFAULT;
- }
- }
- if (state == SCE_HB_DEFAULT) { // One of the above succeeded
- if (ch == '\"') {
- state = SCE_HB_STRING;
- } else if (ch == '\'') {
- state = SCE_HB_COMMENTLINE;
- } else if (iswordstart(ch)) {
- state = SCE_HB_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HB_DEFAULT);
- }
- }
- if (state == SCE_HBA_DEFAULT) { // One of the above succeeded
- if (ch == '\"') {
- state = SCE_HBA_STRING;
- } else if (ch == '\'') {
- state = SCE_HBA_COMMENTLINE;
- } else if (iswordstart(ch)) {
- state = SCE_HBA_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HBA_DEFAULT);
- }
- }
- if (state == SCE_HJ_DEFAULT) { // One of the above succeeded
- if (ch == '/' && chNext == '*') {
- if (styler.SafeGetCharAt(i + 2) == '*')
- state = SCE_HJ_COMMENTDOC;
- else
- state = SCE_HJ_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_HJ_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_HJ_DOUBLESTRING;
- } else if (ch == '\'') {
- state = SCE_HJ_SINGLESTRING;
- } else if (iswordstart(ch)) {
- state = SCE_HJ_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HJ_SYMBOLS);
- }
- }
- if (state == SCE_HJA_DEFAULT) { // One of the above succeeded
- if (ch == '/' && chNext == '*') {
- if (styler.SafeGetCharAt(i + 2) == '*')
- state = SCE_HJA_COMMENTDOC;
- else
- state = SCE_HJA_COMMENT;
- } else if (ch == '/' && chNext == '/') {
- state = SCE_HJA_COMMENTLINE;
- } else if (ch == '\"') {
- state = SCE_HJA_DOUBLESTRING;
- } else if (ch == '\'') {
- state = SCE_HJA_SINGLESTRING;
- } else if (iswordstart(ch)) {
- state = SCE_HJA_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_HJA_SYMBOLS);
- }
- }
- chPrev2 = chPrev;
- chPrev = ch;
- }
- styler.ColourTo(lengthDoc - 1, state);
-}
-
-static void ColourisePropsLine(char *lineBuffer, int lengthLine, int startLine, int endPos, StylingContext &styler) {
- int i = 0;
- while (isspace(lineBuffer[i]) && (i < lengthLine)) // Skip initial spaces
- i++;
- if (lineBuffer[i] == '#' || lineBuffer[i] == '!' || lineBuffer[i] == ';') {
- styler.ColourTo(endPos, 1);
- } else if (lineBuffer[i] == '[') {
- styler.ColourTo(endPos, 2);
- } else if (lineBuffer[i] == '@') {
- styler.ColourTo(startLine+i, 4);
- if (lineBuffer[++i] == '=')
- styler.ColourTo(startLine+i, 3);
- styler.ColourTo(endPos, 0);
- } else {
- while (lineBuffer[i] != '=' && (i < lengthLine)) // Search the '=' character
- i++;
- if (lineBuffer[i] == '=') {
- styler.ColourTo(startLine+i-1, 0);
- styler.ColourTo(startLine+i, 3);
- styler.ColourTo(endPos, 0);
- } else {
- styler.ColourTo(endPos, 0);
- }
- }
-}
-
-static void ColourisePropsDoc(int startPos, int length, int, StylingContext &styler) {
- char lineBuffer[1024];
- styler.StartSegment(startPos);
- unsigned int linePos = 0;
- int startLine = startPos;
- for (int i = startPos; i <= startPos + length; i++) {
- lineBuffer[linePos++] = styler[i];
- if ((styler[i] == '\r' && styler.SafeGetCharAt(i+1) != '\n') ||
- styler[i] == '\n' ||
- (linePos >= sizeof(lineBuffer) - 1)) {
- lineBuffer[linePos] = '\0';
- ColourisePropsLine(lineBuffer, linePos, startLine, i, styler);
- linePos = 0;
- startLine = i+1;
- }
- }
- if (linePos > 0)
- ColourisePropsLine(lineBuffer, linePos, startLine, startPos + length, styler);
-}
-
-static void ColouriseMakeLine(char *lineBuffer, int lengthLine, int endPos, StylingContext &styler) {
- int i = 0;
- while (isspace(lineBuffer[i]) && (i < lengthLine))
- i++;
- if (lineBuffer[i] == '#' || lineBuffer[i] == '!') {
- styler.ColourTo(endPos, 1);
- } else {
- styler.ColourTo(endPos, 0);
- }
-}
-
-static void ColouriseMakeDoc(int startPos, int length, int, StylingContext &styler) {
- char lineBuffer[1024];
- styler.StartSegment(startPos);
- unsigned int linePos = 0;
- for (int i = startPos; i <= startPos + length; i++) {
- lineBuffer[linePos++] = styler[i];
- if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
- ColouriseMakeLine(lineBuffer, linePos, i, styler);
- linePos = 0;
- }
- }
- if (linePos > 0)
- ColouriseMakeLine(lineBuffer, linePos, startPos + length, styler);
-}
-
-static void ColouriseErrorListLine(char *lineBuffer, int lengthLine, int endPos, StylingContext &styler) {
- if (lineBuffer[0] == '>') {
- // Command or return status
- styler.ColourTo(endPos, 4);
- } else if (strstr(lineBuffer, "File \"") && strstr(lineBuffer, ", line ")) {
- styler.ColourTo(endPos, 1);
- } else if (0 == strncmp(lineBuffer, "Error ", strlen("Error "))) {
- // Borland error message
- styler.ColourTo(endPos, 5);
- } else if (0 == strncmp(lineBuffer, "Warning ", strlen("Warning "))) {
- // Borland warning message
- styler.ColourTo(endPos, 5);
- } else {
- // Look for <filename>:<line>:message
- // Look for <filename>(line)message
- // Look for <filename>(line,pos)message
- int state = 0;
- for (int i = 0; i < lengthLine; i++) {
- if (state == 0 && lineBuffer[i] == ':' && isdigit(lineBuffer[i + 1])) {
- state = 1;
- } else if (state == 0 && lineBuffer[i] == '(') {
- state = 10;
- } else if (state == 1 && isdigit(lineBuffer[i])) {
- state = 2;
- } else if (state == 2 && lineBuffer[i] == ':') {
- state = 3;
- break;
- } else if (state == 2 && !isdigit(lineBuffer[i])) {
- state = 99;
- } else if (state == 10 && isdigit(lineBuffer[i])) {
- state = 11;
- } else if (state == 11 && lineBuffer[i] == ',') {
- state = 14;
- } else if (state == 11 && lineBuffer[i] == ')') {
- state = 12;
- break;
- } else if (state == 12 && lineBuffer[i] == ':') {
- state = 13;
- } else if (state == 14 && lineBuffer[i] == ')') {
- state = 15;
- break;
- } else if (((state == 11) || (state == 14)) && !((lineBuffer[i] == ' ') || isdigit(lineBuffer[i]))) {
- state = 99;
- }
- }
- if (state == 3) {
- styler.ColourTo(endPos, 2);
- } else if ((state == 14) || (state == 15)) {
- styler.ColourTo(endPos, 3);
- } else {
- styler.ColourTo(endPos, 0);
- }
- }
-}
-
-static void ColouriseErrorListDoc(int startPos, int length, int, StylingContext &styler) {
- char lineBuffer[1024];
- styler.StartSegment(startPos);
- unsigned int linePos = 0;
- for (int i = startPos; i <= startPos + length; i++) {
- lineBuffer[linePos++] = styler[i];
- if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
- ColouriseErrorListLine(lineBuffer, linePos, i, styler);
- linePos = 0;
- }
- }
- if (linePos > 0)
- ColouriseErrorListLine(lineBuffer, linePos, startPos + length, styler);
-}
-
-static void classifyWordSQL(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
- char s[100];
- bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
- for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
- s[i] = toupper(styler[start + i]);
- s[i + 1] = '\0';
- }
- char chAttr = SCE_C_IDENTIFIER;
- if (wordIsNumber)
- chAttr = SCE_C_NUMBER;
- else {
- if (keywords.InList(s))
- chAttr = SCE_C_WORD;
- }
- styler.ColourTo(end, chAttr);
-}
-
-static void ColouriseSQLDoc(int codePage, int startPos, int length,
- int initStyle, WordList &keywords, StylingContext &styler) {
-
- bool fold = styler.GetPropSet().GetInt("fold");
- int lineCurrent = styler.GetLine(startPos);
- int spaceFlags = 0;
- int indentCurrent = 0;
-
- int state = initStyle;
- char chPrev = ' ';
- char chNext = styler[startPos];
- styler.StartSegment(startPos);
- int lengthDoc = startPos + length;
- bool prevCr = false;
- for (int i = startPos; i <= lengthDoc; i++) {
- char ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
-
- if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
- indentCurrent = IndentAmount(styler, lineCurrent, &spaceFlags);
- int lev = indentCurrent;
- if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
- // Only non whitespace lines can be headers
- int indentNext = IndentAmount(styler, lineCurrent + 1, &spaceFlags);
- if (indentCurrent < (indentNext & ~SC_FOLDLEVELWHITEFLAG)) {
- lev |= SC_FOLDLEVELHEADERFLAG;
- }
- }
- if (fold) {
- styler.SetLevel(lineCurrent, lev);
- }
- }
-
- if (IsLeadByte(codePage, ch)) { // dbcs
- chNext = styler.SafeGetCharAt(i + 2);
- chPrev = ' ';
- i += 1;
- continue;
- }
-
- if (state == SCE_C_DEFAULT) {
- if (iswordstart(ch)) {
- styler.ColourTo(i - 1, state);
- state = SCE_C_WORD;
- } else if (ch == '/' && chNext == '*') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_COMMENT;
- } else if (ch == '-' && chNext == '-') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\'') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_STRING;
- } else if (isoperator(ch)) {
- styler.ColourTo(i - 1, state);
- styler.ColourTo(i, SCE_C_OPERATOR);
- }
- } else if (state == SCE_C_WORD) {
- if (!iswordchar(ch)) {
- classifyWordSQL(styler.GetStartSegment(), i - 1, keywords, styler);
- state = SCE_C_DEFAULT;
- if (ch == '/' && chNext == '*') {
- state = SCE_C_COMMENT;
- } else if (ch == '-' && chNext == '-') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\'') {
- state = SCE_C_STRING;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_C_OPERATOR);
- }
- }
- } else {
- if (state == SCE_C_COMMENT) {
- if (ch == '/' && chPrev == '*') {
- if (((i > styler.GetStartSegment() + 2) || ((initStyle == SCE_C_COMMENT) &&
- (styler.GetStartSegment() == startPos)))) {
- state = SCE_C_DEFAULT;
- styler.ColourTo(i, state);
- }
- }
- } else if (state == SCE_C_COMMENTLINE) {
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_C_DEFAULT;
- }
- } else if (state == SCE_C_STRING) {
- if (ch == '\'') {
- if ( chNext == '\'' ) {
- i++;
- } else {
- styler.ColourTo(i, state);
- state = SCE_C_DEFAULT;
- i++;
- }
- ch = chNext;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- }
- if (state == SCE_C_DEFAULT) { // One of the above succeeded
- if (ch == '/' && chNext == '*') {
- state = SCE_C_COMMENT;
- } else if (ch == '-' && chNext == '-') {
- state = SCE_C_COMMENTLINE;
- } else if (ch == '\'') {
- state = SCE_C_STRING;
- } else if (iswordstart(ch)) {
- state = SCE_C_WORD;
- } else if (isoperator(ch)) {
- styler.ColourTo(i, SCE_C_OPERATOR);
- }
- }
- }
- chPrev = ch;
- }
- styler.ColourTo(lengthDoc - 1, state);
+LexerModule::LexerModule(int language_, LexerFunction fn_) :
+ language(language_), fn(fn_) {
+ next = base;
+ base = this;
}
-void ColouriseDoc(int codePage, int startPos, int lengthDoc, int initStyle,
- int language, WordList *keywordlists[], StylingContext &styler) {
- //Platform::DebugPrintf("ColouriseDoc <%s>\n", language);
- if (language == SCLEX_PYTHON) {
- // Python uses a different mask because bad indentation is marked by oring with 32
- styler.StartAt(startPos, 127);
- ColourisePyDoc(codePage, startPos, lengthDoc, initStyle, *keywordlists[0], styler);
- } else if (language == SCLEX_PERL) {
- // Lexer for perl often has to backtrack to start of current style to determine
- // which characters are being used as quotes, how deeply nested is the
- // start position and what the termination string is for here documents
- ColourisePerlDoc(codePage, startPos, lengthDoc, initStyle, *keywordlists[0], styler);
- } else if ((language == SCLEX_HTML) || (language == SCLEX_XML)) {
- // Lexer for HTML requires more lexical states (6 bits worth) than most lexers
- ColouriseHyperTextDoc(codePage, startPos, lengthDoc, initStyle,
- *keywordlists[0], *keywordlists[1], *keywordlists[2], *keywordlists[3], styler);
- } else {
- styler.StartAt(startPos);
- if (language == SCLEX_CPP) {
- ColouriseCppDoc(codePage, startPos, lengthDoc, initStyle, *keywordlists[0], styler);
- } else if (language == SCLEX_SQL) {
- ColouriseSQLDoc(codePage, startPos, lengthDoc, initStyle, *keywordlists[0], styler);
- } else if (language == SCLEX_VB) {
- ColouriseVBDoc(codePage, startPos, lengthDoc, initStyle, *keywordlists[0], styler);
- } else if (language == SCLEX_PROPERTIES) {
- ColourisePropsDoc(startPos, lengthDoc, initStyle, styler);
- } else if (language == SCLEX_ERRORLIST) {
- ColouriseErrorListDoc(startPos, lengthDoc, initStyle, styler);
- } else if (language == SCLEX_MAKEFILE) {
- ColouriseMakeDoc(startPos, lengthDoc, initStyle, styler);
- } else if (language == SCLEX_BATCH) {
- ColouriseBatchDoc(startPos, lengthDoc, initStyle, styler);
- } else {
- // Null language means all style bytes are 0 so just mark the end - no need to fill in.
- styler.StartAt(startPos + lengthDoc - 1);
- styler.StartSegment(startPos + lengthDoc - 1);
- styler.ColourTo(startPos + lengthDoc - 1, 0);
+void LexerModule::Colourise(unsigned int startPos, int lengthDoc, int initStyle,
+ int language, WordList *keywordlists[], StylingContext &styler) {
+ LexerModule *lm = base;
+ while (lm) {
+ if (lm->language == language) {
+ lm->fn(startPos, lengthDoc, initStyle, keywordlists, styler);
+ return;
}
+ lm = lm->next;
}
+ // Unknown language
+ // Null language means all style bytes are 0 so just mark the end - no need to fill in.
+ styler.StartAt(startPos + lengthDoc - 1);
+ styler.StartSegment(startPos + lengthDoc - 1);
+ styler.ColourTo(startPos + lengthDoc - 1, 0);
}
diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx
new file mode 100644
index 000000000..c6d56702e
--- /dev/null
+++ b/src/LexCPP.cxx
@@ -0,0 +1,240 @@
+// SciTE - Scintilla based Text Editor
+// LexCPP.cxx - lexer for C++, C, Java, and Javascript
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+static void classifyWordCpp(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_C_IDENTIFIER;
+ if (wordIsNumber)
+ chAttr = SCE_C_NUMBER;
+ else {
+ if (keywords.InList(s))
+ chAttr = SCE_C_WORD;
+ }
+ styler.ColourTo(end, chAttr);
+}
+
+static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
+ StylingContext &styler) {
+
+ WordList &keywords = *keywordlists[0];
+
+ styler.StartAt(startPos);
+
+ bool fold = styler.GetPropSet().GetInt("fold");
+ int lineCurrent = styler.GetLine(startPos);
+ int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
+ int levelCurrent = levelPrev;
+
+ int state = initStyle;
+ char chPrev = ' ';
+ char chNext = styler[startPos];
+ unsigned int lengthDoc = startPos + length;
+ int visChars = 0;
+ styler.StartSegment(startPos);
+ for (unsigned int i = startPos; i <= lengthDoc; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+
+ if ((fold) && ((ch == '\r' && chNext != '\n') || (ch == '\n'))) {
+ int lev = levelPrev;
+ if (visChars == 0)
+ lev |= SC_FOLDLEVELWHITEFLAG;
+ if ((levelCurrent > levelPrev) && (visChars > 0))
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ styler.SetLevel(lineCurrent, lev);
+ lineCurrent++;
+ visChars = 0;
+ levelPrev = levelCurrent;
+ }
+ if (!isspace(ch))
+ visChars++;
+
+ if (styler.IsLeadByte(ch)) {
+ chNext = styler.SafeGetCharAt(i + 2);
+ chPrev = ' ';
+ i += 1;
+ continue;
+ }
+
+ if (state == SCE_C_STRINGEOL) {
+ if (ch != '\r' && ch != '\n') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_DEFAULT;
+ }
+ }
+ if (state == SCE_C_DEFAULT) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_WORD;
+ } else if (ch == '/' && chNext == '*') {
+ styler.ColourTo(i-1, state);
+ if (styler.SafeGetCharAt(i + 2) == '*')
+ state = SCE_C_COMMENTDOC;
+ else
+ state = SCE_C_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_STRING;
+ } else if (ch == '\'') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_CHARACTER;
+ } else if (ch == '#') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_PREPROCESSOR;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i-1, state);
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ if ((ch == '{') || (ch == '}')) {
+ levelCurrent += (ch == '{') ? 1 : -1;
+ }
+ }
+ } else if (state == SCE_C_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordCpp(styler.GetStartSegment(), i - 1, keywords, styler);
+ state = SCE_C_DEFAULT;
+ if (ch == '/' && chNext == '*') {
+ if (styler.SafeGetCharAt(i + 2) == '*')
+ state = SCE_C_COMMENTDOC;
+ else
+ state = SCE_C_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_C_STRING;
+ } else if (ch == '\'') {
+ state = SCE_C_CHARACTER;
+ } else if (ch == '#') {
+ state = SCE_C_PREPROCESSOR;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ if ((ch == '{') || (ch == '}')) {
+ levelCurrent += (ch == '{') ? 1 : -1;
+ }
+ }
+ }
+ } else {
+ if (state == SCE_C_PREPROCESSOR) {
+ if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_DEFAULT;
+ }
+ } else if (state == SCE_C_COMMENT) {
+ if (ch == '/' && chPrev == '*') {
+ if (((i > styler.GetStartSegment() + 2) || (
+ (initStyle == SCE_C_COMMENT) &&
+ (styler.GetStartSegment() == static_cast<unsigned int>(startPos))))) {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ }
+ }
+ } else if (state == SCE_C_COMMENTDOC) {
+ if (ch == '/' && chPrev == '*') {
+ if (((i > styler.GetStartSegment() + 3) || (
+ (initStyle == SCE_C_COMMENTDOC) &&
+ (styler.GetStartSegment() == static_cast<unsigned int>(startPos))))) {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ }
+ }
+ } else if (state == SCE_C_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_DEFAULT;
+ }
+ } else if (state == SCE_C_STRING) {
+ if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_STRINGEOL;
+ } else if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (state == SCE_C_CHARACTER) {
+ if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
+ styler.ColourTo(i-1, state);
+ state = SCE_C_STRINGEOL;
+ } else if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
+ if (state == SCE_C_DEFAULT) { // One of the above succeeded
+ if (ch == '/' && chNext == '*') {
+ if (styler.SafeGetCharAt(i + 2) == '*')
+ state = SCE_C_COMMENTDOC;
+ else
+ state = SCE_C_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_C_STRING;
+ } else if (ch == '\'') {
+ state = SCE_C_CHARACTER;
+ } else if (ch == '#') {
+ state = SCE_C_PREPROCESSOR;
+ } else if (iswordstart(ch)) {
+ state = SCE_C_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ if ((ch == '{') || (ch == '}')) {
+ levelCurrent += (ch == '{') ? 1 : -1;
+ }
+ }
+ }
+ }
+ chPrev = ch;
+ }
+ styler.ColourTo(lengthDoc - 1, state);
+
+ // Fill in the real level of the next line, keeping the current flags as they will be filled in later
+ if (fold) {
+ int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
+ //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
+ styler.SetLevel(lineCurrent, levelPrev | flagsNext);
+
+ }
+}
+
+static LexerModule lmCPP(SCLEX_CPP, ColouriseCppDoc);
diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx
new file mode 100644
index 000000000..fa88ab6ac
--- /dev/null
+++ b/src/LexHTML.cxx
@@ -0,0 +1,1139 @@
+// SciTE - Scintilla based Text Editor
+// LexHTML.cxx - lexer for HTML
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+enum { eScriptNone, eScriptJS, eScriptVBS, eScriptPython };
+static int segIsScriptingIndicator(StylingContext &styler, unsigned int start, unsigned int end, int prevValue) {
+ char s[100];
+ s[0] = '\0';
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = tolower(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+Platform::DebugPrintf("Scripting indicator [%s]\n", s);
+ if (strstr(s, "vbs"))
+ return eScriptVBS;
+ if (strstr(s, "pyth"))
+ return eScriptPython;
+ if (strstr(s, "javas"))
+ return eScriptJS;
+ if (strstr(s, "jscr"))
+ return eScriptJS;
+
+ return prevValue;
+}
+
+static void classifyAttribHTML(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.') ||
+ (styler[start] == '-') || (styler[start] == '#');
+ char chAttr = SCE_H_ATTRIBUTEUNKNOWN;
+ if (wordIsNumber) {
+ chAttr = SCE_H_NUMBER;
+ } else {
+ char s[100];
+ s[0] = '\0';
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = tolower(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+ if (keywords.InList(s))
+ chAttr = SCE_H_ATTRIBUTE;
+ }
+ styler.ColourTo(end, chAttr);
+}
+
+static int classifyTagHTML(unsigned int start, unsigned int end,
+ WordList &keywords, StylingContext &styler) {
+ char s[100];
+ // Copy after the '<'
+ unsigned int i = 0;
+ for (unsigned int cPos=start; cPos <= end && i < 30; cPos++) {
+ char ch = styler[cPos];
+ if (ch != '<')
+ s[i++] = tolower(ch);
+ }
+ s[i] = '\0';
+ char chAttr = SCE_H_TAGUNKNOWN;
+ if (s[0] == '!' && s[1] == '-' && s[2] == '-') { //Comment
+ chAttr = SCE_H_COMMENT;
+ } else if (s[0] == '/') { // Closing tag
+ if (keywords.InList(s + 1))
+ chAttr = SCE_H_TAG;
+ } else {
+ if (keywords.InList(s)) {
+ chAttr = SCE_H_TAG;
+ if (0 == strcmp(s, "script"))
+ chAttr = SCE_H_SCRIPT;
+ }
+ }
+ styler.ColourTo(end, chAttr);
+ return chAttr;
+}
+
+static void classifyWordHTJS(unsigned int start, unsigned int end,
+ WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HJ_WORD;
+ if (wordIsNumber)
+ chAttr = SCE_HJ_NUMBER;
+ else {
+ if (keywords.InList(s))
+ chAttr = SCE_HJ_KEYWORD;
+ }
+ styler.ColourTo(end, chAttr);
+}
+
+static void classifyWordHTJSA(unsigned int start, unsigned int end,
+ WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HJA_WORD;
+ if (wordIsNumber)
+ chAttr = SCE_HJA_NUMBER;
+ else {
+ if (keywords.InList(s))
+ chAttr = SCE_HJA_KEYWORD;
+ }
+ styler.ColourTo(end, chAttr);
+}
+
+static int classifyWordHTVB(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = tolower(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HB_IDENTIFIER;
+ if (wordIsNumber)
+ chAttr = SCE_HB_NUMBER;
+ else {
+ if (keywords.InList(s)) {
+ chAttr = SCE_HB_WORD;
+ if (strcmp(s, "rem") == 0)
+ chAttr = SCE_HB_COMMENTLINE;
+ }
+ }
+ styler.ColourTo(end, chAttr);
+ if (chAttr == SCE_HB_COMMENTLINE)
+ return SCE_HB_COMMENTLINE;
+ else
+ return SCE_HB_DEFAULT;
+}
+
+static int classifyWordHTVBA(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = tolower(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HBA_IDENTIFIER;
+ if (wordIsNumber)
+ chAttr = SCE_HBA_NUMBER;
+ else {
+ if (keywords.InList(s)) {
+ chAttr = SCE_HBA_WORD;
+ if (strcmp(s, "rem") == 0)
+ chAttr = SCE_HBA_COMMENTLINE;
+ }
+ }
+ styler.ColourTo(end, chAttr);
+ if (chAttr == SCE_HBA_COMMENTLINE)
+ return SCE_HBA_COMMENTLINE;
+ else
+ return SCE_HBA_DEFAULT;
+}
+
+static void classifyWordHTPy(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]);
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HP_IDENTIFIER;
+ if (0 == strcmp(prevWord, "class"))
+ chAttr = SCE_HP_CLASSNAME;
+ else if (0 == strcmp(prevWord, "def"))
+ chAttr = SCE_HP_DEFNAME;
+ else if (wordIsNumber)
+ chAttr = SCE_HP_NUMBER;
+ else if (keywords.InList(s))
+ chAttr = SCE_HP_WORD;
+ styler.ColourTo(end, chAttr);
+ strcpy(prevWord, s);
+}
+
+static void classifyWordHTPyA(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]);
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_HPA_IDENTIFIER;
+ if (0 == strcmp(prevWord, "class"))
+ chAttr = SCE_HPA_CLASSNAME;
+ else if (0 == strcmp(prevWord, "def"))
+ chAttr = SCE_HPA_DEFNAME;
+ else if (wordIsNumber)
+ chAttr = SCE_HPA_NUMBER;
+ else if (keywords.InList(s))
+ chAttr = SCE_HPA_WORD;
+ styler.ColourTo(end, chAttr);
+ strcpy(prevWord, s);
+}
+
+inline bool ishtmlwordchar(char ch) {
+ return isalnum(ch) || ch == '.' || ch == '-' || ch == '_' || ch == ':' || ch == '!' || ch == '#';
+}
+
+static bool InTagState(int state) {
+ return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN ||
+ state == SCE_H_SCRIPT ||
+ state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN ||
+ state == SCE_H_NUMBER || state == SCE_H_OTHER ||
+ state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING;
+}
+
+static bool isLineEnd(char ch) {
+ return ch == '\r' || ch == '\n';
+}
+
+static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
+ StylingContext &styler) {
+
+ WordList &keywords=*keywordlists[0];
+ WordList &keywords2=*keywordlists[1];
+ WordList &keywords3=*keywordlists[2];
+ WordList &keywords4=*keywordlists[3];
+
+ // Lexer for HTML requires more lexical states (7 bits worth) than most lexers
+ styler.StartAt(startPos, 127);
+ bool lastTagWasScript = false;
+ char prevWord[200];
+ prevWord[0] = '\0';
+ int scriptLanguage = eScriptJS;
+ int state = initStyle;
+ // If inside a tag, it may be a script tage, so reread from the start to ensure any language tas are seen
+ if (InTagState(state)) {
+ while ((startPos > 1) && (InTagState(styler.StyleAt(startPos - 1)))) {
+ startPos--;
+ }
+ state = SCE_H_DEFAULT;
+ }
+ styler.StartAt(startPos, 127);
+
+ int lineState = eScriptVBS;
+ int lineCurrent = styler.GetLine(startPos);
+ if (lineCurrent > 0)
+ lineState = styler.GetLineState(lineCurrent);
+ int defaultScript = lineState &0xff;
+ int beforeASP = (lineState >> 8) &0xff;
+ int inASP = (lineState >> 16) &0xff;
+
+ char chPrev = ' ';
+ char chPrev2 = ' ';
+ styler.StartSegment(startPos);
+ int lengthDoc = startPos + length;
+ for (int i = startPos; i <= lengthDoc; i++) {
+ char ch = styler[i];
+ char chNext = styler.SafeGetCharAt(i + 1);
+ char chNext2 = styler.SafeGetCharAt(i + 2);
+
+ if (styler.IsLeadByte(ch)) {
+ chPrev2 = ' ';
+ chPrev = ' ';
+ i += 1;
+ continue;
+ }
+
+ if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
+ // New line -> record any line state onto /next/ line
+ lineCurrent++;
+ styler.SetLineState(lineCurrent,
+ defaultScript | (beforeASP << 8) | (inASP << 16));
+ }
+
+ // Handle ASP even within other constructs as it is a preprocessor
+ if ((ch == '<') && (chNext == '%')) {
+ beforeASP = state;
+ styler.ColourTo(i - 1, state);
+ if (chNext2 == '@') {
+ styler.ColourTo(i + 2, SCE_H_ASP);
+ state = SCE_H_ASPAT;
+ i+=2;
+ } else {
+ if (defaultScript == eScriptVBS)
+ state = SCE_HBA_START;
+ else if (defaultScript == eScriptPython)
+ state = SCE_HPA_START;
+ else
+ state = SCE_HJA_START;
+ if (chNext2 == '=') {
+ styler.ColourTo(i + 2, SCE_H_ASP);
+ i+=2;
+ } else {
+ styler.ColourTo(i + 1, SCE_H_ASP);
+ i++;
+ }
+ }
+ inASP = 1;
+ continue;
+ }
+ if (inASP && (ch == '%') && (chNext == '>')) {
+ if (state == SCE_H_ASPAT)
+ defaultScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i-1, defaultScript);
+ // Bounce out of any ASP mode
+ if (state == SCE_HJA_WORD) {
+ classifyWordHTJSA(styler.GetStartSegment(), i - 1, keywords2, styler);
+ } else if (state == SCE_HBA_WORD) {
+ classifyWordHTVBA(styler.GetStartSegment(), i - 1, keywords3, styler);
+ } else if (state == SCE_HPA_WORD) {
+ classifyWordHTPyA(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
+ } else {
+ styler.ColourTo(i - 1, state);
+ }
+ //if (state == SCE_H_ASPAT)
+ // styler.ColourTo(i+1, SCE_H_ASPAT);
+ //else
+ styler.ColourTo(i+1, SCE_H_ASP);
+ i++;
+ state = beforeASP;
+ beforeASP = SCE_H_DEFAULT;
+ inASP = 0;
+ continue;
+ }
+
+ if (state == SCE_H_DEFAULT) {
+ if (ch == '<') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ if (chNext == '?') {
+ styler.ColourTo(i + 1, SCE_H_XMLSTART);
+ i++;
+ ch = chNext;
+ }
+ } else if (ch == '&') {
+ styler.ColourTo(i - 1, SCE_H_DEFAULT);
+ state = SCE_H_ENTITY;
+ }
+ } else if (state == SCE_H_COMMENT) {
+ if ((ch == '>') && (chPrev == '-')) {
+ styler.ColourTo(i, state);
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_H_ENTITY) {
+ if (ch == ';') {
+ styler.ColourTo(i, state);
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_H_TAGUNKNOWN) {
+ if (!ishtmlwordchar(ch) && ch != '/' && ch != '-') {
+ int eClass = classifyTagHTML(styler.GetStartSegment(), i - 1, keywords, styler);
+ lastTagWasScript = eClass == SCE_H_SCRIPT;
+ if (lastTagWasScript) {
+ scriptLanguage = eScriptJS;
+ eClass = SCE_H_TAG;
+ }
+ if (ch == '>') {
+ styler.ColourTo(i, SCE_H_TAG);
+ if (lastTagWasScript) {
+ if (scriptLanguage == eScriptVBS)
+ state = SCE_HB_START;
+ else if (scriptLanguage == eScriptPython)
+ state = SCE_HP_START;
+ else
+ state = SCE_HJ_START;
+ } else {
+ state = SCE_H_DEFAULT;
+ }
+ } else {
+ if (eClass == SCE_H_COMMENT) {
+ state = SCE_H_COMMENT;
+ } else {
+ state = SCE_H_OTHER;
+ }
+ }
+ }
+ } else if (state == SCE_H_ATTRIBUTE) {
+ if (!ishtmlwordchar(ch) && ch != '/' && ch != '-') {
+ if (lastTagWasScript)
+ scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i-1, scriptLanguage);
+ classifyAttribHTML(styler.GetStartSegment(), i - 1, keywords, styler);
+ if (ch == '>') {
+ styler.ColourTo(i, SCE_H_TAG);
+ if (lastTagWasScript) {
+ if (scriptLanguage == eScriptVBS)
+ state = SCE_HB_START;
+ else if (scriptLanguage == eScriptPython)
+ state = SCE_HP_START;
+ else
+ state = SCE_HJ_START;
+ } else {
+ state = SCE_H_DEFAULT;
+ }
+ } else {
+ state = SCE_H_OTHER;
+ }
+ }
+ } else if (state == SCE_H_ASP) {
+ if ((ch == '>') && (chPrev == '%')) {
+ styler.ColourTo(i, state);
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_H_ASPAT) {
+ if ((ch == '>') && (chPrev == '%')) {
+ styler.ColourTo(i, state);
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_H_OTHER) {
+ if (ch == '>') {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_H_TAG);
+ if (lastTagWasScript) {
+ if (scriptLanguage == eScriptVBS)
+ state = SCE_HB_START;
+ else if (scriptLanguage == eScriptPython)
+ state = SCE_HP_START;
+ else
+ state = SCE_HJ_START;
+ } else {
+ state = SCE_H_DEFAULT;
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_DOUBLESTRING;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_SINGLESTRING;
+ } else if (ch == '/' && chNext == '>') {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_TAGEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ } else if (ch == '?' && chNext == '>') {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_XMLEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ } else if (ishtmlwordchar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_ATTRIBUTE;
+ }
+ } else if (state == SCE_H_DOUBLESTRING) {
+ if (ch == '\"') {
+ if (lastTagWasScript)
+ scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
+ styler.ColourTo(i, SCE_H_DOUBLESTRING);
+ state = SCE_H_OTHER;
+ }
+ } else if (state == SCE_H_SINGLESTRING) {
+ if (ch == '\'') {
+ if (lastTagWasScript)
+ scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
+ styler.ColourTo(i, SCE_H_SINGLESTRING);
+ state = SCE_H_OTHER;
+ }
+ } else if (state == SCE_HJ_DEFAULT || state == SCE_HJ_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_WORD;
+ } else if (ch == '/' && chNext == '*') {
+ styler.ColourTo(i - 1, state);
+ if (chNext2 == '*')
+ state = SCE_HJ_COMMENTDOC;
+ else
+ state = SCE_HJ_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_DOUBLESTRING;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_SINGLESTRING;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HJ_SYMBOLS);
+ state = SCE_HJ_DEFAULT;
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HJ_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HJ_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler);
+ //styler.ColourTo(i - 1, eHTJSKeyword);
+ state = SCE_HJ_DEFAULT;
+ if (ch == '/' && chNext == '*') {
+ if (chNext2 == '*')
+ state = SCE_HJ_COMMENTDOC;
+ else
+ state = SCE_HJ_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_HJ_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_HJ_DOUBLESTRING;
+ } else if (ch == '\'') {
+ state = SCE_HJ_SINGLESTRING;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HJ_SYMBOLS);
+ state = SCE_HJ_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HJ_COMMENT) {
+ if (ch == '/' && chPrev == '*') {
+ state = SCE_HJ_DEFAULT;
+ styler.ColourTo(i, SCE_HJ_COMMENT);
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_TAGEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_HJ_COMMENTDOC) {
+ if (ch == '/' && chPrev == '*') {
+ state = SCE_HJ_DEFAULT;
+ styler.ColourTo(i, SCE_HJ_COMMENTDOC);
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_TAGEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_HJ_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, SCE_HJ_COMMENTLINE);
+ state = SCE_HJ_DEFAULT;
+ } else if ((ch == '<') && (chNext == '/')) {
+ // Common to hide end script tag in comment
+ styler.ColourTo(i - 1, SCE_HJ_COMMENTLINE);
+ state = SCE_H_TAGUNKNOWN;
+ }
+ } else if (state == SCE_HJ_DOUBLESTRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, SCE_HJ_DOUBLESTRING);
+ state = SCE_HJ_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (isLineEnd(ch)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_HJ_STRINGEOL;
+ }
+ } else if (state == SCE_HJ_SINGLESTRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, SCE_HJ_SINGLESTRING);
+ state = SCE_HJ_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (isLineEnd(ch)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_HJ_STRINGEOL;
+ }
+ } else if (state == SCE_HJ_STRINGEOL) {
+ if (!isLineEnd(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJ_DEFAULT;
+ } else if (!isLineEnd(chNext)) {
+ styler.ColourTo(i, state);
+ state = SCE_HJ_DEFAULT;
+ }
+ } else if (state == SCE_HJA_DEFAULT || state == SCE_HJA_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_WORD;
+ } else if (ch == '/' && chNext == '*') {
+ styler.ColourTo(i - 1, state);
+ if (chNext2 == '*')
+ state = SCE_HJA_COMMENTDOC;
+ else
+ state = SCE_HJA_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_DOUBLESTRING;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_SINGLESTRING;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HJA_SYMBOLS);
+ state = SCE_HJA_DEFAULT;
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HJA_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HJA_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordHTJSA(styler.GetStartSegment(), i - 1, keywords2, styler);
+ //styler.ColourTo(i - 1, eHTJSKeyword);
+ state = SCE_HJA_DEFAULT;
+ if (ch == '/' && chNext == '*') {
+ if (chNext2 == '*')
+ state = SCE_HJA_COMMENTDOC;
+ else
+ state = SCE_HJA_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_HJA_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_HJA_DOUBLESTRING;
+ } else if (ch == '\'') {
+ state = SCE_HJA_SINGLESTRING;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HJA_SYMBOLS);
+ state = SCE_HJA_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HJA_COMMENT) {
+ if (ch == '/' && chPrev == '*') {
+ state = SCE_HJA_DEFAULT;
+ styler.ColourTo(i, SCE_HJA_COMMENT);
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_TAGEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_HJA_COMMENTDOC) {
+ if (ch == '/' && chPrev == '*') {
+ state = SCE_HJA_DEFAULT;
+ styler.ColourTo(i, SCE_HJA_COMMENTDOC);
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i + 1, SCE_H_TAGEND);
+ i++;
+ ch = chNext;
+ state = SCE_H_DEFAULT;
+ }
+ } else if (state == SCE_HJA_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, SCE_HJA_COMMENTLINE);
+ state = SCE_HJA_DEFAULT;
+ } else if ((ch == '<') && (chNext == '/')) {
+ // Common to hide end script tag in comment
+ styler.ColourTo(i - 1, SCE_HJA_COMMENTLINE);
+ state = SCE_H_TAGUNKNOWN;
+ }
+ } else if (state == SCE_HJA_DOUBLESTRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, SCE_HJA_DOUBLESTRING);
+ state = SCE_HJA_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (isLineEnd(ch)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_HJA_STRINGEOL;
+ }
+ } else if (state == SCE_HJA_SINGLESTRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, SCE_HJA_SINGLESTRING);
+ state = SCE_HJA_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (isLineEnd(ch)) {
+ styler.ColourTo(i-1, state);
+ state = SCE_HJA_STRINGEOL;
+ }
+ } else if (state == SCE_HJA_STRINGEOL) {
+ if (!isLineEnd(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HJA_DEFAULT;
+ } else if (!isLineEnd(chNext)) {
+ styler.ColourTo(i, state);
+ state = SCE_HJA_DEFAULT;
+ }
+ } else if (state == SCE_HB_DEFAULT || state == SCE_HB_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_WORD;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_STRING;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HB_DEFAULT);
+ state = SCE_HB_DEFAULT;
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HB_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HB_WORD) {
+ if (!iswordchar(ch)) {
+ state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler);
+ if (state == SCE_HB_DEFAULT) {
+ if (ch == '\"') {
+ state = SCE_HB_STRING;
+ } else if (ch == '\'') {
+ state = SCE_HB_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HB_DEFAULT);
+ state = SCE_HB_DEFAULT;
+ }
+ }
+ }
+ } else if (state == SCE_HB_STRING) {
+ if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HB_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i-1, state);
+ state = SCE_HB_STRINGEOL;
+ }
+ } else if (state == SCE_HB_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_DEFAULT;
+ } else if ((ch == '<') && (chNext == '/')) {
+ // Common to hide end script tag in comment
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ }
+ } else if (state == SCE_HB_STRINGEOL) {
+ if (!isLineEnd(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HB_DEFAULT;
+ } else if (!isLineEnd(chNext)) {
+ styler.ColourTo(i, state);
+ state = SCE_HB_DEFAULT;
+ }
+ } else if (state == SCE_HBA_DEFAULT || state == SCE_HBA_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_WORD;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_STRING;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HBA_DEFAULT);
+ state = SCE_HBA_DEFAULT;
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HBA_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HBA_WORD) {
+ if (!iswordchar(ch)) {
+ state = classifyWordHTVBA(styler.GetStartSegment(), i - 1, keywords3, styler);
+ if (state == SCE_HBA_DEFAULT) {
+ if (ch == '\"') {
+ state = SCE_HBA_STRING;
+ } else if (ch == '\'') {
+ state = SCE_HBA_COMMENTLINE;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HBA_DEFAULT);
+ state = SCE_HBA_DEFAULT;
+ }
+ }
+ }
+ } else if (state == SCE_HBA_STRING) {
+ if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HBA_DEFAULT;
+ i++;
+ ch = chNext;
+ } else if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i-1, state);
+ state = SCE_HBA_STRINGEOL;
+ }
+ } else if (state == SCE_HBA_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_DEFAULT;
+ } else if ((ch == '<') && (chNext == '/')) {
+ // Common to hide end script tag in comment
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ }
+ } else if (state == SCE_HBA_STRINGEOL) {
+ if (!isLineEnd(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HBA_DEFAULT;
+ } else if (!isLineEnd(chNext)) {
+ styler.ColourTo(i, state);
+ state = SCE_HBA_DEFAULT;
+ }
+ } else if (state == SCE_HP_DEFAULT || state == SCE_HP_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HP_WORD;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HP_COMMENTLINE;
+ } else if (ch == '#') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HP_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_HP_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HP_STRING;
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_HP_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HP_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HP_OPERATOR);
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HP_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HP_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HP_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
+ state = SCE_HP_DEFAULT;
+ if (ch == '#') {
+ state = SCE_HP_COMMENTLINE;
+ } else if (ch == '\"') {
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_HP_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HP_STRING;
+ }
+ } else if (ch == '\'') {
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_HP_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HP_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HP_OPERATOR);
+ }
+ }
+ } else if (state == SCE_HP_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HP_DEFAULT;
+ }
+ } else if (state == SCE_HP_STRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HP_DEFAULT;
+ }
+ } else if (state == SCE_HP_CHARACTER) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_HP_DEFAULT;
+ }
+ } else if (state == SCE_HP_TRIPLE) {
+ if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_HP_DEFAULT;
+ }
+ } else if (state == SCE_HP_TRIPLEDOUBLE) {
+ if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HP_DEFAULT;
+ }
+ } else if (state == SCE_HPA_DEFAULT || state == SCE_HPA_START) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HPA_WORD;
+ } else if ((ch == '<') && (chNext == '/')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_H_TAGUNKNOWN;
+ } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
+ styler.SafeGetCharAt(i + 3) == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HPA_COMMENTLINE;
+ } else if (ch == '#') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HPA_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_HPA_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HPA_STRING;
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_HPA_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HPA_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_HPA_OPERATOR);
+ } else if ((ch == ' ') || (ch == '\t')) {
+ if (state == SCE_HPA_START) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ }
+ } else if (state == SCE_HPA_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordHTPyA(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord);
+ state = SCE_HPA_DEFAULT;
+ if (ch == '#') {
+ state = SCE_HPA_COMMENTLINE;
+ } else if (ch == '\"') {
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_HPA_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HPA_STRING;
+ }
+ } else if (ch == '\'') {
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_HPA_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_HPA_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HPA_OPERATOR);
+ }
+ }
+ } else if (state == SCE_HPA_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ } else if (state == SCE_HPA_STRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ } else if (state == SCE_HPA_CHARACTER) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ } else if (state == SCE_HPA_TRIPLE) {
+ if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ } else if (state == SCE_HPA_TRIPLEDOUBLE) {
+ if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_HPA_DEFAULT;
+ }
+ }
+ if (state == SCE_HB_DEFAULT) { // One of the above succeeded
+ if (ch == '\"') {
+ state = SCE_HB_STRING;
+ } else if (ch == '\'') {
+ state = SCE_HB_COMMENTLINE;
+ } else if (iswordstart(ch)) {
+ state = SCE_HB_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HB_DEFAULT);
+ }
+ }
+ if (state == SCE_HBA_DEFAULT) { // One of the above succeeded
+ if (ch == '\"') {
+ state = SCE_HBA_STRING;
+ } else if (ch == '\'') {
+ state = SCE_HBA_COMMENTLINE;
+ } else if (iswordstart(ch)) {
+ state = SCE_HBA_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HBA_DEFAULT);
+ }
+ }
+ if (state == SCE_HJ_DEFAULT) { // One of the above succeeded
+ if (ch == '/' && chNext == '*') {
+ if (styler.SafeGetCharAt(i + 2) == '*')
+ state = SCE_HJ_COMMENTDOC;
+ else
+ state = SCE_HJ_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_HJ_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_HJ_DOUBLESTRING;
+ } else if (ch == '\'') {
+ state = SCE_HJ_SINGLESTRING;
+ } else if (iswordstart(ch)) {
+ state = SCE_HJ_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HJ_SYMBOLS);
+ }
+ }
+ if (state == SCE_HJA_DEFAULT) { // One of the above succeeded
+ if (ch == '/' && chNext == '*') {
+ if (styler.SafeGetCharAt(i + 2) == '*')
+ state = SCE_HJA_COMMENTDOC;
+ else
+ state = SCE_HJA_COMMENT;
+ } else if (ch == '/' && chNext == '/') {
+ state = SCE_HJA_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_HJA_DOUBLESTRING;
+ } else if (ch == '\'') {
+ state = SCE_HJA_SINGLESTRING;
+ } else if (iswordstart(ch)) {
+ state = SCE_HJA_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_HJA_SYMBOLS);
+ }
+ }
+ chPrev2 = chPrev;
+ chPrev = ch;
+ }
+ styler.ColourTo(lengthDoc - 1, state);
+}
+
+static LexerModule lmHTML(SCLEX_HTML, ColouriseHyperTextDoc);
+static LexerModule lmXML(SCLEX_XML, ColouriseHyperTextDoc);
diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx
new file mode 100644
index 000000000..d2a0d563b
--- /dev/null
+++ b/src/LexOthers.cxx
@@ -0,0 +1,200 @@
+// SciTE - Scintilla based Text Editor
+// LexOthers.cxx - lexers for properties files, batch files, make files and error lists
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+static void ColouriseBatchLine(char *lineBuffer, int endLine, StylingContext &styler) {
+ if (0 == strncmp(lineBuffer, "REM", 3)) {
+ styler.ColourTo(endLine, 1);
+ } else if (0 == strncmp(lineBuffer, "rem", 3)) {
+ styler.ColourTo(endLine, 1);
+ } else if (0 == strncmp(lineBuffer, "SET", 3)) {
+ styler.ColourTo(endLine, 2);
+ } else if (0 == strncmp(lineBuffer, "set", 3)) {
+ styler.ColourTo(endLine, 2);
+ } else if (lineBuffer[0] == ':') {
+ styler.ColourTo(endLine, 3);
+ } else {
+ styler.ColourTo(endLine, 0);
+ }
+}
+
+static void ColouriseBatchDoc(unsigned int startPos, int length, int, WordList *[], StylingContext &styler) {
+ char lineBuffer[1024];
+ styler.StartAt(startPos);
+ styler.StartSegment(startPos);
+ unsigned int linePos = 0;
+ for (unsigned int i = startPos; i < startPos + length; i++) {
+ lineBuffer[linePos++] = styler[i];
+ if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
+ ColouriseBatchLine(lineBuffer, i, styler);
+ linePos = 0;
+ }
+ }
+ if (linePos > 0)
+ ColouriseBatchLine(lineBuffer, startPos + length, styler);
+}
+
+static void ColourisePropsLine(char *lineBuffer, int lengthLine, int startLine, int endPos, StylingContext &styler) {
+ int i = 0;
+ while (isspace(lineBuffer[i]) && (i < lengthLine)) // Skip initial spaces
+ i++;
+ if (lineBuffer[i] == '#' || lineBuffer[i] == '!' || lineBuffer[i] == ';') {
+ styler.ColourTo(endPos, 1);
+ } else if (lineBuffer[i] == '[') {
+ styler.ColourTo(endPos, 2);
+ } else if (lineBuffer[i] == '@') {
+ styler.ColourTo(startLine+i, 4);
+ if (lineBuffer[++i] == '=')
+ styler.ColourTo(startLine+i, 3);
+ styler.ColourTo(endPos, 0);
+ } else {
+ while (lineBuffer[i] != '=' && (i < lengthLine)) // Search the '=' character
+ i++;
+ if (lineBuffer[i] == '=') {
+ styler.ColourTo(startLine+i-1, 0);
+ styler.ColourTo(startLine+i, 3);
+ styler.ColourTo(endPos, 0);
+ } else {
+ styler.ColourTo(endPos, 0);
+ }
+ }
+}
+
+static void ColourisePropsDoc(unsigned int startPos, int length, int, WordList *[], StylingContext &styler) {
+ char lineBuffer[1024];
+ styler.StartAt(startPos);
+ styler.StartSegment(startPos);
+ unsigned int linePos = 0;
+ int startLine = startPos;
+ for (unsigned int i = startPos; i <= startPos + length; i++) {
+ lineBuffer[linePos++] = styler[i];
+ if ((styler[i] == '\r' && styler.SafeGetCharAt(i+1) != '\n') ||
+ styler[i] == '\n' ||
+ (linePos >= sizeof(lineBuffer) - 1)) {
+ lineBuffer[linePos] = '\0';
+ ColourisePropsLine(lineBuffer, linePos, startLine, i, styler);
+ linePos = 0;
+ startLine = i+1;
+ }
+ }
+ if (linePos > 0)
+ ColourisePropsLine(lineBuffer, linePos, startLine, startPos + length, styler);
+}
+
+static void ColouriseMakeLine(char *lineBuffer, int lengthLine, int endPos, StylingContext &styler) {
+ int i = 0;
+ while (isspace(lineBuffer[i]) && (i < lengthLine))
+ i++;
+ if (lineBuffer[i] == '#' || lineBuffer[i] == '!') {
+ styler.ColourTo(endPos, 1);
+ } else {
+ styler.ColourTo(endPos, 0);
+ }
+}
+
+static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[], StylingContext &styler) {
+ char lineBuffer[1024];
+ styler.StartAt(startPos);
+ styler.StartSegment(startPos);
+ unsigned int linePos = 0;
+ for (unsigned int i = startPos; i <= startPos + length; i++) {
+ lineBuffer[linePos++] = styler[i];
+ if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
+ ColouriseMakeLine(lineBuffer, linePos, i, styler);
+ linePos = 0;
+ }
+ }
+ if (linePos > 0)
+ ColouriseMakeLine(lineBuffer, linePos, startPos + length, styler);
+}
+
+static void ColouriseErrorListLine(char *lineBuffer, int lengthLine, int endPos, StylingContext &styler) {
+ if (lineBuffer[0] == '>') {
+ // Command or return status
+ styler.ColourTo(endPos, 4);
+ } else if (strstr(lineBuffer, "File \"") && strstr(lineBuffer, ", line ")) {
+ styler.ColourTo(endPos, 1);
+ } else if (0 == strncmp(lineBuffer, "Error ", strlen("Error "))) {
+ // Borland error message
+ styler.ColourTo(endPos, 5);
+ } else if (0 == strncmp(lineBuffer, "Warning ", strlen("Warning "))) {
+ // Borland warning message
+ styler.ColourTo(endPos, 5);
+ } else {
+ // Look for <filename>:<line>:message
+ // Look for <filename>(line)message
+ // Look for <filename>(line,pos)message
+ int state = 0;
+ for (int i = 0; i < lengthLine; i++) {
+ if (state == 0 && lineBuffer[i] == ':' && isdigit(lineBuffer[i + 1])) {
+ state = 1;
+ } else if (state == 0 && lineBuffer[i] == '(') {
+ state = 10;
+ } else if (state == 1 && isdigit(lineBuffer[i])) {
+ state = 2;
+ } else if (state == 2 && lineBuffer[i] == ':') {
+ state = 3;
+ break;
+ } else if (state == 2 && !isdigit(lineBuffer[i])) {
+ state = 99;
+ } else if (state == 10 && isdigit(lineBuffer[i])) {
+ state = 11;
+ } else if (state == 11 && lineBuffer[i] == ',') {
+ state = 14;
+ } else if (state == 11 && lineBuffer[i] == ')') {
+ state = 12;
+ break;
+ } else if (state == 12 && lineBuffer[i] == ':') {
+ state = 13;
+ } else if (state == 14 && lineBuffer[i] == ')') {
+ state = 15;
+ break;
+ } else if (((state == 11) || (state == 14)) && !((lineBuffer[i] == ' ') || isdigit(lineBuffer[i]))) {
+ state = 99;
+ }
+ }
+ if (state == 3) {
+ styler.ColourTo(endPos, 2);
+ } else if ((state == 14) || (state == 15)) {
+ styler.ColourTo(endPos, 3);
+ } else {
+ styler.ColourTo(endPos, 0);
+ }
+ }
+}
+
+static void ColouriseErrorListDoc(unsigned int startPos, int length, int, WordList *[], StylingContext &styler) {
+ char lineBuffer[1024];
+ styler.StartAt(startPos);
+ styler.StartSegment(startPos);
+ unsigned int linePos = 0;
+ for (unsigned int i = startPos; i <= startPos + length; i++) {
+ lineBuffer[linePos++] = styler[i];
+ if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
+ ColouriseErrorListLine(lineBuffer, linePos, i, styler);
+ linePos = 0;
+ }
+ }
+ if (linePos > 0)
+ ColouriseErrorListLine(lineBuffer, linePos, startPos + length, styler);
+}
+
+static LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc);
+static LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);
+static LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc);
+static LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc);
diff --git a/src/LexPerl.cxx b/src/LexPerl.cxx
new file mode 100644
index 000000000..f9170b9c3
--- /dev/null
+++ b/src/LexPerl.cxx
@@ -0,0 +1,488 @@
+// SciTE - Scintilla based Text Editor
+// LexPerl.cxx - lexer for subset of Perl
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+inline bool isPerlOperator(char ch) {
+ if (isalnum(ch))
+ return false;
+ // '.' left out as it is used to make up numbers
+ if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || ch == '\\' ||
+ ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
+ ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
+ ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
+ ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
+ ch == '?' || ch == '!' || ch == '.' || ch == '~')
+ return true;
+ return false;
+}
+
+static int classifyWordPerl(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_PL_IDENTIFIER;
+ if (wordIsNumber)
+ chAttr = SCE_PL_NUMBER;
+ else {
+ if (keywords.InList(s))
+ chAttr = SCE_PL_WORD;
+ }
+ styler.ColourTo(end, chAttr);
+ return chAttr;
+}
+
+static bool isEndVar(char ch) {
+ return !isalnum(ch) && ch != '#' && ch != '$' &&
+ ch != '_' && ch != '\'';
+}
+
+static bool isMatch(StylingContext &styler, int lengthDoc, int pos, const char *val) {
+ if ((pos + static_cast<int>(strlen(val))) >= lengthDoc) {
+ return false;
+ }
+ while (*val) {
+ if (*val != styler[pos++]) {
+ return false;
+ }
+ val++;
+ }
+ return true;
+}
+
+static bool isOKQuote(char ch) {
+ if (isalnum(ch))
+ return false;
+ if (isspace(ch))
+ return false;
+ if (iscntrl(ch))
+ return false;
+ return true;
+}
+
+static char opposite(char ch) {
+ if (ch == '(')
+ return ')';
+ if (ch == '[')
+ return ']';
+ if (ch == '{')
+ return '}';
+ if (ch == '<')
+ return '>';
+ return ch;
+}
+
+static void ColourisePerlDoc(unsigned int startPos, int length, int initStyle,
+ WordList *keywordlists[], StylingContext &styler) {
+
+ // Lexer for perl often has to backtrack to start of current style to determine
+ // which characters are being used as quotes, how deeply nested is the
+ // start position and what the termination string is for here documents
+
+ WordList &keywords = *keywordlists[0];
+
+ char sooked[100];
+ int quotes = 0;
+ char quoteDown = 'd';
+ char quoteUp = 'd';
+ int quoteRep = 1;
+ int sookedpos = 0;
+ bool preferRE = true;
+ sooked[sookedpos] = '\0';
+ int state = initStyle;
+ int lengthDoc = startPos + length;
+ // If in a long distance lexical state, seek to the beginning to find quote characters
+ if (state == SCE_PL_HERE || state == SCE_PL_REGEX ||
+ state == SCE_PL_REGSUBST || state == SCE_PL_LONGQUOTE) {
+ while ((startPos > 1) && (styler.StyleAt(startPos - 1) == state)) {
+ startPos--;
+ }
+ state = SCE_PL_DEFAULT;
+ }
+ styler.StartAt(startPos);
+ char chPrev = ' ';
+ char chNext = styler[startPos];
+ styler.StartSegment(startPos);
+ for (int i = startPos; i <= lengthDoc; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ char chNext2 = styler.SafeGetCharAt(i + 2);
+
+ if (styler.IsLeadByte(ch)) {
+ chNext = styler.SafeGetCharAt(i + 2);
+ chPrev = ' ';
+ i += 1;
+ continue;
+ }
+
+ if (state == SCE_PL_DEFAULT) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ if (ch == 's' && !isalnum(chNext)) {
+ state = SCE_PL_REGSUBST;
+ quotes = 0;
+ quoteUp = '\0';
+ quoteDown = '\0';
+ quoteRep = 2;
+ } else if (ch == 'm' && !isalnum(chNext)) {
+ state = SCE_PL_REGEX;
+ quotes = 0;
+ quoteUp = '\0';
+ quoteDown = '\0';
+ quoteRep = 1;
+ } else if (ch == 't' && chNext == 'r' && !isalnum(chNext2)) {
+ state = SCE_PL_REGSUBST;
+ quotes = 0;
+ quoteUp = '\0';
+ quoteDown = '\0';
+ quoteRep = 2;
+ i++;
+ chNext = chNext2;
+ } else if (ch == 'q' && (chNext == 'q' || chNext == 'r' || chNext == 'w' || chNext == 'x') && !isalnum(chNext2)) {
+ state = SCE_PL_LONGQUOTE;
+ i++;
+ chNext = chNext2;
+ quotes = 0;
+ quoteUp = '\0';
+ quoteDown = '\0';
+ quoteRep = 1;
+ } else {
+ state = SCE_PL_WORD;
+ preferRE = false;
+ }
+ } else if (ch == '#') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_STRING;
+ } else if (ch == '\'') {
+ if (chPrev == '&') {
+ // Archaic call
+ styler.ColourTo(i, state);
+ } else {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_CHARACTER;
+ }
+ } else if (ch == '`') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_BACKTICKS;
+ } else if (ch == '$') {
+ preferRE = false;
+ styler.ColourTo(i - 1, state);
+ if (isalnum(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
+ state = SCE_PL_SCALAR;
+ } else if (chNext != '{' && chNext != '[') {
+ styler.ColourTo(i, SCE_PL_SCALAR);
+ i++;
+ ch = ' ';
+ chNext = ' ';
+ } else {
+ styler.ColourTo(i, SCE_PL_SCALAR);
+ }
+ } else if (ch == '@') {
+ preferRE = false;
+ styler.ColourTo(i - 1, state);
+ if (isalpha(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
+ state = SCE_PL_ARRAY;
+ } else if (chNext != '{' && chNext != '[') {
+ styler.ColourTo(i, SCE_PL_ARRAY);
+ i++;
+ ch = ' ';
+ } else {
+ styler.ColourTo(i, SCE_PL_ARRAY);
+ }
+ } else if (ch == '%') {
+ preferRE = false;
+ styler.ColourTo(i - 1, state);
+ if (isalpha(chNext) || chNext == '#' || chNext == '$' || chNext == '_') {
+ state = SCE_PL_HASH;
+ } else if (chNext != '{' && chNext != '[') {
+ styler.ColourTo(i, SCE_PL_HASH);
+ i++;
+ ch = ' ';
+ } else {
+ styler.ColourTo(i, SCE_PL_HASH);
+ }
+ } else if (ch == '*') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_SYMBOLTABLE;
+ } else if (ch == '/' && preferRE) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_REGEX;
+ quoteUp = '/';
+ quoteDown = '/';
+ quotes = 1;
+ quoteRep = 1;
+ } else if (ch == '<' && chNext == '<') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_HERE;
+ i++;
+ ch = chNext;
+ chNext = chNext2;
+ quotes = 0;
+ sookedpos = 0;
+ sooked[sookedpos] = '\0';
+ } else if (ch == '=' && isalpha(chNext)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_POD;
+ quotes = 0;
+ sookedpos = 0;
+ sooked[sookedpos] = '\0';
+ } else if (isPerlOperator(ch)) {
+ if (ch == ')' || ch == ']')
+ preferRE = false;
+ else
+ preferRE = true;
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_PL_OPERATOR);
+ }
+ } else if (state == SCE_PL_WORD) {
+ if (!iswordchar(ch) && ch != '\'') { // Archaic Perl has quotes inside names
+ if (isMatch(styler, lengthDoc, styler.GetStartSegment(), "__DATA__")) {
+ styler.ColourTo(i, SCE_PL_DATASECTION);
+ state = SCE_PL_DATASECTION;
+ } else if (isMatch(styler, lengthDoc, styler.GetStartSegment(), "__END__")) {
+ styler.ColourTo(i, SCE_PL_DATASECTION);
+ state = SCE_PL_DATASECTION;
+ } else {
+ if (classifyWordPerl(styler.GetStartSegment(), i - 1, keywords, styler) == SCE_PL_WORD)
+ preferRE = true;
+ state = SCE_PL_DEFAULT;
+ if (ch == '#') {
+ state = SCE_PL_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_PL_STRING;
+ } else if (ch == '\'') {
+ state = SCE_PL_CHARACTER;
+ } else if (ch == '<' && chNext == '<') {
+ state = SCE_PL_HERE;
+ quotes = 0;
+ sookedpos = 0;
+ sooked[sookedpos] = '\0';
+ } else if (isPerlOperator(ch)) {
+ if (ch == ')' || ch == ']')
+ preferRE = false;
+ else
+ preferRE = true;
+ styler.ColourTo(i, SCE_PL_OPERATOR);
+ state = SCE_PL_DEFAULT;
+ }
+ }
+ }
+ } else {
+ if (state == SCE_PL_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_HERE) {
+ if (isalnum(ch) && quotes < 2) {
+ sooked[sookedpos++] = ch;
+ sooked[sookedpos] = '\0';
+ if (quotes == 0)
+ quotes = 1;
+ } else {
+ quotes++;
+ }
+
+ if (quotes > 1 && isMatch(styler, lengthDoc, i, sooked)) {
+ styler.ColourTo(i + sookedpos - 1, SCE_PL_HERE);
+ state = SCE_PL_DEFAULT;
+ i += sookedpos;
+ chNext = ' ';
+ }
+ } else if (state == SCE_PL_STRING) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (state == SCE_PL_CHARACTER) {
+ if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (state == SCE_PL_BACKTICKS) {
+ if (ch == '`') {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (state == SCE_PL_POD) {
+ if (ch == '=') {
+ if (isMatch(styler, lengthDoc, i, "=cut")) {
+ styler.ColourTo(i - 1 + 4, state);
+ i += 4;
+ state = SCE_PL_DEFAULT;
+ chNext = ' ';
+ ch = ' ';
+ }
+ }
+ } else if (state == SCE_PL_SCALAR) {
+ if (isEndVar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_ARRAY) {
+ if (isEndVar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_HASH) {
+ if (isEndVar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_SYMBOLTABLE) {
+ if (isEndVar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_REF) {
+ if (isEndVar(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_PL_DEFAULT;
+ }
+ } else if (state == SCE_PL_REGEX) {
+ if (!quoteUp && !isspace(ch)) {
+ quoteUp = ch;
+ quoteDown = opposite(ch);
+ quotes++;
+ } else {
+ if (ch == quoteDown && chPrev != '\\') {
+ quotes--;
+ if (quotes == 0) {
+ quoteRep--;
+ if (quoteUp == quoteDown) {
+ quotes++;
+ }
+ }
+ if (!isalpha(chNext)) {
+ if (quoteRep <= 0) {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ ch = ' ';
+ }
+ }
+ } else if (ch == quoteUp && chPrev != '\\') {
+ quotes++;
+ } else if (!isalpha(chNext)) {
+ if (quoteRep <= 0) {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ ch = ' ';
+ }
+ }
+ }
+ } else if (state == SCE_PL_REGSUBST) {
+ if (!quoteUp && !isspace(ch)) {
+ quoteUp = ch;
+ quoteDown = opposite(ch);
+ quotes++;
+ } else {
+ if (ch == quoteDown && chPrev != '\\') {
+ quotes--;
+ if (quotes == 0) {
+ quoteRep--;
+ }
+ if (!isalpha(chNext)) {
+ if (quoteRep <= 0) {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ ch = ' ';
+ }
+ }
+ if (quoteUp == quoteDown) {
+ quotes++;
+ }
+ } else if (ch == quoteUp && chPrev != '\\') {
+ quotes++;
+ } else if (!isalpha(chNext)) {
+ if (quoteRep <= 0) {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ ch = ' ';
+ }
+ }
+ }
+ } else if (state == SCE_PL_LONGQUOTE) {
+ if (!quoteDown && !isspace(ch)) {
+ quoteUp = ch;
+ quoteDown = opposite(quoteUp);
+ quotes++;
+ } else if (ch == quoteDown) {
+ quotes--;
+ if (quotes == 0) {
+ quoteRep--;
+ if (quoteRep <= 0) {
+ styler.ColourTo(i, state);
+ state = SCE_PL_DEFAULT;
+ ch = ' ';
+ }
+ if (quoteUp == quoteDown) {
+ quotes++;
+ }
+ }
+ } else if (ch == quoteUp) {
+ quotes++;
+ }
+ }
+
+ if (state == SCE_PL_DEFAULT) { // One of the above succeeded
+ if (ch == '#') {
+ state = SCE_PL_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_PL_STRING;
+ } else if (ch == '\'') {
+ state = SCE_PL_CHARACTER;
+ } else if (iswordstart(ch)) {
+ state = SCE_PL_WORD;
+ preferRE = false;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_PL_OPERATOR);
+ }
+ }
+ }
+ chPrev = ch;
+ }
+ styler.ColourTo(lengthDoc, state);
+}
+
+static LexerModule lmPerl(SCLEX_PERL, ColourisePerlDoc);
diff --git a/src/LexPython.cxx b/src/LexPython.cxx
new file mode 100644
index 000000000..acce39a4a
--- /dev/null
+++ b/src/LexPython.cxx
@@ -0,0 +1,254 @@
+// SciTE - Scintilla based Text Editor
+// LexPython.cxx - lexer for Python
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+static void classifyWordPy(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler, char *prevWord) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]);
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_P_IDENTIFIER;
+ if (0 == strcmp(prevWord, "class"))
+ chAttr = SCE_P_CLASSNAME;
+ else if (0 == strcmp(prevWord, "def"))
+ chAttr = SCE_P_DEFNAME;
+ else if (wordIsNumber)
+ chAttr = SCE_P_NUMBER;
+ else if (keywords.InList(s))
+ chAttr = SCE_P_WORD;
+ styler.ColourTo(end, chAttr);
+ strcpy(prevWord, s);
+}
+
+static bool IsPyComment(StylingContext &styler, int pos, int len) {
+ return len>0 && styler[pos]=='#';
+}
+
+static void ColourisePyDoc(unsigned int startPos, int length, int initStyle,
+ WordList *keywordlists[], StylingContext &styler) {
+
+ // Python uses a different mask because bad indentation is marked by oring with 32
+ styler.StartAt(startPos, 127);
+
+ WordList &keywords = *keywordlists[0];
+
+ //Platform::DebugPrintf("Python coloured\n");
+ bool fold = styler.GetPropSet().GetInt("fold");
+ int whingeLevel = styler.GetPropSet().GetInt("tab.timmy.whinge.level");
+ char prevWord[200];
+ prevWord[0] = '\0';
+ if (length == 0)
+ return ;
+ int lineCurrent = styler.GetLine(startPos);
+ int spaceFlags = 0;
+ // TODO: Need to check previous line for indentation for both folding and bad indentation
+ int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment);
+
+ int state = initStyle & 31;
+ char chPrev = ' ';
+ char chPrev2 = ' ';
+ char chNext = styler[startPos];
+ char chNext2 = styler[startPos];
+ styler.StartSegment(startPos);
+ int lengthDoc = startPos + length;
+ bool atStartLine = true;
+ for (int i = startPos; i <= lengthDoc; i++) {
+
+ if (atStartLine) {
+ if (whingeLevel == 1) {
+ styler.SetFlags((spaceFlags & wsInconsistent) ? 64 : 0, state);
+ } else if (whingeLevel == 2) {
+ styler.SetFlags((spaceFlags & wsSpaceTab) ? 64 : 0, state);
+ } else if (whingeLevel == 3) {
+ styler.SetFlags((spaceFlags & wsSpace) ? 64 : 0, state);
+ } else if (whingeLevel == 4) {
+ styler.SetFlags((spaceFlags & wsTab) ? 64 : 0, state);
+ }
+ atStartLine = false;
+ }
+
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ chNext2 = styler.SafeGetCharAt(i + 2);
+
+ if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == lengthDoc)) {
+ if ((state == SCE_P_DEFAULT) || (state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE)) {
+ // Perform colourisation of white space and triple quoted strings at end of each line to allow
+ // tab marking to work inside white space and triple quoted strings
+ styler.ColourTo(i, state);
+ }
+
+ int lev = indentCurrent;
+ int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags, IsPyComment);
+ if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
+ // Only non whitespace lines can be headers
+ if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK)) {
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ } else if (indentNext & SC_FOLDLEVELWHITEFLAG) {
+ // Line after is blank so check the next - maybe should continue further?
+ int spaceFlags2 = 0;
+ int indentNext2 = styler.IndentAmount(lineCurrent + 2, &spaceFlags2, IsPyComment);
+ if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext2 & SC_FOLDLEVELNUMBERMASK)) {
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ }
+ }
+ }
+ indentCurrent = indentNext;
+ if (fold) {
+ styler.SetLevel(lineCurrent, lev);
+ }
+ lineCurrent++;
+ atStartLine = true;
+ }
+
+ if (styler.IsLeadByte(ch)) {
+ chNext = styler.SafeGetCharAt(i + 2);
+ chPrev = ' ';
+ chPrev2 = ' ';
+ i += 1;
+ continue;
+ }
+
+ if (state == SCE_P_STRINGEOL) {
+ if (ch != '\r' && ch != '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_P_DEFAULT;
+ }
+ }
+ if (state == SCE_P_DEFAULT) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_P_WORD;
+ } else if (ch == '#') {
+ styler.ColourTo(i - 1, state);
+ state = chNext == '#' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_P_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_P_STRING;
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_P_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_P_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_P_OPERATOR);
+ }
+ } else if (state == SCE_P_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordPy(styler.GetStartSegment(), i - 1, keywords, styler, prevWord);
+ state = SCE_P_DEFAULT;
+ if (ch == '#') {
+ state = chNext == '#' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE;
+ } else if (ch == '\"') {
+ if (chNext == '\"' && chNext2 == '\"') {
+ i += 2;
+ state = SCE_P_TRIPLEDOUBLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_P_STRING;
+ }
+ } else if (ch == '\'') {
+ if (chNext == '\'' && chNext2 == '\'') {
+ i += 2;
+ state = SCE_P_TRIPLE;
+ ch = ' ';
+ chPrev = ' ';
+ chNext = styler.SafeGetCharAt(i + 1);
+ } else {
+ state = SCE_P_CHARACTER;
+ }
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_P_OPERATOR);
+ }
+ }
+ } else {
+ if (state == SCE_P_COMMENTLINE || state == SCE_P_COMMENTBLOCK) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_P_DEFAULT;
+ }
+ } else if (state == SCE_P_STRING) {
+ if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_P_STRINGEOL;
+ } else if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_P_DEFAULT;
+ }
+ } else if (state == SCE_P_CHARACTER) {
+ if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_P_STRINGEOL;
+ } else if (ch == '\\') {
+ if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ } else if (ch == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_P_DEFAULT;
+ }
+ } else if (state == SCE_P_TRIPLE) {
+ if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
+ styler.ColourTo(i, state);
+ state = SCE_P_DEFAULT;
+ }
+ } else if (state == SCE_P_TRIPLEDOUBLE) {
+ if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_P_DEFAULT;
+ }
+ }
+ }
+ chPrev2 = chPrev;
+ chPrev = ch;
+ }
+ if (state == SCE_P_WORD) {
+ classifyWordPy(styler.GetStartSegment(), lengthDoc, keywords, styler, prevWord);
+ } else {
+ styler.ColourTo(lengthDoc, state);
+ }
+}
+
+static LexerModule lmPython(SCLEX_PYTHON, ColourisePyDoc);
diff --git a/src/LexSQL.cxx b/src/LexSQL.cxx
new file mode 100644
index 000000000..c76dd3b07
--- /dev/null
+++ b/src/LexSQL.cxx
@@ -0,0 +1,158 @@
+// SciTE - Scintilla based Text Editor
+// LexSQL.cxx - lexer for SQL
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+static void classifyWordSQL(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = toupper(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_C_IDENTIFIER;
+ if (wordIsNumber)
+ chAttr = SCE_C_NUMBER;
+ else {
+ if (keywords.InList(s))
+ chAttr = SCE_C_WORD;
+ }
+ styler.ColourTo(end, chAttr);
+}
+
+static void ColouriseSQLDoc(unsigned int startPos, int length,
+ int initStyle, WordList *keywordlists[], StylingContext &styler) {
+
+ WordList &keywords = *keywordlists[0];
+
+ styler.StartAt(startPos);
+
+ bool fold = styler.GetPropSet().GetInt("fold");
+ int lineCurrent = styler.GetLine(startPos);
+ int spaceFlags = 0;
+ int indentCurrent = 0;
+
+ int state = initStyle;
+ char chPrev = ' ';
+ char chNext = styler[startPos];
+ styler.StartSegment(startPos);
+ unsigned int lengthDoc = startPos + length;
+ bool prevCr = false;
+ for (unsigned int i = startPos; i <= lengthDoc; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+
+ if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
+ indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags);
+ int lev = indentCurrent;
+ if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
+ // Only non whitespace lines can be headers
+ int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags);
+ if (indentCurrent < (indentNext & ~SC_FOLDLEVELWHITEFLAG)) {
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ }
+ }
+ if (fold) {
+ styler.SetLevel(lineCurrent, lev);
+ }
+ }
+
+ if (styler.IsLeadByte(ch)) {
+ chNext = styler.SafeGetCharAt(i + 2);
+ chPrev = ' ';
+ i += 1;
+ continue;
+ }
+
+ if (state == SCE_C_DEFAULT) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_WORD;
+ } else if (ch == '/' && chNext == '*') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_COMMENT;
+ } else if (ch == '-' && chNext == '-') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_STRING;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i - 1, state);
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ }
+ } else if (state == SCE_C_WORD) {
+ if (!iswordchar(ch)) {
+ classifyWordSQL(styler.GetStartSegment(), i - 1, keywords, styler);
+ state = SCE_C_DEFAULT;
+ if (ch == '/' && chNext == '*') {
+ state = SCE_C_COMMENT;
+ } else if (ch == '-' && chNext == '-') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\'') {
+ state = SCE_C_STRING;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ }
+ }
+ } else {
+ if (state == SCE_C_COMMENT) {
+ if (ch == '/' && chPrev == '*') {
+ if (((i > (styler.GetStartSegment() + 2)) || ((initStyle == SCE_C_COMMENT) &&
+ (styler.GetStartSegment() == startPos)))) {
+ state = SCE_C_DEFAULT;
+ styler.ColourTo(i, state);
+ }
+ }
+ } else if (state == SCE_C_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_DEFAULT;
+ }
+ } else if (state == SCE_C_STRING) {
+ if (ch == '\'') {
+ if ( chNext == '\'' ) {
+ i++;
+ } else {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ i++;
+ }
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
+ if (state == SCE_C_DEFAULT) { // One of the above succeeded
+ if (ch == '/' && chNext == '*') {
+ state = SCE_C_COMMENT;
+ } else if (ch == '-' && chNext == '-') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\'') {
+ state = SCE_C_STRING;
+ } else if (iswordstart(ch)) {
+ state = SCE_C_WORD;
+ } else if (isoperator(ch)) {
+ styler.ColourTo(i, SCE_C_OPERATOR);
+ }
+ }
+ }
+ chPrev = ch;
+ }
+ styler.ColourTo(lengthDoc - 1, state);
+}
+
+static LexerModule lmSQL(SCLEX_SQL, ColouriseSQLDoc);
diff --git a/src/LexVB.cxx b/src/LexVB.cxx
new file mode 100644
index 000000000..a78ea07b5
--- /dev/null
+++ b/src/LexVB.cxx
@@ -0,0 +1,118 @@
+// SciTE - Scintilla based Text Editor
+// LexVB.cxx - lexer for Visual Basic and VBScript
+// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+static int classifyWordVB(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
+
+ char s[100];
+ bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = tolower(styler[start + i]);
+ s[i + 1] = '\0';
+ }
+ char chAttr = SCE_C_DEFAULT;
+ if (wordIsNumber)
+ chAttr = SCE_C_NUMBER;
+ else {
+ if (keywords.InList(s)) {
+ chAttr = SCE_C_WORD;
+ if (strcmp(s, "rem") == 0)
+ chAttr = SCE_C_COMMENTLINE;
+ }
+ }
+ styler.ColourTo(end, chAttr);
+ if (chAttr == SCE_C_COMMENTLINE)
+ return SCE_C_COMMENTLINE;
+ else
+ return SCE_C_DEFAULT;
+}
+
+static void ColouriseVBDoc(unsigned int startPos, int length, int initStyle,
+ WordList *keywordlists[], StylingContext &styler) {
+
+ WordList &keywords = *keywordlists[0];
+
+ styler.StartAt(startPos);
+
+ int state = initStyle;
+ char chNext = styler[startPos];
+ styler.StartSegment(startPos);
+ int lengthDoc = startPos + length;
+ for (int i = startPos; i < lengthDoc; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+
+ if (styler.IsLeadByte(ch)) {
+ chNext = styler.SafeGetCharAt(i + 2);
+ i += 1;
+ continue;
+ }
+
+ if (state == SCE_C_DEFAULT) {
+ if (iswordstart(ch)) {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_WORD;
+ } else if (ch == '\'') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_STRING;
+ }
+ } else if (state == SCE_C_WORD) {
+ if (!iswordchar(ch)) {
+ state = classifyWordVB(styler.GetStartSegment(), i - 1, keywords, styler);
+ if (state == SCE_C_DEFAULT) {
+ if (ch == '\'') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_C_STRING;
+ }
+ }
+ }
+ } else {
+ if (state == SCE_C_COMMENTLINE) {
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_C_DEFAULT;
+ }
+ } else if (state == SCE_C_STRING) {
+ // VB doubles quotes to preserve them
+ if (ch == '\"') {
+ styler.ColourTo(i, state);
+ state = SCE_C_DEFAULT;
+ i++;
+ ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ }
+ if (state == SCE_C_DEFAULT) { // One of the above succeeded
+ if (ch == '\'') {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '\"') {
+ state = SCE_C_STRING;
+ } else if (iswordstart(ch)) {
+ state = SCE_C_WORD;
+ }
+ }
+ }
+ }
+ styler.ColourTo(lengthDoc, state);
+}
+
+static LexerModule lmVB(SCLEX_VB, ColouriseVBDoc);
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 0ca299bd2..21f984044 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -281,8 +281,9 @@ void ScintillaBase::Colourise(int start, int end) {
int styleStart = 0;
if (start > 0)
styleStart = styler.StyleAt(start - 1);
-
- ColouriseDoc(pdoc->dbcsCodePage, start, len, styleStart, lexLanguage, keyWordLists, styler);
+ styler.SetCodePage(pdoc->dbcsCodePage);
+
+ LexerModule::Colourise(start, len, styleStart, lexLanguage, keyWordLists, styler);
styler.Flush();
}
#endif