]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexOthers.cxx
1 // SciTE - Scintilla based Text Editor
2 // LexOthers.cxx - lexers for properties files, batch files, make files and error lists
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
17 #include "Scintilla.h"
20 static void ColouriseBatchLine(char *lineBuffer
, int endLine
, Accessor
&styler
) {
21 if (0 == strncmp(lineBuffer
, "REM", 3)) {
22 styler
.ColourTo(endLine
, 1);
23 } else if (0 == strncmp(lineBuffer
, "rem", 3)) {
24 styler
.ColourTo(endLine
, 1);
25 } else if (0 == strncmp(lineBuffer
, "SET", 3)) {
26 styler
.ColourTo(endLine
, 2);
27 } else if (0 == strncmp(lineBuffer
, "set", 3)) {
28 styler
.ColourTo(endLine
, 2);
29 } else if (lineBuffer
[0] == ':') {
30 styler
.ColourTo(endLine
, 3);
32 styler
.ColourTo(endLine
, 0);
36 static void ColouriseBatchDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
37 char lineBuffer
[1024];
38 styler
.StartAt(startPos
);
39 styler
.StartSegment(startPos
);
40 unsigned int linePos
= 0;
41 for (unsigned int i
= startPos
; i
< startPos
+ length
; i
++) {
42 lineBuffer
[linePos
++] = styler
[i
];
43 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
44 ColouriseBatchLine(lineBuffer
, i
, styler
);
49 ColouriseBatchLine(lineBuffer
, startPos
+ length
, styler
);
52 static void ColouriseDiffLine(char *lineBuffer
, int endLine
, Accessor
&styler
) {
53 // It is needed to remember the current state to recognize starting
54 // comment lines before the first "diff " or "--- ". If a real
55 // difference starts then each line starting with ' ' is a whitespace
56 // otherwise it is considered a comment (Only in..., Binary file...)
57 if (0 == strncmp(lineBuffer
, "diff ", 3)) {
58 styler
.ColourTo(endLine
, 2);
59 } else if (0 == strncmp(lineBuffer
, "--- ", 3)) {
60 styler
.ColourTo(endLine
, 3);
61 } else if (0 == strncmp(lineBuffer
, "+++ ", 3)) {
62 styler
.ColourTo(endLine
, 3);
63 } else if (lineBuffer
[0] == '@') {
64 styler
.ColourTo(endLine
, 4);
65 } else if (lineBuffer
[0] == '-') {
66 styler
.ColourTo(endLine
, 5);
67 } else if (lineBuffer
[0] == '+') {
68 styler
.ColourTo(endLine
, 6);
69 } else if (lineBuffer
[0] != ' ') {
70 styler
.ColourTo(endLine
, 1);
72 styler
.ColourTo(endLine
, 0);
76 static void ColouriseDiffDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
77 char lineBuffer
[1024];
78 styler
.StartAt(startPos
);
79 styler
.StartSegment(startPos
);
80 unsigned int linePos
= 0;
81 for (unsigned int i
= startPos
; i
< startPos
+ length
; i
++) {
82 lineBuffer
[linePos
++] = styler
[i
];
83 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
84 ColouriseDiffLine(lineBuffer
, i
, styler
);
89 ColouriseDiffLine(lineBuffer
, startPos
+ length
, styler
);
92 static void ColourisePropsLine(char *lineBuffer
, int lengthLine
, int startLine
, int endPos
, Accessor
&styler
) {
94 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
)) // Skip initial spaces
96 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!' || lineBuffer
[i
] == ';') {
97 styler
.ColourTo(endPos
, 1);
98 } else if (lineBuffer
[i
] == '[') {
99 styler
.ColourTo(endPos
, 2);
100 } else if (lineBuffer
[i
] == '@') {
101 styler
.ColourTo(startLine
+i
, 4);
102 if (lineBuffer
[++i
] == '=')
103 styler
.ColourTo(startLine
+i
, 3);
104 styler
.ColourTo(endPos
, 0);
106 while (lineBuffer
[i
] != '=' && (i
< lengthLine
)) // Search the '=' character
108 if (lineBuffer
[i
] == '=') {
109 styler
.ColourTo(startLine
+i
-1, 0);
110 styler
.ColourTo(startLine
+i
, 3);
111 styler
.ColourTo(endPos
, 0);
113 styler
.ColourTo(endPos
, 0);
118 static void ColourisePropsDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
119 char lineBuffer
[1024];
120 styler
.StartAt(startPos
);
121 styler
.StartSegment(startPos
);
122 unsigned int linePos
= 0;
123 int startLine
= startPos
;
124 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
125 lineBuffer
[linePos
++] = styler
[i
];
126 if ((styler
[i
] == '\r' && styler
.SafeGetCharAt(i
+1) != '\n') ||
128 (linePos
>= sizeof(lineBuffer
) - 1)) {
129 lineBuffer
[linePos
] = '\0';
130 ColourisePropsLine(lineBuffer
, linePos
, startLine
, i
, styler
);
136 ColourisePropsLine(lineBuffer
, linePos
, startLine
, startPos
+ length
, styler
);
139 static void ColouriseMakeLine(char *lineBuffer
, int lengthLine
, int endPos
, Accessor
&styler
) {
141 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
))
143 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!') {
144 styler
.ColourTo(endPos
, 1);
146 styler
.ColourTo(endPos
, 0);
150 static void ColouriseMakeDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
151 char lineBuffer
[1024];
152 styler
.StartAt(startPos
);
153 styler
.StartSegment(startPos
);
154 unsigned int linePos
= 0;
155 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
156 lineBuffer
[linePos
++] = styler
[i
];
157 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
158 ColouriseMakeLine(lineBuffer
, linePos
, i
, styler
);
163 ColouriseMakeLine(lineBuffer
, linePos
, startPos
+ length
, styler
);
166 static void ColouriseErrorListLine(char *lineBuffer
, int lengthLine
, int endPos
, Accessor
&styler
) {
167 if (lineBuffer
[0] == '>') {
168 // Command or return status
169 styler
.ColourTo(endPos
, SCE_ERR_CMD
);
170 } else if (strstr(lineBuffer
, "File \"") && strstr(lineBuffer
, ", line ")) {
171 styler
.ColourTo(endPos
, SCE_ERR_PYTHON
);
172 } else if (0 == strncmp(lineBuffer
, "Error ", strlen("Error "))) {
173 // Borland error message
174 styler
.ColourTo(endPos
, SCE_ERR_BORLAND
);
175 } else if (0 == strncmp(lineBuffer
, "Warning ", strlen("Warning "))) {
176 // Borland warning message
177 styler
.ColourTo(endPos
, SCE_ERR_BORLAND
);
178 } else if (strstr(lineBuffer
, " at " ) &&
179 strstr(lineBuffer
, " at " ) < lineBuffer
+lengthLine
&&
180 strstr(lineBuffer
, " line ") &&
181 strstr(lineBuffer
, " line ") < lineBuffer
+lengthLine
) {
182 // perl error message
183 styler
.ColourTo(endPos
, SCE_ERR_PERL
);
185 // Look for <filename>:<line>:message
186 // Look for <filename>(line)message
187 // Look for <filename>(line,pos)message
189 for (int i
= 0; i
< lengthLine
; i
++) {
190 if (state
== 0 && lineBuffer
[i
] == ':' && isdigit(lineBuffer
[i
+ 1])) {
192 } else if (state
== 0 && lineBuffer
[i
] == '(') {
194 } else if (state
== 1 && isdigit(lineBuffer
[i
])) {
196 } else if (state
== 2 && lineBuffer
[i
] == ':') {
199 } else if (state
== 2 && !isdigit(lineBuffer
[i
])) {
201 } else if (state
== 10 && isdigit(lineBuffer
[i
])) {
203 } else if (state
== 11 && lineBuffer
[i
] == ',') {
205 } else if (state
== 11 && lineBuffer
[i
] == ')') {
207 } else if (state
== 12 && lineBuffer
[i
] == ':') {
209 } else if (state
== 14 && lineBuffer
[i
] == ')') {
212 } else if (((state
== 11) || (state
== 14)) && !((lineBuffer
[i
] == ' ') || isdigit(lineBuffer
[i
]))) {
217 styler
.ColourTo(endPos
, SCE_ERR_GCC
);
218 } else if ((state
== 13) || (state
== 14) || (state
== 15)) {
219 styler
.ColourTo(endPos
, SCE_ERR_MS
);
221 styler
.ColourTo(endPos
, SCE_ERR_DEFAULT
);
226 static void ColouriseErrorListDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
227 char lineBuffer
[1024];
228 styler
.StartAt(startPos
);
229 styler
.StartSegment(startPos
);
230 unsigned int linePos
= 0;
231 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
232 lineBuffer
[linePos
++] = styler
[i
];
233 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
234 ColouriseErrorListLine(lineBuffer
, linePos
, i
, styler
);
239 ColouriseErrorListLine(lineBuffer
, linePos
, startPos
+ length
, styler
);
242 static int isSpecial(char s
) {
244 return (s
== '\\') || (s
== ',') || (s
== ';') || (s
== '\'') || (s
== ' ') ||
245 (s
== '\"') || (s
== '`') || (s
== '^') || (s
== '~');
248 static int isTag(int start
, Accessor
&styler
) {
251 unsigned int i
= 0, e
=1;
253 s
[i
] = styler
[start
+ i
];
255 e
= styler
[start
+ i
] != '{';
258 return (strcmp(s
, "begin") == 0) || (strcmp(s
, "end") == 0);
261 static void ColouriseLatexDoc(unsigned int startPos
, int length
, int initStyle
,
262 WordList
*[], Accessor
&styler
) {
264 styler
.StartAt(startPos
);
266 int state
= initStyle
;
267 char chNext
= styler
[startPos
];
268 styler
.StartSegment(startPos
);
269 int lengthDoc
= startPos
+ length
;
271 for (int i
= startPos
; i
< lengthDoc
; i
++) {
273 chNext
= styler
.SafeGetCharAt(i
+ 1);
275 if (styler
.IsLeadByte(ch
)) {
276 chNext
= styler
.SafeGetCharAt(i
+ 2);
284 styler
.ColourTo(i
- 1, state
);
285 if (isSpecial(styler
[i
+ 1])) {
286 styler
.ColourTo(i
+ 1, SCE_L_COMMAND
);
288 chNext
= styler
.SafeGetCharAt(i
+ 1);
291 if (isTag(i
+1, styler
))
294 state
= SCE_L_COMMAND
;
298 styler
.ColourTo(i
- 1, state
);
302 chNext
= styler
.SafeGetCharAt(i
+ 1);
306 styler
.ColourTo(i
- 1, state
);
307 state
= SCE_L_COMMENT
;
312 if (chNext
== '[' || chNext
== '{' || chNext
== '}' ||
313 chNext
== ' ' || chNext
== '\r' || chNext
== '\n') {
314 styler
.ColourTo(i
, state
);
315 state
= SCE_L_DEFAULT
;
317 chNext
= styler
.SafeGetCharAt(i
+ 1);
322 styler
.ColourTo(i
, state
);
323 state
= SCE_L_DEFAULT
;
330 chNext
= styler
.SafeGetCharAt(i
+ 1);
332 styler
.ColourTo(i
, state
);
333 state
= SCE_L_DEFAULT
;
337 if (ch
== '\r' || ch
== '\n') {
338 styler
.ColourTo(i
- 1, state
);
339 state
= SCE_L_DEFAULT
;
343 styler
.ColourTo(lengthDoc
, state
);
346 LexerModule
lmBatch(SCLEX_BATCH
, ColouriseBatchDoc
);
347 LexerModule
lmDiff(SCLEX_DIFF
, ColouriseDiffDoc
);
348 LexerModule
lmProps(SCLEX_PROPERTIES
, ColourisePropsDoc
);
349 LexerModule
lmMake(SCLEX_MAKEFILE
, ColouriseMakeDoc
);
350 LexerModule
lmErrorList(SCLEX_ERRORLIST
, ColouriseErrorListDoc
);
351 LexerModule
lmLatex(SCLEX_LATEX
, ColouriseLatexDoc
);