]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexOthers.cxx
using CLSCTX_ALL fails with Microsoft Office applications, correct the last change...
[wxWidgets.git] / src / stc / scintilla / src / LexOthers.cxx
1 // Scintilla source code edit control
2 /** @file LexOthers.cxx
3 ** Lexers for batch files, diff results, properties files, make files and error lists.
4 ** Also lexer for LaTeX documents.
5 **/
6 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
8
9 #include <stdlib.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14
15 #include "Platform.h"
16
17 #include "PropSet.h"
18 #include "Accessor.h"
19 #include "KeyWords.h"
20 #include "Scintilla.h"
21 #include "SciLexer.h"
22
23 #ifdef SCI_NAMESPACE
24 using namespace Scintilla;
25 #endif
26
27 static bool Is0To9(char ch) {
28 return (ch >= '0') && (ch <= '9');
29 }
30
31 static bool Is1To9(char ch) {
32 return (ch >= '1') && (ch <= '9');
33 }
34
35 static inline bool AtEOL(Accessor &styler, unsigned int i) {
36 return (styler[i] == '\n') ||
37 ((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
38 }
39
40 // Tests for BATCH Operators
41 static bool IsBOperator(char ch) {
42 return (ch == '=') || (ch == '+') || (ch == '>') || (ch == '<') ||
43 (ch == '|') || (ch == '?') || (ch == '*');
44 }
45
46 // Tests for BATCH Separators
47 static bool IsBSeparator(char ch) {
48 return (ch == '\\') || (ch == '.') || (ch == ';') ||
49 (ch == '\"') || (ch == '\'') || (ch == '/') || (ch == ')');
50 }
51
52 static void ColouriseBatchLine(
53 char *lineBuffer,
54 unsigned int lengthLine,
55 unsigned int startLine,
56 unsigned int endPos,
57 WordList *keywordlists[],
58 Accessor &styler) {
59
60 unsigned int offset = 0; // Line Buffer Offset
61 unsigned int enVarEnd; // Environment Variable End point
62 unsigned int cmdLoc; // External Command / Program Location
63 char wordBuffer[81]; // Word Buffer - large to catch long paths
64 unsigned int wbl; // Word Buffer Length
65 unsigned int wbo; // Word Buffer Offset - also Special Keyword Buffer Length
66 WordList &keywords = *keywordlists[0]; // Internal Commands
67 WordList &keywords2 = *keywordlists[1]; // External Commands (optional)
68
69 // CHOICE, ECHO, GOTO, PROMPT and SET have Default Text that may contain Regular Keywords
70 // Toggling Regular Keyword Checking off improves readability
71 // Other Regular Keywords and External Commands / Programs might also benefit from toggling
72 // Need a more robust algorithm to properly toggle Regular Keyword Checking
73 bool continueProcessing = true; // Used to toggle Regular Keyword Checking
74 // Special Keywords are those that allow certain characters without whitespace after the command
75 // Examples are: cd. cd\ md. rd. dir| dir> echo: echo. path=
76 // Special Keyword Buffer used to determine if the first n characters is a Keyword
77 char sKeywordBuffer[10]; // Special Keyword Buffer
78 bool sKeywordFound; // Exit Special Keyword for-loop if found
79
80 // Skip initial spaces
81 while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
82 offset++;
83 }
84 // Colorize Default Text
85 styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
86 // Set External Command / Program Location
87 cmdLoc = offset;
88
89 // Check for Fake Label (Comment) or Real Label - return if found
90 if (lineBuffer[offset] == ':') {
91 if (lineBuffer[offset + 1] == ':') {
92 // Colorize Fake Label (Comment) - :: is similar to REM, see http://content.techweb.com/winmag/columns/explorer/2000/21.htm
93 styler.ColourTo(endPos, SCE_BAT_COMMENT);
94 } else {
95 // Colorize Real Label
96 styler.ColourTo(endPos, SCE_BAT_LABEL);
97 }
98 return;
99 // Check for Drive Change (Drive Change is internal command) - return if found
100 } else if ((isalpha(lineBuffer[offset])) &&
101 (lineBuffer[offset + 1] == ':') &&
102 ((isspacechar(lineBuffer[offset + 2])) ||
103 (((lineBuffer[offset + 2] == '\\')) &&
104 (isspacechar(lineBuffer[offset + 3]))))) {
105 // Colorize Regular Keyword
106 styler.ColourTo(endPos, SCE_BAT_WORD);
107 return;
108 }
109
110 // Check for Hide Command (@ECHO OFF/ON)
111 if (lineBuffer[offset] == '@') {
112 styler.ColourTo(startLine + offset, SCE_BAT_HIDE);
113 offset++;
114 // Check for Argument (%n) or Environment Variable (%x...%)
115 } else if (lineBuffer[offset] == '%') {
116 enVarEnd = offset + 1;
117 // Search end of word for second % (can be a long path)
118 while ((enVarEnd < lengthLine) &&
119 (!isspacechar(lineBuffer[enVarEnd])) &&
120 (lineBuffer[enVarEnd] != '%') &&
121 (!IsBOperator(lineBuffer[enVarEnd])) &&
122 (!IsBSeparator(lineBuffer[enVarEnd]))) {
123 enVarEnd++;
124 }
125 // Check for Argument (%n)
126 if ((Is0To9(lineBuffer[offset + 1])) &&
127 (lineBuffer[enVarEnd] != '%')) {
128 // Colorize Argument
129 styler.ColourTo(startLine + offset + 1, SCE_BAT_IDENTIFIER);
130 offset += 2;
131 // Check for External Command / Program
132 if (offset < lengthLine && !isspacechar(lineBuffer[offset])) {
133 cmdLoc = offset;
134 }
135 // Check for Environment Variable (%x...%)
136 } else if ((lineBuffer[offset + 1] != '%') &&
137 (lineBuffer[enVarEnd] == '%')) {
138 offset = enVarEnd;
139 // Colorize Environment Variable
140 styler.ColourTo(startLine + offset, SCE_BAT_IDENTIFIER);
141 offset++;
142 // Check for External Command / Program
143 if (offset < lengthLine && !isspacechar(lineBuffer[offset])) {
144 cmdLoc = offset;
145 }
146 }
147 }
148 // Skip next spaces
149 while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
150 offset++;
151 }
152
153 // Read remainder of line word-at-a-time or remainder-of-word-at-a-time
154 while (offset < lengthLine) {
155 if (offset > startLine) {
156 // Colorize Default Text
157 styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
158 }
159 // Copy word from Line Buffer into Word Buffer
160 wbl = 0;
161 for (; offset < lengthLine && wbl < 80 &&
162 !isspacechar(lineBuffer[offset]); wbl++, offset++) {
163 wordBuffer[wbl] = static_cast<char>(tolower(lineBuffer[offset]));
164 }
165 wordBuffer[wbl] = '\0';
166 wbo = 0;
167
168 // Check for Comment - return if found
169 if (CompareCaseInsensitive(wordBuffer, "rem") == 0) {
170 styler.ColourTo(endPos, SCE_BAT_COMMENT);
171 return;
172 }
173 // Check for Separator
174 if (IsBSeparator(wordBuffer[0])) {
175 // Check for External Command / Program
176 if ((cmdLoc == offset - wbl) &&
177 ((wordBuffer[0] == ':') ||
178 (wordBuffer[0] == '\\') ||
179 (wordBuffer[0] == '.'))) {
180 // Reset Offset to re-process remainder of word
181 offset -= (wbl - 1);
182 // Colorize External Command / Program
183 if (!keywords2) {
184 styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
185 } else if (keywords2.InList(wordBuffer)) {
186 styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
187 } else {
188 styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
189 }
190 // Reset External Command / Program Location
191 cmdLoc = offset;
192 } else {
193 // Reset Offset to re-process remainder of word
194 offset -= (wbl - 1);
195 // Colorize Default Text
196 styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
197 }
198 // Check for Regular Keyword in list
199 } else if ((keywords.InList(wordBuffer)) &&
200 (continueProcessing)) {
201 // ECHO, GOTO, PROMPT and SET require no further Regular Keyword Checking
202 if ((CompareCaseInsensitive(wordBuffer, "echo") == 0) ||
203 (CompareCaseInsensitive(wordBuffer, "goto") == 0) ||
204 (CompareCaseInsensitive(wordBuffer, "prompt") == 0) ||
205 (CompareCaseInsensitive(wordBuffer, "set") == 0)) {
206 continueProcessing = false;
207 }
208 // Identify External Command / Program Location for ERRORLEVEL, and EXIST
209 if ((CompareCaseInsensitive(wordBuffer, "errorlevel") == 0) ||
210 (CompareCaseInsensitive(wordBuffer, "exist") == 0)) {
211 // Reset External Command / Program Location
212 cmdLoc = offset;
213 // Skip next spaces
214 while ((cmdLoc < lengthLine) &&
215 (isspacechar(lineBuffer[cmdLoc]))) {
216 cmdLoc++;
217 }
218 // Skip comparison
219 while ((cmdLoc < lengthLine) &&
220 (!isspacechar(lineBuffer[cmdLoc]))) {
221 cmdLoc++;
222 }
223 // Skip next spaces
224 while ((cmdLoc < lengthLine) &&
225 (isspacechar(lineBuffer[cmdLoc]))) {
226 cmdLoc++;
227 }
228 // Identify External Command / Program Location for CALL, DO, LOADHIGH and LH
229 } else if ((CompareCaseInsensitive(wordBuffer, "call") == 0) ||
230 (CompareCaseInsensitive(wordBuffer, "do") == 0) ||
231 (CompareCaseInsensitive(wordBuffer, "loadhigh") == 0) ||
232 (CompareCaseInsensitive(wordBuffer, "lh") == 0)) {
233 // Reset External Command / Program Location
234 cmdLoc = offset;
235 // Skip next spaces
236 while ((cmdLoc < lengthLine) &&
237 (isspacechar(lineBuffer[cmdLoc]))) {
238 cmdLoc++;
239 }
240 }
241 // Colorize Regular keyword
242 styler.ColourTo(startLine + offset - 1, SCE_BAT_WORD);
243 // No need to Reset Offset
244 // Check for Special Keyword in list, External Command / Program, or Default Text
245 } else if ((wordBuffer[0] != '%') &&
246 (!IsBOperator(wordBuffer[0])) &&
247 (continueProcessing)) {
248 // Check for Special Keyword
249 // Affected Commands are in Length range 2-6
250 // Good that ERRORLEVEL, EXIST, CALL, DO, LOADHIGH, and LH are unaffected
251 sKeywordFound = false;
252 for (unsigned int keywordLength = 2; keywordLength < wbl && keywordLength < 7 && !sKeywordFound; keywordLength++) {
253 wbo = 0;
254 // Copy Keyword Length from Word Buffer into Special Keyword Buffer
255 for (; wbo < keywordLength; wbo++) {
256 sKeywordBuffer[wbo] = static_cast<char>(wordBuffer[wbo]);
257 }
258 sKeywordBuffer[wbo] = '\0';
259 // Check for Special Keyword in list
260 if ((keywords.InList(sKeywordBuffer)) &&
261 ((IsBOperator(wordBuffer[wbo])) ||
262 (IsBSeparator(wordBuffer[wbo])))) {
263 sKeywordFound = true;
264 // ECHO requires no further Regular Keyword Checking
265 if (CompareCaseInsensitive(sKeywordBuffer, "echo") == 0) {
266 continueProcessing = false;
267 }
268 // Colorize Special Keyword as Regular Keyword
269 styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_WORD);
270 // Reset Offset to re-process remainder of word
271 offset -= (wbl - wbo);
272 }
273 }
274 // Check for External Command / Program or Default Text
275 if (!sKeywordFound) {
276 wbo = 0;
277 // Check for External Command / Program
278 if (cmdLoc == offset - wbl) {
279 // Read up to %, Operator or Separator
280 while ((wbo < wbl) &&
281 (wordBuffer[wbo] != '%') &&
282 (!IsBOperator(wordBuffer[wbo])) &&
283 (!IsBSeparator(wordBuffer[wbo]))) {
284 wbo++;
285 }
286 // Reset External Command / Program Location
287 cmdLoc = offset - (wbl - wbo);
288 // Reset Offset to re-process remainder of word
289 offset -= (wbl - wbo);
290 // CHOICE requires no further Regular Keyword Checking
291 if (CompareCaseInsensitive(wordBuffer, "choice") == 0) {
292 continueProcessing = false;
293 }
294 // Check for START (and its switches) - What follows is External Command \ Program
295 if (CompareCaseInsensitive(wordBuffer, "start") == 0) {
296 // Reset External Command / Program Location
297 cmdLoc = offset;
298 // Skip next spaces
299 while ((cmdLoc < lengthLine) &&
300 (isspacechar(lineBuffer[cmdLoc]))) {
301 cmdLoc++;
302 }
303 // Reset External Command / Program Location if command switch detected
304 if (lineBuffer[cmdLoc] == '/') {
305 // Skip command switch
306 while ((cmdLoc < lengthLine) &&
307 (!isspacechar(lineBuffer[cmdLoc]))) {
308 cmdLoc++;
309 }
310 // Skip next spaces
311 while ((cmdLoc < lengthLine) &&
312 (isspacechar(lineBuffer[cmdLoc]))) {
313 cmdLoc++;
314 }
315 }
316 }
317 // Colorize External Command / Program
318 if (!keywords2) {
319 styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
320 } else if (keywords2.InList(wordBuffer)) {
321 styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
322 } else {
323 styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
324 }
325 // No need to Reset Offset
326 // Check for Default Text
327 } else {
328 // Read up to %, Operator or Separator
329 while ((wbo < wbl) &&
330 (wordBuffer[wbo] != '%') &&
331 (!IsBOperator(wordBuffer[wbo])) &&
332 (!IsBSeparator(wordBuffer[wbo]))) {
333 wbo++;
334 }
335 // Colorize Default Text
336 styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT);
337 // Reset Offset to re-process remainder of word
338 offset -= (wbl - wbo);
339 }
340 }
341 // Check for Argument (%n), Environment Variable (%x...%) or Local Variable (%%a)
342 } else if (wordBuffer[0] == '%') {
343 // Colorize Default Text
344 styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT);
345 wbo++;
346 // Search to end of word for second % (can be a long path)
347 while ((wbo < wbl) &&
348 (wordBuffer[wbo] != '%') &&
349 (!IsBOperator(wordBuffer[wbo])) &&
350 (!IsBSeparator(wordBuffer[wbo]))) {
351 wbo++;
352 }
353 // Check for Argument (%n)
354 if ((Is0To9(wordBuffer[1])) &&
355 (wordBuffer[wbo] != '%')) {
356 // Check for External Command / Program
357 if (cmdLoc == offset - wbl) {
358 cmdLoc = offset - (wbl - 2);
359 }
360 // Colorize Argument
361 styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_IDENTIFIER);
362 // Reset Offset to re-process remainder of word
363 offset -= (wbl - 2);
364 // Check for Environment Variable (%x...%)
365 } else if ((wordBuffer[1] != '%') &&
366 (wordBuffer[wbo] == '%')) {
367 wbo++;
368 // Check for External Command / Program
369 if (cmdLoc == offset - wbl) {
370 cmdLoc = offset - (wbl - wbo);
371 }
372 // Colorize Environment Variable
373 styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER);
374 // Reset Offset to re-process remainder of word
375 offset -= (wbl - wbo);
376 // Check for Local Variable (%%a)
377 } else if (
378 (wbl > 2) &&
379 (wordBuffer[1] == '%') &&
380 (wordBuffer[2] != '%') &&
381 (!IsBOperator(wordBuffer[2])) &&
382 (!IsBSeparator(wordBuffer[2]))) {
383 // Check for External Command / Program
384 if (cmdLoc == offset - wbl) {
385 cmdLoc = offset - (wbl - 3);
386 }
387 // Colorize Local Variable
388 styler.ColourTo(startLine + offset - 1 - (wbl - 3), SCE_BAT_IDENTIFIER);
389 // Reset Offset to re-process remainder of word
390 offset -= (wbl - 3);
391 }
392 // Check for Operator
393 } else if (IsBOperator(wordBuffer[0])) {
394 // Colorize Default Text
395 styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT);
396 // Check for Comparison Operator
397 if ((wordBuffer[0] == '=') && (wordBuffer[1] == '=')) {
398 // Identify External Command / Program Location for IF
399 cmdLoc = offset;
400 // Skip next spaces
401 while ((cmdLoc < lengthLine) &&
402 (isspacechar(lineBuffer[cmdLoc]))) {
403 cmdLoc++;
404 }
405 // Colorize Comparison Operator
406 styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_OPERATOR);
407 // Reset Offset to re-process remainder of word
408 offset -= (wbl - 2);
409 // Check for Pipe Operator
410 } else if (wordBuffer[0] == '|') {
411 // Reset External Command / Program Location
412 cmdLoc = offset - wbl + 1;
413 // Skip next spaces
414 while ((cmdLoc < lengthLine) &&
415 (isspacechar(lineBuffer[cmdLoc]))) {
416 cmdLoc++;
417 }
418 // Colorize Pipe Operator
419 styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR);
420 // Reset Offset to re-process remainder of word
421 offset -= (wbl - 1);
422 // Check for Other Operator
423 } else {
424 // Check for > Operator
425 if (wordBuffer[0] == '>') {
426 // Turn Keyword and External Command / Program checking back on
427 continueProcessing = true;
428 }
429 // Colorize Other Operator
430 styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR);
431 // Reset Offset to re-process remainder of word
432 offset -= (wbl - 1);
433 }
434 // Check for Default Text
435 } else {
436 // Read up to %, Operator or Separator
437 while ((wbo < wbl) &&
438 (wordBuffer[wbo] != '%') &&
439 (!IsBOperator(wordBuffer[wbo])) &&
440 (!IsBSeparator(wordBuffer[wbo]))) {
441 wbo++;
442 }
443 // Colorize Default Text
444 styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT);
445 // Reset Offset to re-process remainder of word
446 offset -= (wbl - wbo);
447 }
448 // Skip next spaces - nothing happens if Offset was Reset
449 while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
450 offset++;
451 }
452 }
453 // Colorize Default Text for remainder of line - currently not lexed
454 styler.ColourTo(endPos, SCE_BAT_DEFAULT);
455 }
456
457 static void ColouriseBatchDoc(
458 unsigned int startPos,
459 int length,
460 int /*initStyle*/,
461 WordList *keywordlists[],
462 Accessor &styler) {
463
464 char lineBuffer[1024];
465
466 styler.StartAt(startPos);
467 styler.StartSegment(startPos);
468 unsigned int linePos = 0;
469 unsigned int startLine = startPos;
470 for (unsigned int i = startPos; i < startPos + length; i++) {
471 lineBuffer[linePos++] = styler[i];
472 if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
473 // End of line (or of line buffer) met, colourise it
474 lineBuffer[linePos] = '\0';
475 ColouriseBatchLine(lineBuffer, linePos, startLine, i, keywordlists, styler);
476 linePos = 0;
477 startLine = i + 1;
478 }
479 }
480 if (linePos > 0) { // Last line does not have ending characters
481 lineBuffer[linePos] = '\0';
482 ColouriseBatchLine(lineBuffer, linePos, startLine, startPos + length - 1,
483 keywordlists, styler);
484 }
485 }
486
487 static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {
488 // It is needed to remember the current state to recognize starting
489 // comment lines before the first "diff " or "--- ". If a real
490 // difference starts then each line starting with ' ' is a whitespace
491 // otherwise it is considered a comment (Only in..., Binary file...)
492 if (0 == strncmp(lineBuffer, "diff ", 5)) {
493 styler.ColourTo(endLine, SCE_DIFF_COMMAND);
494 } else if (0 == strncmp(lineBuffer, "--- ", 4)) {
495 // In a context diff, --- appears in both the header and the position markers
496 if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
497 styler.ColourTo(endLine, SCE_DIFF_POSITION);
498 else
499 styler.ColourTo(endLine, SCE_DIFF_HEADER);
500 } else if (0 == strncmp(lineBuffer, "+++ ", 4)) {
501 // I don't know of any diff where "+++ " is a position marker, but for
502 // consistency, do the same as with "--- " and "*** ".
503 if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
504 styler.ColourTo(endLine, SCE_DIFF_POSITION);
505 else
506 styler.ColourTo(endLine, SCE_DIFF_HEADER);
507 } else if (0 == strncmp(lineBuffer, "====", 4)) { // For p4's diff
508 styler.ColourTo(endLine, SCE_DIFF_HEADER);
509 } else if (0 == strncmp(lineBuffer, "***", 3)) {
510 // In a context diff, *** appears in both the header and the position markers.
511 // Also ******** is a chunk header, but here it's treated as part of the
512 // position marker since there is no separate style for a chunk header.
513 if (lineBuffer[3] == ' ' && atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
514 styler.ColourTo(endLine, SCE_DIFF_POSITION);
515 else if (lineBuffer[3] == '*')
516 styler.ColourTo(endLine, SCE_DIFF_POSITION);
517 else
518 styler.ColourTo(endLine, SCE_DIFF_HEADER);
519 } else if (0 == strncmp(lineBuffer, "? ", 2)) { // For difflib
520 styler.ColourTo(endLine, SCE_DIFF_HEADER);
521 } else if (lineBuffer[0] == '@') {
522 styler.ColourTo(endLine, SCE_DIFF_POSITION);
523 } else if (lineBuffer[0] >= '0' && lineBuffer[0] <= '9') {
524 styler.ColourTo(endLine, SCE_DIFF_POSITION);
525 } else if (lineBuffer[0] == '-' || lineBuffer[0] == '<') {
526 styler.ColourTo(endLine, SCE_DIFF_DELETED);
527 } else if (lineBuffer[0] == '+' || lineBuffer[0] == '>') {
528 styler.ColourTo(endLine, SCE_DIFF_ADDED);
529 } else if (lineBuffer[0] != ' ') {
530 styler.ColourTo(endLine, SCE_DIFF_COMMENT);
531 } else {
532 styler.ColourTo(endLine, SCE_DIFF_DEFAULT);
533 }
534 }
535
536 static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
537 char lineBuffer[1024];
538 styler.StartAt(startPos);
539 styler.StartSegment(startPos);
540 unsigned int linePos = 0;
541 for (unsigned int i = startPos; i < startPos + length; i++) {
542 lineBuffer[linePos++] = styler[i];
543 if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
544 // End of line (or of line buffer) met, colourise it
545 lineBuffer[linePos] = '\0';
546 ColouriseDiffLine(lineBuffer, i, styler);
547 linePos = 0;
548 }
549 }
550 if (linePos > 0) { // Last line does not have ending characters
551 ColouriseDiffLine(lineBuffer, startPos + length - 1, styler);
552 }
553 }
554
555 static void FoldDiffDoc(unsigned int startPos, int length, int, WordList*[], Accessor &styler) {
556 int curLine = styler.GetLine(startPos);
557 int prevLevel = SC_FOLDLEVELBASE;
558 if (curLine > 0)
559 prevLevel = styler.LevelAt(curLine-1);
560
561 int curLineStart = styler.LineStart(curLine);
562 do {
563 int nextLevel = prevLevel;
564 if (prevLevel & SC_FOLDLEVELHEADERFLAG)
565 nextLevel = (prevLevel & SC_FOLDLEVELNUMBERMASK) + 1;
566
567 int lineType = styler.StyleAt(curLineStart);
568 if (lineType == SCE_DIFF_COMMAND)
569 nextLevel = (SC_FOLDLEVELBASE + 1) | SC_FOLDLEVELHEADERFLAG;
570 else if (lineType == SCE_DIFF_HEADER) {
571 nextLevel = (SC_FOLDLEVELBASE + 2) | SC_FOLDLEVELHEADERFLAG;
572 } else if (lineType == SCE_DIFF_POSITION)
573 nextLevel = (SC_FOLDLEVELBASE + 3) | SC_FOLDLEVELHEADERFLAG;
574
575 if ((nextLevel & SC_FOLDLEVELHEADERFLAG) && (nextLevel == prevLevel))
576 styler.SetLevel(curLine-1, prevLevel & ~SC_FOLDLEVELHEADERFLAG);
577
578 styler.SetLevel(curLine, nextLevel);
579 prevLevel = nextLevel;
580
581 curLineStart = styler.LineStart(++curLine);
582 } while (static_cast<int>(startPos) + length > curLineStart);
583 }
584
585
586 static void ColourisePropsLine(
587 char *lineBuffer,
588 unsigned int lengthLine,
589 unsigned int startLine,
590 unsigned int endPos,
591 Accessor &styler) {
592
593 unsigned int i = 0;
594 while ((i < lengthLine) && isspacechar(lineBuffer[i])) // Skip initial spaces
595 i++;
596 if (i < lengthLine) {
597 if (lineBuffer[i] == '#' || lineBuffer[i] == '!' || lineBuffer[i] == ';') {
598 styler.ColourTo(endPos, SCE_PROPS_COMMENT);
599 } else if (lineBuffer[i] == '[') {
600 styler.ColourTo(endPos, SCE_PROPS_SECTION);
601 } else if (lineBuffer[i] == '@') {
602 styler.ColourTo(startLine + i, SCE_PROPS_DEFVAL);
603 if (lineBuffer[++i] == '=')
604 styler.ColourTo(startLine + i, SCE_PROPS_ASSIGNMENT);
605 styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
606 } else {
607 // Search for the '=' character
608 while ((i < lengthLine) && (lineBuffer[i] != '='))
609 i++;
610 if ((i < lengthLine) && (lineBuffer[i] == '=')) {
611 styler.ColourTo(startLine + i - 1, SCE_PROPS_KEY);
612 styler.ColourTo(startLine + i, SCE_PROPS_ASSIGNMENT);
613 styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
614 } else {
615 styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
616 }
617 }
618 } else {
619 styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
620 }
621 }
622
623 static void ColourisePropsDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
624 char lineBuffer[1024];
625 styler.StartAt(startPos);
626 styler.StartSegment(startPos);
627 unsigned int linePos = 0;
628 unsigned int startLine = startPos;
629 for (unsigned int i = startPos; i < startPos + length; i++) {
630 lineBuffer[linePos++] = styler[i];
631 if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
632 // End of line (or of line buffer) met, colourise it
633 lineBuffer[linePos] = '\0';
634 ColourisePropsLine(lineBuffer, linePos, startLine, i, styler);
635 linePos = 0;
636 startLine = i + 1;
637 }
638 }
639 if (linePos > 0) { // Last line does not have ending characters
640 ColourisePropsLine(lineBuffer, linePos, startLine, startPos + length - 1, styler);
641 }
642 }
643
644 // adaption by ksc, using the "} else {" trick of 1.53
645 // 030721
646 static void FoldPropsDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
647 bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
648
649 unsigned int endPos = startPos + length;
650 int visibleChars = 0;
651 int lineCurrent = styler.GetLine(startPos);
652
653 char chNext = styler[startPos];
654 int styleNext = styler.StyleAt(startPos);
655 bool headerPoint = false;
656 int lev;
657
658 for (unsigned int i = startPos; i < endPos; i++) {
659 char ch = chNext;
660 chNext = styler[i+1];
661
662 int style = styleNext;
663 styleNext = styler.StyleAt(i + 1);
664 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
665
666 if (style == SCE_PROPS_SECTION) {
667 headerPoint = true;
668 }
669
670 if (atEOL) {
671 lev = SC_FOLDLEVELBASE;
672
673 if (lineCurrent > 0) {
674 int levelPrevious = styler.LevelAt(lineCurrent - 1);
675
676 if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
677 lev = SC_FOLDLEVELBASE + 1;
678 } else {
679 lev = levelPrevious & SC_FOLDLEVELNUMBERMASK;
680 }
681 }
682
683 if (headerPoint) {
684 lev = SC_FOLDLEVELBASE;
685 }
686 if (visibleChars == 0 && foldCompact)
687 lev |= SC_FOLDLEVELWHITEFLAG;
688
689 if (headerPoint) {
690 lev |= SC_FOLDLEVELHEADERFLAG;
691 }
692 if (lev != styler.LevelAt(lineCurrent)) {
693 styler.SetLevel(lineCurrent, lev);
694 }
695
696 lineCurrent++;
697 visibleChars = 0;
698 headerPoint = false;
699 }
700 if (!isspacechar(ch))
701 visibleChars++;
702 }
703
704 if (lineCurrent > 0) {
705 int levelPrevious = styler.LevelAt(lineCurrent - 1);
706 if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
707 lev = SC_FOLDLEVELBASE + 1;
708 } else {
709 lev = levelPrevious & SC_FOLDLEVELNUMBERMASK;
710 }
711 } else {
712 lev = SC_FOLDLEVELBASE;
713 }
714 int flagsNext = styler.LevelAt(lineCurrent);
715 styler.SetLevel(lineCurrent, lev | flagsNext & ~SC_FOLDLEVELNUMBERMASK);
716 }
717
718 static void ColouriseMakeLine(
719 char *lineBuffer,
720 unsigned int lengthLine,
721 unsigned int startLine,
722 unsigned int endPos,
723 Accessor &styler) {
724
725 unsigned int i = 0;
726 int lastNonSpace = -1;
727 unsigned int state = SCE_MAKE_DEFAULT;
728 bool bSpecial = false;
729
730 // check for a tab character in column 0 indicating a command
731 bool bCommand = false;
732 if ((lengthLine > 0) && (lineBuffer[0] == '\t'))
733 bCommand = true;
734
735 // Skip initial spaces
736 while ((i < lengthLine) && isspacechar(lineBuffer[i])) {
737 i++;
738 }
739 if (lineBuffer[i] == '#') { // Comment
740 styler.ColourTo(endPos, SCE_MAKE_COMMENT);
741 return;
742 }
743 if (lineBuffer[i] == '!') { // Special directive
744 styler.ColourTo(endPos, SCE_MAKE_PREPROCESSOR);
745 return;
746 }
747 while (i < lengthLine) {
748 if (lineBuffer[i] == '$' && lineBuffer[i + 1] == '(') {
749 styler.ColourTo(startLine + i - 1, state);
750 state = SCE_MAKE_IDENTIFIER;
751 } else if (state == SCE_MAKE_IDENTIFIER && lineBuffer[i] == ')') {
752 styler.ColourTo(startLine + i, state);
753 state = SCE_MAKE_DEFAULT;
754 }
755
756 // skip identifier and target styling if this is a command line
757 if (!bSpecial && !bCommand) {
758 if (lineBuffer[i] == ':') {
759 if (((i + 1) < lengthLine) && (lineBuffer[i + 1] == '=')) {
760 // it's a ':=', so style as an identifier
761 if (lastNonSpace >= 0)
762 styler.ColourTo(startLine + lastNonSpace, SCE_MAKE_IDENTIFIER);
763 styler.ColourTo(startLine + i - 1, SCE_MAKE_DEFAULT);
764 styler.ColourTo(startLine + i + 1, SCE_MAKE_OPERATOR);
765 } else {
766 // We should check that no colouring was made since the beginning of the line,
767 // to avoid colouring stuff like /OUT:file
768 if (lastNonSpace >= 0)
769 styler.ColourTo(startLine + lastNonSpace, SCE_MAKE_TARGET);
770 styler.ColourTo(startLine + i - 1, SCE_MAKE_DEFAULT);
771 styler.ColourTo(startLine + i, SCE_MAKE_OPERATOR);
772 }
773 bSpecial = true; // Only react to the first ':' of the line
774 state = SCE_MAKE_DEFAULT;
775 } else if (lineBuffer[i] == '=') {
776 if (lastNonSpace >= 0)
777 styler.ColourTo(startLine + lastNonSpace, SCE_MAKE_IDENTIFIER);
778 styler.ColourTo(startLine + i - 1, SCE_MAKE_DEFAULT);
779 styler.ColourTo(startLine + i, SCE_MAKE_OPERATOR);
780 bSpecial = true; // Only react to the first '=' of the line
781 state = SCE_MAKE_DEFAULT;
782 }
783 }
784 if (!isspacechar(lineBuffer[i])) {
785 lastNonSpace = i;
786 }
787 i++;
788 }
789 if (state == SCE_MAKE_IDENTIFIER) {
790 styler.ColourTo(endPos, SCE_MAKE_IDEOL); // Error, variable reference not ended
791 } else {
792 styler.ColourTo(endPos, SCE_MAKE_DEFAULT);
793 }
794 }
795
796 static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
797 char lineBuffer[1024];
798 styler.StartAt(startPos);
799 styler.StartSegment(startPos);
800 unsigned int linePos = 0;
801 unsigned int startLine = startPos;
802 for (unsigned int i = startPos; i < startPos + length; i++) {
803 lineBuffer[linePos++] = styler[i];
804 if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
805 // End of line (or of line buffer) met, colourise it
806 lineBuffer[linePos] = '\0';
807 ColouriseMakeLine(lineBuffer, linePos, startLine, i, styler);
808 linePos = 0;
809 startLine = i + 1;
810 }
811 }
812 if (linePos > 0) { // Last line does not have ending characters
813 ColouriseMakeLine(lineBuffer, linePos, startLine, startPos + length - 1, styler);
814 }
815 }
816
817 static bool strstart(const char *haystack, const char *needle) {
818 return strncmp(haystack, needle, strlen(needle)) == 0;
819 }
820
821 static int RecogniseErrorListLine(const char *lineBuffer, unsigned int lengthLine, int &startValue) {
822 if (lineBuffer[0] == '>') {
823 // Command or return status
824 return SCE_ERR_CMD;
825 } else if (lineBuffer[0] == '<') {
826 // Diff removal, but not interested. Trapped to avoid hitting CTAG cases.
827 return SCE_ERR_DEFAULT;
828 } else if (lineBuffer[0] == '!') {
829 return SCE_ERR_DIFF_CHANGED;
830 } else if (lineBuffer[0] == '+') {
831 if (strstart(lineBuffer, "+++ ")) {
832 return SCE_ERR_DIFF_MESSAGE;
833 } else {
834 return SCE_ERR_DIFF_ADDITION;
835 }
836 } else if (lineBuffer[0] == '-') {
837 if (strstart(lineBuffer, "--- ")) {
838 return SCE_ERR_DIFF_MESSAGE;
839 } else {
840 return SCE_ERR_DIFF_DELETION;
841 }
842 } else if (strstart(lineBuffer, "cf90-")) {
843 // Absoft Pro Fortran 90/95 v8.2 error and/or warning message
844 return SCE_ERR_ABSF;
845 } else if (strstart(lineBuffer, "fortcom:")) {
846 // Intel Fortran Compiler v8.0 error/warning message
847 return SCE_ERR_IFORT;
848 } else if (strstr(lineBuffer, "File \"") && strstr(lineBuffer, ", line ")) {
849 return SCE_ERR_PYTHON;
850 } else if (strstr(lineBuffer, " in ") && strstr(lineBuffer, " on line ")) {
851 return SCE_ERR_PHP;
852 } else if ((strstart(lineBuffer, "Error ") ||
853 strstart(lineBuffer, "Warning ")) &&
854 strstr(lineBuffer, " at (") &&
855 strstr(lineBuffer, ") : ") &&
856 (strstr(lineBuffer, " at (") < strstr(lineBuffer, ") : "))) {
857 // Intel Fortran Compiler error/warning message
858 return SCE_ERR_IFC;
859 } else if (strstart(lineBuffer, "Error ")) {
860 // Borland error message
861 return SCE_ERR_BORLAND;
862 } else if (strstart(lineBuffer, "Warning ")) {
863 // Borland warning message
864 return SCE_ERR_BORLAND;
865 } else if (strstr(lineBuffer, "at line " ) &&
866 (strstr(lineBuffer, "at line " ) < (lineBuffer + lengthLine)) &&
867 strstr(lineBuffer, "file ") &&
868 (strstr(lineBuffer, "file ") < (lineBuffer + lengthLine))) {
869 // Lua 4 error message
870 return SCE_ERR_LUA;
871 } else if (strstr(lineBuffer, " at " ) &&
872 (strstr(lineBuffer, " at " ) < (lineBuffer + lengthLine)) &&
873 strstr(lineBuffer, " line ") &&
874 (strstr(lineBuffer, " line ") < (lineBuffer + lengthLine)) &&
875 (strstr(lineBuffer, " at " ) < (strstr(lineBuffer, " line ")))) {
876 // perl error message
877 return SCE_ERR_PERL;
878 } else if ((memcmp(lineBuffer, " at ", 6) == 0) &&
879 strstr(lineBuffer, ":line ")) {
880 // A .NET traceback
881 return SCE_ERR_NET;
882 } else if (strstart(lineBuffer, "Line ") &&
883 strstr(lineBuffer, ", file ")) {
884 // Essential Lahey Fortran error message
885 return SCE_ERR_ELF;
886 } else if (strstart(lineBuffer, "line ") &&
887 strstr(lineBuffer, " column ")) {
888 // HTML tidy style: line 42 column 1
889 return SCE_ERR_TIDY;
890 } else if (strstart(lineBuffer, "\tat ") &&
891 strstr(lineBuffer, "(") &&
892 strstr(lineBuffer, ".java:")) {
893 // Java stack back trace
894 return SCE_ERR_JAVA_STACK;
895 } else {
896 // Look for one of the following formats:
897 // GCC: <filename>:<line>:<message>
898 // Microsoft: <filename>(<line>) :<message>
899 // Common: <filename>(<line>): warning|error|note|remark|catastrophic|fatal
900 // Common: <filename>(<line>) warning|error|note|remark|catastrophic|fatal
901 // Microsoft: <filename>(<line>,<column>)<message>
902 // CTags: \t<message>
903 // Lua 5 traceback: \t<filename>:<line>:<message>
904 // Lua 5.1: <exe>: <filename>:<line>:<message>
905 bool initialTab = (lineBuffer[0] == '\t');
906 bool initialColonPart = false;
907 enum { stInitial,
908 stGccStart, stGccDigit, stGcc,
909 stMsStart, stMsDigit, stMsBracket, stMsVc, stMsDigitComma, stMsDotNet,
910 stCtagsStart, stCtagsStartString, stCtagsStringDollar, stCtags,
911 stUnrecognized
912 } state = stInitial;
913 for (unsigned int i = 0; i < lengthLine; i++) {
914 char ch = lineBuffer[i];
915 char chNext = ' ';
916 if ((i + 1) < lengthLine)
917 chNext = lineBuffer[i + 1];
918 if (state == stInitial) {
919 if (ch == ':') {
920 // May be GCC, or might be Lua 5 (Lua traceback same but with tab prefix)
921 if ((chNext != '\\') && (chNext != '/') && (chNext != ' ')) {
922 // This check is not completely accurate as may be on
923 // GTK+ with a file name that includes ':'.
924 state = stGccStart;
925 } else if (chNext == ' ') { // indicates a Lua 5.1 error message
926 initialColonPart = true;
927 }
928 } else if ((ch == '(') && Is1To9(chNext) && (!initialTab)) {
929 // May be Microsoft
930 // Check against '0' often removes phone numbers
931 state = stMsStart;
932 } else if ((ch == '\t') && (!initialTab)) {
933 // May be CTags
934 state = stCtagsStart;
935 }
936 } else if (state == stGccStart) { // <filename>:
937 state = Is1To9(ch) ? stGccDigit : stUnrecognized;
938 } else if (state == stGccDigit) { // <filename>:<line>
939 if (ch == ':') {
940 state = stGcc; // :9.*: is GCC
941 startValue = i + 1;
942 break;
943 } else if (!Is0To9(ch)) {
944 state = stUnrecognized;
945 }
946 } else if (state == stMsStart) { // <filename>(
947 state = Is0To9(ch) ? stMsDigit : stUnrecognized;
948 } else if (state == stMsDigit) { // <filename>(<line>
949 if (ch == ',') {
950 state = stMsDigitComma;
951 } else if (ch == ')') {
952 state = stMsBracket;
953 } else if ((ch != ' ') && !Is0To9(ch)) {
954 state = stUnrecognized;
955 }
956 } else if (state == stMsBracket) { // <filename>(<line>)
957 if ((ch == ' ') && (chNext == ':')) {
958 state = stMsVc;
959 } else if ((ch == ':' && chNext == ' ') || (ch == ' ')) {
960 // Possibly Delphi.. don't test against chNext as it's one of the strings below.
961 char word[512];
962 unsigned int j, chPos;
963 unsigned numstep;
964 chPos = 0;
965 if (ch == ' ')
966 numstep = 1; // ch was ' ', handle as if it's a delphi errorline, only add 1 to i.
967 else
968 numstep = 2; // otherwise add 2.
969 for (j = i + numstep; j < lengthLine && isalpha(lineBuffer[j]) && chPos < sizeof(word) - 1; j++)
970 word[chPos++] = lineBuffer[j];
971 word[chPos] = 0;
972 if (!CompareCaseInsensitive(word, "error") || !CompareCaseInsensitive(word, "warning") ||
973 !CompareCaseInsensitive(word, "fatal") || !CompareCaseInsensitive(word, "catastrophic") ||
974 !CompareCaseInsensitive(word, "note") || !CompareCaseInsensitive(word, "remark")) {
975 state = stMsVc;
976 } else
977 state = stUnrecognized;
978 } else {
979 state = stUnrecognized;
980 }
981 } else if (state == stMsDigitComma) { // <filename>(<line>,
982 if (ch == ')') {
983 state = stMsDotNet;
984 break;
985 } else if ((ch != ' ') && !Is0To9(ch)) {
986 state = stUnrecognized;
987 }
988 } else if (state == stCtagsStart) {
989 if ((lineBuffer[i - 1] == '\t') &&
990 ((ch == '/' && lineBuffer[i + 1] == '^') || Is0To9(ch))) {
991 state = stCtags;
992 break;
993 } else if ((ch == '/') && (lineBuffer[i + 1] == '^')) {
994 state = stCtagsStartString;
995 }
996 } else if ((state == stCtagsStartString) && ((lineBuffer[i] == '$') && (lineBuffer[i + 1] == '/'))) {
997 state = stCtagsStringDollar;
998 break;
999 }
1000 }
1001 if (state == stGcc) {
1002 return initialColonPart ? SCE_ERR_LUA : SCE_ERR_GCC;
1003 } else if ((state == stMsVc) || (state == stMsDotNet)) {
1004 return SCE_ERR_MS;
1005 } else if ((state == stCtagsStringDollar) || (state == stCtags)) {
1006 return SCE_ERR_CTAG;
1007 } else {
1008 return SCE_ERR_DEFAULT;
1009 }
1010 }
1011 }
1012
1013 static void ColouriseErrorListLine(
1014 char *lineBuffer,
1015 unsigned int lengthLine,
1016 unsigned int endPos,
1017 Accessor &styler,
1018 bool valueSeparate) {
1019 int startValue = -1;
1020 int style = RecogniseErrorListLine(lineBuffer, lengthLine, startValue);
1021 if (valueSeparate && (startValue >= 0)) {
1022 styler.ColourTo(endPos - (lengthLine - startValue), style);
1023 styler.ColourTo(endPos, SCE_ERR_VALUE);
1024 } else {
1025 styler.ColourTo(endPos, style);
1026 }
1027 }
1028
1029 static void ColouriseErrorListDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
1030 char lineBuffer[10000];
1031 styler.StartAt(startPos);
1032 styler.StartSegment(startPos);
1033 unsigned int linePos = 0;
1034 bool valueSeparate = styler.GetPropertyInt("lexer.errorlist.value.separate", 0) != 0;
1035 for (unsigned int i = startPos; i < startPos + length; i++) {
1036 lineBuffer[linePos++] = styler[i];
1037 if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
1038 // End of line (or of line buffer) met, colourise it
1039 lineBuffer[linePos] = '\0';
1040 ColouriseErrorListLine(lineBuffer, linePos, i, styler, valueSeparate);
1041 linePos = 0;
1042 }
1043 }
1044 if (linePos > 0) { // Last line does not have ending characters
1045 ColouriseErrorListLine(lineBuffer, linePos, startPos + length - 1, styler, valueSeparate);
1046 }
1047 }
1048
1049 static int isSpecial(char s) {
1050 return (s == '\\') || (s == ',') || (s == ';') || (s == '\'') || (s == ' ') ||
1051 (s == '\"') || (s == '`') || (s == '^') || (s == '~');
1052 }
1053
1054 static int isTag(int start, Accessor &styler) {
1055 char s[6];
1056 unsigned int i = 0, e = 1;
1057 while (i < 5 && e) {
1058 s[i] = styler[start + i];
1059 i++;
1060 e = styler[start + i] != '{';
1061 }
1062 s[i] = '\0';
1063 return (strcmp(s, "begin") == 0) || (strcmp(s, "end") == 0);
1064 }
1065
1066 static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
1067 WordList *[], Accessor &styler) {
1068
1069 styler.StartAt(startPos);
1070
1071 int state = initStyle;
1072 char chNext = styler[startPos];
1073 styler.StartSegment(startPos);
1074 int lengthDoc = startPos + length;
1075
1076 for (int i = startPos; i < lengthDoc; i++) {
1077 char ch = chNext;
1078 chNext = styler.SafeGetCharAt(i + 1);
1079
1080 if (styler.IsLeadByte(ch)) {
1081 chNext = styler.SafeGetCharAt(i + 2);
1082 i++;
1083 continue;
1084 }
1085 switch (state) {
1086 case SCE_L_DEFAULT :
1087 switch (ch) {
1088 case '\\' :
1089 styler.ColourTo(i - 1, state);
1090 if (isSpecial(styler[i + 1])) {
1091 styler.ColourTo(i + 1, SCE_L_COMMAND);
1092 i++;
1093 chNext = styler.SafeGetCharAt(i + 1);
1094 } else {
1095 if (isTag(i + 1, styler))
1096 state = SCE_L_TAG;
1097 else
1098 state = SCE_L_COMMAND;
1099 }
1100 break;
1101 case '$' :
1102 styler.ColourTo(i - 1, state);
1103 state = SCE_L_MATH;
1104 if (chNext == '$') {
1105 i++;
1106 chNext = styler.SafeGetCharAt(i + 1);
1107 }
1108 break;
1109 case '%' :
1110 styler.ColourTo(i - 1, state);
1111 state = SCE_L_COMMENT;
1112 break;
1113 }
1114 break;
1115 case SCE_L_COMMAND :
1116 if (chNext == '[' || chNext == '{' || chNext == '}' ||
1117 chNext == ' ' || chNext == '\r' || chNext == '\n') {
1118 styler.ColourTo(i, state);
1119 state = SCE_L_DEFAULT;
1120 i++;
1121 chNext = styler.SafeGetCharAt(i + 1);
1122 }
1123 break;
1124 case SCE_L_TAG :
1125 if (ch == '}') {
1126 styler.ColourTo(i, state);
1127 state = SCE_L_DEFAULT;
1128 }
1129 break;
1130 case SCE_L_MATH :
1131 if (ch == '$') {
1132 if (chNext == '$') {
1133 i++;
1134 chNext = styler.SafeGetCharAt(i + 1);
1135 }
1136 styler.ColourTo(i, state);
1137 state = SCE_L_DEFAULT;
1138 }
1139 break;
1140 case SCE_L_COMMENT :
1141 if (ch == '\r' || ch == '\n') {
1142 styler.ColourTo(i - 1, state);
1143 state = SCE_L_DEFAULT;
1144 }
1145 }
1146 }
1147 styler.ColourTo(lengthDoc-1, state);
1148 }
1149
1150 static const char * const batchWordListDesc[] = {
1151 "Internal Commands",
1152 "External Commands",
1153 0
1154 };
1155
1156 static const char * const emptyWordListDesc[] = {
1157 0
1158 };
1159
1160 static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[],
1161 Accessor &styler) {
1162 // Null language means all style bytes are 0 so just mark the end - no need to fill in.
1163 if (length > 0) {
1164 styler.StartAt(startPos + length - 1);
1165 styler.StartSegment(startPos + length - 1);
1166 styler.ColourTo(startPos + length - 1, 0);
1167 }
1168 }
1169
1170 LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc, "batch", 0, batchWordListDesc);
1171 LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc, "diff", FoldDiffDoc, emptyWordListDesc);
1172 LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc, "props", FoldPropsDoc, emptyWordListDesc);
1173 LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc, "makefile", 0, emptyWordListDesc);
1174 LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc, "errorlist", 0, emptyWordListDesc);
1175 LexerModule lmLatex(SCLEX_LATEX, ColouriseLatexDoc, "latex", 0, emptyWordListDesc);
1176 LexerModule lmNull(SCLEX_NULL, ColouriseNullDoc, "null");