aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/SciLexer.h8
-rw-r--r--include/Scintilla.iface6
-rw-r--r--src/LexOthers.cxx105
3 files changed, 119 insertions, 0 deletions
diff --git a/include/SciLexer.h b/include/SciLexer.h
index b99526e4f..d869758f6 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -22,6 +22,7 @@
#define SCLEX_MAKEFILE 11
#define SCLEX_BATCH 12
#define SCLEX_XCODE 13
+#define SCLEX_LATEX 14
// Lexical states for SCLEX_PYTHON
#define SCE_P_DEFAULT 0
@@ -170,4 +171,11 @@
#define SCE_PL_BACKTICKS 20
#define SCE_PL_DATASECTION 21
+// Lexical states for SCLEX_LATEX
+#define SCE_L_DEFAULT 0
+#define SCE_L_COMMAND 1
+#define SCE_L_TAG 2
+#define SCE_L_MATH 3
+#define SCE_L_COMMENT 4
+
#endif
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index b10252ac0..0233a24ca 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -762,6 +762,7 @@ val SCLEX_ERRORLIST=10
val SCLEX_MAKEFILE=11
val SCLEX_BATCH=12
val SCLEX_XCODE=13
+val SCLEX_LATEX=14
val SCE_P_DEFAULT=0
val SCE_P_COMMENTLINE=1
val SCE_P_NUMBER=2
@@ -894,6 +895,11 @@ val SCE_PL_REGSUBST=18
val SCE_PL_LONGQUOTE=19
val SCE_PL_BACKTICKS=20
val SCE_PL_DATASECTION=21
+val SCE_L_DEFAULT=0
+val SCE_L_COMMAND=1
+val SCE_L_TAG=2
+val SCE_L_MATH=3
+val SCE_L_COMMENT=4
################################################
# From WinDefs.h
diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx
index 30589d6f3..90f41e3bf 100644
--- a/src/LexOthers.cxx
+++ b/src/LexOthers.cxx
@@ -193,7 +193,112 @@ static void ColouriseErrorListDoc(unsigned int startPos, int length, int, WordLi
ColouriseErrorListLine(lineBuffer, linePos, startPos + length, styler);
}
+static int isSpecial(char s) {
+
+ return (s == '\\') || (s == ',') || (s == ';') || (s == '\'') || (s == ' ') ||
+ (s == '\"') || (s == '`') || (s == '^') || (s == '~');
+}
+
+static int isTag(int start, Accessor &styler) {
+
+ char s[6];
+ unsigned int i = 0, e=1;
+ while (i < 5 && e) {
+ s[i] = styler[start + i];
+ i++;
+ e = styler[start + i] != '{';
+ }
+ s[i] = '\0';
+ return (strcmp(s, "begin") == 0) || (strcmp(s, "end") == 0);
+}
+
+static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
+ WordList *[], Accessor &styler) {
+
+ 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++;
+ continue;
+ }
+ switch(state) {
+ case SCE_L_DEFAULT :
+ switch(ch) {
+ case '\\' :
+ styler.ColourTo(i - 1, state);
+ if (isSpecial(styler[i + 1])) {
+ styler.ColourTo(i + 1, SCE_L_COMMAND);
+ i++;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ else {
+ if (isTag(i+1, styler))
+ state = SCE_L_TAG;
+ else
+ state = SCE_L_COMMAND;
+ }
+ break;
+ case '$' :
+ styler.ColourTo(i - 1, state);
+ state = SCE_L_MATH;
+ if (chNext == '$') {
+ i++;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ break;
+ case '%' :
+ styler.ColourTo(i - 1, state);
+ state = SCE_L_COMMENT;
+ break;
+ }
+ break;
+ case SCE_L_COMMAND :
+ if (chNext == '[' || chNext == '{' || chNext == '}' ||
+ chNext == ' ' || chNext == '\r' || chNext == '\n') {
+ styler.ColourTo(i, state);
+ state = SCE_L_DEFAULT;
+ i++;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ break;
+ case SCE_L_TAG :
+ if (ch == '}') {
+ styler.ColourTo(i, state);
+ state = SCE_L_DEFAULT;
+ }
+ break;
+ case SCE_L_MATH :
+ if (ch == '$') {
+ if (chNext == '$') {
+ i++;
+ chNext = styler.SafeGetCharAt(i + 1);
+ }
+ styler.ColourTo(i, state);
+ state = SCE_L_DEFAULT;
+ }
+ break;
+ case SCE_L_COMMENT :
+ if (ch == '\r' || ch == '\n') {
+ styler.ColourTo(i - 1, state);
+ state = SCE_L_DEFAULT;
+ }
+ }
+ }
+ styler.ColourTo(lengthDoc, state);
+}
+
LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc);
LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);
LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc);
LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc);
+LexerModule lmLatex(SCLEX_LATEX, ColouriseLatexDoc);