]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexOthers.cxx
6e576c2c8aa6dc74dfc1b8f1ea561375760b9d5c
[wxWidgets.git] / 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.
5
6 #include <stdlib.h>
7 #include <string.h>
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 #include "Platform.h"
13
14 #include "PropSet.h"
15 #include "Accessor.h"
16 #include "KeyWords.h"
17 #include "Scintilla.h"
18 #include "SciLexer.h"
19
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);
31 } else {
32 styler.ColourTo(endLine, 0);
33 }
34 }
35
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);
45 linePos = 0;
46 }
47 }
48 if (linePos > 0)
49 ColouriseBatchLine(lineBuffer, startPos + length, styler);
50 }
51
52 static void ColourisePropsLine(char *lineBuffer, int lengthLine, int startLine, int endPos, StylingContext &styler) {
53 int i = 0;
54 while (isspace(lineBuffer[i]) && (i < lengthLine)) // Skip initial spaces
55 i++;
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);
65 } else {
66 while (lineBuffer[i] != '=' && (i < lengthLine)) // Search the '=' character
67 i++;
68 if (lineBuffer[i] == '=') {
69 styler.ColourTo(startLine+i-1, 0);
70 styler.ColourTo(startLine+i, 3);
71 styler.ColourTo(endPos, 0);
72 } else {
73 styler.ColourTo(endPos, 0);
74 }
75 }
76 }
77
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') ||
87 styler[i] == '\n' ||
88 (linePos >= sizeof(lineBuffer) - 1)) {
89 lineBuffer[linePos] = '\0';
90 ColourisePropsLine(lineBuffer, linePos, startLine, i, styler);
91 linePos = 0;
92 startLine = i+1;
93 }
94 }
95 if (linePos > 0)
96 ColourisePropsLine(lineBuffer, linePos, startLine, startPos + length, styler);
97 }
98
99 static void ColouriseMakeLine(char *lineBuffer, int lengthLine, int endPos, StylingContext &styler) {
100 int i = 0;
101 while (isspace(lineBuffer[i]) && (i < lengthLine))
102 i++;
103 if (lineBuffer[i] == '#' || lineBuffer[i] == '!') {
104 styler.ColourTo(endPos, 1);
105 } else {
106 styler.ColourTo(endPos, 0);
107 }
108 }
109
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);
119 linePos = 0;
120 }
121 }
122 if (linePos > 0)
123 ColouriseMakeLine(lineBuffer, linePos, startPos + length, styler);
124 }
125
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);
138 } else {
139 // Look for <filename>:<line>:message
140 // Look for <filename>(line)message
141 // Look for <filename>(line,pos)message
142 int state = 0;
143 for (int i = 0; i < lengthLine; i++) {
144 if (state == 0 && lineBuffer[i] == ':' && isdigit(lineBuffer[i + 1])) {
145 state = 1;
146 } else if (state == 0 && lineBuffer[i] == '(') {
147 state = 10;
148 } else if (state == 1 && isdigit(lineBuffer[i])) {
149 state = 2;
150 } else if (state == 2 && lineBuffer[i] == ':') {
151 state = 3;
152 break;
153 } else if (state == 2 && !isdigit(lineBuffer[i])) {
154 state = 99;
155 } else if (state == 10 && isdigit(lineBuffer[i])) {
156 state = 11;
157 } else if (state == 11 && lineBuffer[i] == ',') {
158 state = 14;
159 } else if (state == 11 && lineBuffer[i] == ')') {
160 state = 12;
161 break;
162 } else if (state == 12 && lineBuffer[i] == ':') {
163 state = 13;
164 } else if (state == 14 && lineBuffer[i] == ')') {
165 state = 15;
166 break;
167 } else if (((state == 11) || (state == 14)) && !((lineBuffer[i] == ' ') || isdigit(lineBuffer[i]))) {
168 state = 99;
169 }
170 }
171 if (state == 3) {
172 styler.ColourTo(endPos, 2);
173 } else if ((state == 14) || (state == 15)) {
174 styler.ColourTo(endPos, 3);
175 } else {
176 styler.ColourTo(endPos, 0);
177 }
178 }
179 }
180
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);
190 linePos = 0;
191 }
192 }
193 if (linePos > 0)
194 ColouriseErrorListLine(lineBuffer, linePos, startPos + length, styler);
195 }
196
197 LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc);
198 LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);
199 LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc);
200 LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc);