]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexOthers.cxx
90f41e3bf3bd1686a7172fe2a60d64a12833316f
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 ColourisePropsLine(char *lineBuffer
, int lengthLine
, int startLine
, int endPos
, Accessor
&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
*[], Accessor
&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
, Accessor
&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
*[], Accessor
&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
, Accessor
&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
] == ')') {
161 } else if (state
== 12 && lineBuffer
[i
] == ':') {
163 } else if (state
== 14 && lineBuffer
[i
] == ')') {
166 } else if (((state
== 11) || (state
== 14)) && !((lineBuffer
[i
] == ' ') || isdigit(lineBuffer
[i
]))) {
171 styler
.ColourTo(endPos
, 2);
172 } else if ((state
== 13) || (state
== 14) || (state
== 15)) {
173 styler
.ColourTo(endPos
, 3);
175 styler
.ColourTo(endPos
, 0);
180 static void ColouriseErrorListDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
181 char lineBuffer
[1024];
182 styler
.StartAt(startPos
);
183 styler
.StartSegment(startPos
);
184 unsigned int linePos
= 0;
185 for (unsigned int i
= startPos
; i
<= startPos
+ length
; i
++) {
186 lineBuffer
[linePos
++] = styler
[i
];
187 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
188 ColouriseErrorListLine(lineBuffer
, linePos
, i
, styler
);
193 ColouriseErrorListLine(lineBuffer
, linePos
, startPos
+ length
, styler
);
196 static int isSpecial(char s
) {
198 return (s
== '\\') || (s
== ',') || (s
== ';') || (s
== '\'') || (s
== ' ') ||
199 (s
== '\"') || (s
== '`') || (s
== '^') || (s
== '~');
202 static int isTag(int start
, Accessor
&styler
) {
205 unsigned int i
= 0, e
=1;
207 s
[i
] = styler
[start
+ i
];
209 e
= styler
[start
+ i
] != '{';
212 return (strcmp(s
, "begin") == 0) || (strcmp(s
, "end") == 0);
215 static void ColouriseLatexDoc(unsigned int startPos
, int length
, int initStyle
,
216 WordList
*[], Accessor
&styler
) {
218 styler
.StartAt(startPos
);
220 int state
= initStyle
;
221 char chNext
= styler
[startPos
];
222 styler
.StartSegment(startPos
);
223 int lengthDoc
= startPos
+ length
;
225 for (int i
= startPos
; i
< lengthDoc
; i
++) {
227 chNext
= styler
.SafeGetCharAt(i
+ 1);
229 if (styler
.IsLeadByte(ch
)) {
230 chNext
= styler
.SafeGetCharAt(i
+ 2);
238 styler
.ColourTo(i
- 1, state
);
239 if (isSpecial(styler
[i
+ 1])) {
240 styler
.ColourTo(i
+ 1, SCE_L_COMMAND
);
242 chNext
= styler
.SafeGetCharAt(i
+ 1);
245 if (isTag(i
+1, styler
))
248 state
= SCE_L_COMMAND
;
252 styler
.ColourTo(i
- 1, state
);
256 chNext
= styler
.SafeGetCharAt(i
+ 1);
260 styler
.ColourTo(i
- 1, state
);
261 state
= SCE_L_COMMENT
;
266 if (chNext
== '[' || chNext
== '{' || chNext
== '}' ||
267 chNext
== ' ' || chNext
== '\r' || chNext
== '\n') {
268 styler
.ColourTo(i
, state
);
269 state
= SCE_L_DEFAULT
;
271 chNext
= styler
.SafeGetCharAt(i
+ 1);
276 styler
.ColourTo(i
, state
);
277 state
= SCE_L_DEFAULT
;
284 chNext
= styler
.SafeGetCharAt(i
+ 1);
286 styler
.ColourTo(i
, state
);
287 state
= SCE_L_DEFAULT
;
291 if (ch
== '\r' || ch
== '\n') {
292 styler
.ColourTo(i
- 1, state
);
293 state
= SCE_L_DEFAULT
;
297 styler
.ColourTo(lengthDoc
, state
);
300 LexerModule
lmProps(SCLEX_PROPERTIES
, ColourisePropsDoc
);
301 LexerModule
lmErrorList(SCLEX_ERRORLIST
, ColouriseErrorListDoc
);
302 LexerModule
lmMake(SCLEX_MAKEFILE
, ColouriseMakeDoc
);
303 LexerModule
lmBatch(SCLEX_BATCH
, ColouriseBatchDoc
);
304 LexerModule
lmLatex(SCLEX_LATEX
, ColouriseLatexDoc
);