aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2001-04-11 01:48:54 +0000
committernyamatongwe <unknown>2001-04-11 01:48:54 +0000
commit7a28c364fd8f4028b2aeef1cb12a37cad7ff3d7a (patch)
tree58da9f60f1645f2c115c50c352c651db9de9039c /src
parentaf8495c3f8d7c575e9bece7a4dd7e69f70b764dd (diff)
downloadscintilla-mirror-7a28c364fd8f4028b2aeef1cb12a37cad7ff3d7a.tar.gz
Patch from Philippe to make 'rem' work in batch files.
Moved lex class values from LexOthers.cxx to Scintilla.iface. Added recognition of diff output to errorlist lexer so can see in output pane of SciTE.
Diffstat (limited to 'src')
-rw-r--r--src/LexOthers.cxx264
1 files changed, 131 insertions, 133 deletions
diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx
index 2f0520f1f..da0f70040 100644
--- a/src/LexOthers.cxx
+++ b/src/LexOthers.cxx
@@ -20,30 +20,13 @@
#include "Scintilla.h"
#include "SciLexer.h"
-// Temporary patch, we should put this in SciLexer.h, I suppose
-#define SCE_BAT_DEFAULT 0
-#define SCE_BAT_COMMENT 1
-#define SCE_BAT_WORD 2
-#define SCE_BAT_LABEL 3
-#define SCE_BAT_HIDE 4
-#define SCE_BAT_COMMAND 5
-#define SCE_BAT_IDENTIFIER 6
-#define SCE_BAT_OPERATOR 7
-
-#define SCE_MAKE_DEFAULT 0
-#define SCE_MAKE_COMMENT 1
-#define SCE_MAKE_PREPROCESSOR 2
-#define SCE_MAKE_IDENTIFIER 3
-#define SCE_MAKE_OPERATOR 4
-#define SCE_MAKE_IDEOL 9
-
static void ColouriseBatchLine(
- char *lineBuffer,
- unsigned int lengthLine,
- unsigned int startLine,
- unsigned int endPos,
- WordList &keywords,
- Accessor &styler) {
+ char *lineBuffer,
+ unsigned int lengthLine,
+ unsigned int startLine,
+ unsigned int endPos,
+ WordList &keywords,
+ Accessor &styler) {
unsigned int i = 0;
unsigned int state = SCE_BAT_DEFAULT;
@@ -76,18 +59,24 @@ static void ColouriseBatchLine(
wordBuffer[wbl] = static_cast<char>(tolower(lineBuffer[offset]));
}
wordBuffer[wbl] = '\0';
+ // Check if it is a comment
+ if (CompareCaseInsensitive(wordBuffer, "rem") == 0) {
+ styler.ColourTo(endPos, SCE_BAT_COMMENT);
+ return ;
+ }
// Check if it is in the list
if (keywords.InList(wordBuffer)) {
styler.ColourTo(startLine + offset - 1, SCE_BAT_WORD); // Regular keyword
} else {
// Search end of word (can be a long path)
while (offset < lengthLine &&
- !isspacechar(lineBuffer[offset])) {
+ !isspacechar(lineBuffer[offset])) {
offset++;
}
styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); // External command / program
}
// Remainder of the line: colourise the variables.
+
while (offset < lengthLine) {
if (state == SCE_BAT_DEFAULT && lineBuffer[offset] == '%') {
styler.ColourTo(startLine + offset - 1, state);
@@ -95,7 +84,7 @@ static void ColouriseBatchLine(
styler.ColourTo(startLine + offset + 1, SCE_BAT_IDENTIFIER);
offset += 2;
} else if (lineBuffer[offset + 1] == '%' &&
- !isspacechar(lineBuffer[offset + 2])) {
+ !isspacechar(lineBuffer[offset + 2])) {
// Should be safe, as there is CRLF at the end of the line...
styler.ColourTo(startLine + offset + 2, SCE_BAT_IDENTIFIER);
offset += 3;
@@ -106,21 +95,22 @@ static void ColouriseBatchLine(
styler.ColourTo(startLine + offset, state);
state = SCE_BAT_DEFAULT;
} else if (state == SCE_BAT_DEFAULT &&
- (lineBuffer[offset] == '*' ||
- lineBuffer[offset] == '?' ||
- lineBuffer[offset] == '=' ||
- lineBuffer[offset] == '<' ||
- lineBuffer[offset] == '>' ||
- lineBuffer[offset] == '|')) {
+ (lineBuffer[offset] == '*' ||
+ lineBuffer[offset] == '?' ||
+ lineBuffer[offset] == '=' ||
+ lineBuffer[offset] == '<' ||
+ lineBuffer[offset] == '>' ||
+ lineBuffer[offset] == '|')) {
styler.ColourTo(startLine + offset - 1, state);
styler.ColourTo(startLine + offset, SCE_BAT_OPERATOR);
}
offset++;
}
-// if (endPos > startLine + offset - 1) {
- styler.ColourTo(endPos, SCE_BAT_DEFAULT); // Remainder of line, currently not lexed
-// }
+ // if (endPos > startLine + offset - 1) {
+ styler.ColourTo(endPos, SCE_BAT_DEFAULT); // Remainder of line, currently not lexed
+ // }
}
+
}
// ToDo: (not necessarily at beginning of line) GOTO, [IF] NOT, ERRORLEVEL
// IF [NO] (test) (command) -- test is EXIST (filename) | (string1)==(string2) | ERRORLEVEL (number)
@@ -129,14 +119,14 @@ static void ColouriseBatchLine(
// ToDo: Colourise = > >> < | "
static void ColouriseBatchDoc(
- unsigned int startPos,
- int length,
- int /*initStyle*/,
- WordList *keywordlists[],
- Accessor &styler) {
+ unsigned int startPos,
+ int length,
+ int /*initStyle*/,
+ WordList *keywordlists[],
+ Accessor &styler) {
char lineBuffer[1024];
- WordList &keywords = *keywordlists[0];
+ WordList &keywords = *keywordlists[0];
styler.StartAt(startPos);
styler.StartSegment(startPos);
@@ -202,11 +192,11 @@ static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[
}
static void ColourisePropsLine(
- char *lineBuffer,
- unsigned int lengthLine,
- unsigned int startLine,
- unsigned int endPos,
- Accessor &styler) {
+ char *lineBuffer,
+ unsigned int lengthLine,
+ unsigned int startLine,
+ unsigned int endPos,
+ Accessor &styler) {
unsigned int i = 0;
while (isspacechar(lineBuffer[i]) && (i < lengthLine)) // Skip initial spaces
@@ -216,17 +206,17 @@ static void ColourisePropsLine(
} else if (lineBuffer[i] == '[') {
styler.ColourTo(endPos, 2);
} else if (lineBuffer[i] == '@') {
- styler.ColourTo(startLine+i, 4);
+ styler.ColourTo(startLine + i, 4);
if (lineBuffer[++i] == '=')
- styler.ColourTo(startLine+i, 3);
+ styler.ColourTo(startLine + i, 3);
styler.ColourTo(endPos, 0);
} else {
// Search for the '=' character
- while (lineBuffer[i] != '=' && (i < lengthLine-1))
+ while (lineBuffer[i] != '=' && (i < lengthLine - 1))
i++;
if (lineBuffer[i] == '=') {
- styler.ColourTo(startLine+i-1, 0);
- styler.ColourTo(startLine+i, 3);
+ styler.ColourTo(startLine + i - 1, 0);
+ styler.ColourTo(startLine + i, 3);
styler.ColourTo(endPos, 0);
} else {
styler.ColourTo(endPos, 0);
@@ -241,13 +231,13 @@ static void ColourisePropsDoc(unsigned int startPos, int length, int, WordList *
unsigned int linePos = 0, 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 ((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)
@@ -255,11 +245,11 @@ static void ColourisePropsDoc(unsigned int startPos, int length, int, WordList *
}
static void ColouriseMakeLine(
- char *lineBuffer,
- unsigned int lengthLine,
- unsigned int startLine,
- unsigned int endPos,
- Accessor &styler) {
+ char *lineBuffer,
+ unsigned int lengthLine,
+ unsigned int startLine,
+ unsigned int endPos,
+ Accessor &styler) {
unsigned int i = 0;
unsigned int state = SCE_MAKE_DEFAULT;
@@ -270,14 +260,14 @@ static void ColouriseMakeLine(
}
if (lineBuffer[i] == '#') { // Comment
styler.ColourTo(endPos, SCE_MAKE_COMMENT);
- return;
+ return ;
}
if (lineBuffer[i] == '!') { // Special directive
styler.ColourTo(endPos, SCE_MAKE_PREPROCESSOR);
- return;
+ return ;
}
while (i < lengthLine) {
- if (lineBuffer[i] == '$' && lineBuffer[i+1] == '(') {
+ if (lineBuffer[i] == '$' && lineBuffer[i + 1] == '(') {
styler.ColourTo(startLine + i - 1, state);
state = SCE_MAKE_IDENTIFIER;
} else if (state == SCE_MAKE_IDENTIFIER && lineBuffer[i] == ')') {
@@ -285,16 +275,18 @@ static void ColouriseMakeLine(
state = SCE_MAKE_DEFAULT;
}
if (!bSpecial && state == SCE_MAKE_DEFAULT &&
- (lineBuffer[i] == ':' || lineBuffer[i] == '=')) {
+ (lineBuffer[i] == ':' || lineBuffer[i] == '=')) {
styler.ColourTo(startLine + i - 1, state);
styler.ColourTo(startLine + i, SCE_MAKE_OPERATOR);
bSpecial = true; // Only react to the first '=' or ':' of the line
}
+
i++;
}
if (state == SCE_MAKE_IDENTIFIER) {
styler.ColourTo(endPos, SCE_MAKE_IDEOL); // Error, variable reference not ended
- } else {
+ }
+ else {
styler.ColourTo(endPos, SCE_MAKE_DEFAULT);
}
}
@@ -310,7 +302,7 @@ static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[
lineBuffer[linePos] = '\0';
ColouriseMakeLine(lineBuffer, linePos, startLine, i, styler);
linePos = 0;
- startLine = i+1;
+ startLine = i + 1;
}
}
if (linePos > 0) {
@@ -319,15 +311,22 @@ static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[
}
static void ColouriseErrorListLine(
- char *lineBuffer,
- unsigned int lengthLine,
-// unsigned int startLine,
- unsigned int endPos,
- Accessor &styler) {
-
+ char *lineBuffer,
+ unsigned int lengthLine,
+ // unsigned int startLine,
+ unsigned int endPos,
+ Accessor &styler) {
if (lineBuffer[0] == '>') {
// Command or return status
styler.ColourTo(endPos, SCE_ERR_CMD);
+ } else if (lineBuffer[0] == '!') {
+ styler.ColourTo(endPos, SCE_ERR_DIFF_CHANGED);
+ } else if (lineBuffer[0] == '+') {
+ styler.ColourTo(endPos, SCE_ERR_DIFF_ADDITION);
+ } else if (lineBuffer[0] == '-' && lineBuffer[1] == '-' && lineBuffer[2] == '-') {
+ styler.ColourTo(endPos, SCE_ERR_DIFF_MESSAGE);
+ } else if (lineBuffer[0] == '-') {
+ styler.ColourTo(endPos, SCE_ERR_DIFF_DELETION);
} else if (strstr(lineBuffer, "File \"") && strstr(lineBuffer, ", line ")) {
styler.ColourTo(endPos, SCE_ERR_PYTHON);
} else if (0 == strncmp(lineBuffer, "Error ", strlen("Error "))) {
@@ -336,10 +335,10 @@ static void ColouriseErrorListLine(
} else if (0 == strncmp(lineBuffer, "Warning ", strlen("Warning "))) {
// Borland warning message
styler.ColourTo(endPos, SCE_ERR_BORLAND);
- } else if (strstr(lineBuffer, " at " ) &&
- strstr(lineBuffer, " at " ) < lineBuffer+lengthLine &&
- strstr(lineBuffer, " line ") &&
- strstr(lineBuffer, " line ") < lineBuffer+lengthLine) {
+ } else if (strstr(lineBuffer, " at " ) &&
+ strstr(lineBuffer, " at " ) < lineBuffer + lengthLine &&
+ strstr(lineBuffer, " line ") &&
+ strstr(lineBuffer, " line ") < lineBuffer + lengthLine) {
// perl error message
styler.ColourTo(endPos, SCE_ERR_PERL);
} else {
@@ -407,7 +406,7 @@ static int isSpecial(char s) {
static int isTag(int start, Accessor &styler) {
char s[6];
- unsigned int i = 0, e=1;
+ unsigned int i = 0, e = 1;
while (i < 5 && e) {
s[i] = styler[start + i];
i++;
@@ -418,7 +417,7 @@ static int isTag(int start, Accessor &styler) {
}
static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
- WordList *[], Accessor &styler) {
+ WordList *[], Accessor &styler) {
styler.StartAt(startPos);
@@ -436,67 +435,66 @@ static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
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;
+ 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 SCE_L_TAG :
- if (ch == '}') {
- styler.ColourTo(i, state);
- state = SCE_L_DEFAULT;
+ case '$' :
+ styler.ColourTo(i - 1, state);
+ state = SCE_L_MATH;
+ if (chNext == '$') {
+ i++;
+ chNext = styler.SafeGetCharAt(i + 1);
}
break;
- case SCE_L_MATH :
- if (ch == '$') {
- if (chNext == '$') {
- i++;
- chNext = styler.SafeGetCharAt(i + 1);
- }
- styler.ColourTo(i, state);
- state = SCE_L_DEFAULT;
- }
+ case '%' :
+ styler.ColourTo(i - 1, state);
+ state = SCE_L_COMMENT;
break;
- case SCE_L_COMMENT :
- if (ch == '\r' || ch == '\n') {
- styler.ColourTo(i - 1, state);
- state = SCE_L_DEFAULT;
+ }
+ 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);