]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexOthers.cxx
6e576c2c8aa6dc74dfc1b8f1ea561375760b9d5c
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
, StylingContext
&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
*[], StylingContext
&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 ColourisePropsLine(char *lineBuffer
, int lengthLine
, int startLine
, int endPos
, StylingContext
&styler
) {
54 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
)) // Skip initial spaces
56 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!' || lineBuffer
[i
] == ';') {
57 styler
.ColourTo(endPos
, 1);
58 } else if (lineBuffer
[i
] == '[') {
59 styler
.ColourTo(endPos
, 2);
60 } else if (lineBuffer
[i
] == '@') {
61 styler
.ColourTo(startLine
+i
, 4);
62 if (lineBuffer
[++i
] == '=')
63 styler
.ColourTo(startLine
+i
, 3);
64 styler
.ColourTo(endPos
, 0);
66 while (lineBuffer
[i
] != '=' && (i
< lengthLine
)) // Search the '=' character
68 if (lineBuffer
[i
] == '=') {
69 styler
.ColourTo(startLine
+i
-1, 0);
70 styler
.ColourTo(startLine
+i
, 3);
71 styler
.ColourTo(endPos
, 0);
73 styler
.ColourTo(endPos
, 0);
78 static void ColourisePropsDoc(unsigned int startPos
, int length
, int, WordList
*[], StylingContext
&styler
) {
79 char lineBuffer
[1024];
80 styler
.StartAt(startPos
);
81 styler
.StartSegment(startPos
);
82 unsigned int linePos
= 0;
83 int startLine
= startPos
;
84 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
85 lineBuffer
[linePos
++] = styler
[i
];
86 if ((styler
[i
] == '\r' && styler
.SafeGetCharAt(i
+1) != '\n') ||
88 (linePos
>= sizeof(lineBuffer
) - 1)) {
89 lineBuffer
[linePos
] = '\0';
90 ColourisePropsLine(lineBuffer
, linePos
, startLine
, i
, styler
);
96 ColourisePropsLine(lineBuffer
, linePos
, startLine
, startPos
+ length
, styler
);
99 static void ColouriseMakeLine(char *lineBuffer
, int lengthLine
, int endPos
, StylingContext
&styler
) {
101 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
))
103 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!') {
104 styler
.ColourTo(endPos
, 1);
106 styler
.ColourTo(endPos
, 0);
110 static void ColouriseMakeDoc(unsigned int startPos
, int length
, int, WordList
*[], StylingContext
&styler
) {
111 char lineBuffer
[1024];
112 styler
.StartAt(startPos
);
113 styler
.StartSegment(startPos
);
114 unsigned int linePos
= 0;
115 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
116 lineBuffer
[linePos
++] = styler
[i
];
117 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
118 ColouriseMakeLine(lineBuffer
, linePos
, i
, styler
);
123 ColouriseMakeLine(lineBuffer
, linePos
, startPos
+ length
, styler
);
126 static void ColouriseErrorListLine(char *lineBuffer
, int lengthLine
, int endPos
, StylingContext
&styler
) {
127 if (lineBuffer
[0] == '>') {
128 // Command or return status
129 styler
.ColourTo(endPos
, 4);
130 } else if (strstr(lineBuffer
, "File \"") && strstr(lineBuffer
, ", line ")) {
131 styler
.ColourTo(endPos
, 1);
132 } else if (0 == strncmp(lineBuffer
, "Error ", strlen("Error "))) {
133 // Borland error message
134 styler
.ColourTo(endPos
, 5);
135 } else if (0 == strncmp(lineBuffer
, "Warning ", strlen("Warning "))) {
136 // Borland warning message
137 styler
.ColourTo(endPos
, 5);
139 // Look for <filename>:<line>:message
140 // Look for <filename>(line)message
141 // Look for <filename>(line,pos)message
143 for (int i
= 0; i
< lengthLine
; i
++) {
144 if (state
== 0 && lineBuffer
[i
] == ':' && isdigit(lineBuffer
[i
+ 1])) {
146 } else if (state
== 0 && lineBuffer
[i
] == '(') {
148 } else if (state
== 1 && isdigit(lineBuffer
[i
])) {
150 } else if (state
== 2 && lineBuffer
[i
] == ':') {
153 } else if (state
== 2 && !isdigit(lineBuffer
[i
])) {
155 } else if (state
== 10 && isdigit(lineBuffer
[i
])) {
157 } else if (state
== 11 && lineBuffer
[i
] == ',') {
159 } else if (state
== 11 && lineBuffer
[i
] == ')') {
162 } else if (state
== 12 && lineBuffer
[i
] == ':') {
164 } else if (state
== 14 && lineBuffer
[i
] == ')') {
167 } else if (((state
== 11) || (state
== 14)) && !((lineBuffer
[i
] == ' ') || isdigit(lineBuffer
[i
]))) {
172 styler
.ColourTo(endPos
, 2);
173 } else if ((state
== 14) || (state
== 15)) {
174 styler
.ColourTo(endPos
, 3);
176 styler
.ColourTo(endPos
, 0);
181 static void ColouriseErrorListDoc(unsigned int startPos
, int length
, int, WordList
*[], StylingContext
&styler
) {
182 char lineBuffer
[1024];
183 styler
.StartAt(startPos
);
184 styler
.StartSegment(startPos
);
185 unsigned int linePos
= 0;
186 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
187 lineBuffer
[linePos
++] = styler
[i
];
188 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
189 ColouriseErrorListLine(lineBuffer
, linePos
, i
, styler
);
194 ColouriseErrorListLine(lineBuffer
, linePos
, startPos
+ length
, styler
);
197 LexerModule
lmProps(SCLEX_PROPERTIES
, ColourisePropsDoc
);
198 LexerModule
lmErrorList(SCLEX_ERRORLIST
, ColouriseErrorListDoc
);
199 LexerModule
lmMake(SCLEX_MAKEFILE
, ColouriseMakeDoc
);
200 LexerModule
lmBatch(SCLEX_BATCH
, ColouriseBatchDoc
);