]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexBullant.cxx
1f76ffcf00189795df47952d5b0b377664fa308e
[wxWidgets.git] / contrib / src / stc / scintilla / src / LexBullant.cxx
1 // SciTE - Scintilla based Text Editor
2 // LexBullant.cxx - lexer for Bullant
3
4 #include <stdlib.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <stdarg.h>
9
10 #include "Platform.h"
11
12 #include "PropSet.h"
13 #include "Accessor.h"
14 #include "KeyWords.h"
15 #include "Scintilla.h"
16 #include "SciLexer.h"
17
18
19 static int classifyWordBullant(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
20 char s[100];
21 for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
22 s[i] = static_cast<char>(tolower(styler[start + i]));
23 s[i + 1] = '\0';
24 }
25 int lev= 0;
26 char chAttr = SCE_C_IDENTIFIER;
27 if (isdigit(s[0]) || (s[0] == '.')){
28 chAttr = SCE_C_NUMBER;
29 }
30 else {
31 if (keywords.InList(s)) {
32 chAttr = SCE_C_WORD;
33 /* if (strcmp(s, "end method") == 0 ||
34 strcmp(s, "end case") == 0 ||
35 strcmp(s, "end class") == 0 ||
36 strcmp(s, "end debug") == 0 ||
37 strcmp(s, "end test") == 0 ||
38 strcmp(s, "end if") == 0 ||
39 strcmp(s, "end lock") == 0 ||
40 strcmp(s, "end transaction") == 0 ||
41 strcmp(s, "end trap") == 0 ||
42 strcmp(s, "end until") == 0 ||
43 strcmp(s, "end while") == 0)
44 lev = -1;*/
45 if (strcmp(s, "end") == 0)
46 lev = -1;
47 else if (strcmp(s, "method") == 0 ||
48 strcmp(s, "case") == 0 ||
49 strcmp(s, "class") == 0 ||
50 strcmp(s, "debug") == 0 ||
51 strcmp(s, "test") == 0 ||
52 strcmp(s, "if") == 0 ||
53 strcmp(s, "lock") == 0 ||
54 strcmp(s, "transaction") == 0 ||
55 strcmp(s, "trap") == 0 ||
56 strcmp(s, "until") == 0 ||
57 strcmp(s, "while") == 0)
58 lev = 1;
59 }
60 }
61 styler.ColourTo(end, chAttr);
62 return lev;
63 }
64
65 static void ColouriseBullantDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
66 Accessor &styler) {
67 WordList &keywords = *keywordlists[0];
68
69 styler.StartAt(startPos);
70
71 bool fold = styler.GetPropertyInt("fold") != 0;
72 int lineCurrent = styler.GetLine(startPos);
73 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
74 int levelCurrent = levelPrev;
75
76 int state = initStyle;
77 if (state == SCE_C_STRINGEOL) // Does not leak onto next line
78 state = SCE_C_DEFAULT;
79 char chPrev = ' ';
80 char chNext = styler[startPos];
81 unsigned int lengthDoc = startPos + length;
82 int visibleChars = 0;
83 // int blockChange = 0;
84 styler.StartSegment(startPos);
85 int endFoundThisLine = 0;
86 for (unsigned int i = startPos; i < lengthDoc; i++) {
87 char ch = chNext;
88 chNext = styler.SafeGetCharAt(i + 1);
89
90 if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
91 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
92 // Avoid triggering two times on Dos/Win
93 // End of line
94 endFoundThisLine = 0;
95 if (state == SCE_C_STRINGEOL) {
96 styler.ColourTo(i, state);
97 state = SCE_C_DEFAULT;
98 }
99 if (fold) {
100 int lev = levelPrev;
101 if (visibleChars == 0)
102 lev |= SC_FOLDLEVELWHITEFLAG;
103 if ((levelCurrent > levelPrev) && (visibleChars > 0))
104 lev |= SC_FOLDLEVELHEADERFLAG;
105 styler.SetLevel(lineCurrent, lev);
106 lineCurrent++;
107 levelPrev = levelCurrent;
108 }
109 visibleChars = 0;
110
111 /* int indentBlock = GetLineIndentation(lineCurrent);
112 if (blockChange==1){
113 lineCurrent++;
114 int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
115 } else if (blockChange==-1) {
116 indentBlock -= indentSize;
117 if (indentBlock < 0)
118 indentBlock = 0;
119 SetLineIndentation(lineCurrent, indentBlock);
120 lineCurrent++;
121 }
122 blockChange=0;
123 */ }
124 if (!isspace(ch))
125 visibleChars++;
126
127 if (styler.IsLeadByte(ch)) {
128 chNext = styler.SafeGetCharAt(i + 2);
129 chPrev = ' ';
130 i += 1;
131 continue;
132 }
133
134 if (state == SCE_C_DEFAULT) {
135 if (iswordstart(ch)) {
136 styler.ColourTo(i-1, state);
137 state = SCE_C_IDENTIFIER;
138 } else if (ch == '@' && chNext == 'o') {
139 if ((styler.SafeGetCharAt(i+2) =='f') && (styler.SafeGetCharAt(i+3) == 'f')) {
140 styler.ColourTo(i-1, state);
141 state = SCE_C_COMMENT;
142 }
143 } else if (ch == '#') {
144 styler.ColourTo(i-1, state);
145 state = SCE_C_COMMENTLINE;
146 } else if (ch == '\"') {
147 styler.ColourTo(i-1, state);
148 state = SCE_C_STRING;
149 } else if (ch == '\'') {
150 styler.ColourTo(i-1, state);
151 state = SCE_C_CHARACTER;
152 } else if (isoperator(ch)) {
153 styler.ColourTo(i-1, state);
154 styler.ColourTo(i, SCE_C_OPERATOR);
155 }
156 } else if (state == SCE_C_IDENTIFIER) {
157 if (!iswordchar(ch)) {
158 int levelChange = classifyWordBullant(styler.GetStartSegment(), i - 1, keywords, styler);
159 state = SCE_C_DEFAULT;
160 chNext = styler.SafeGetCharAt(i + 1);
161 if (ch == '#') {
162 state = SCE_C_COMMENTLINE;
163 } else if (ch == '\"') {
164 state = SCE_C_STRING;
165 } else if (ch == '\'') {
166 state = SCE_C_CHARACTER;
167 } else if (isoperator(ch)) {
168 styler.ColourTo(i, SCE_C_OPERATOR);
169 }
170 if (endFoundThisLine == 0)
171 levelCurrent+=levelChange;
172 if (levelChange == -1)
173 endFoundThisLine=1;
174 }
175 } else if (state == SCE_C_COMMENT) {
176 if (ch == '@' && chNext == 'o') {
177 if (styler.SafeGetCharAt(i+2) == 'n') {
178 styler.ColourTo(i+2, state);
179 state = SCE_C_DEFAULT;
180 i+=2;
181 }
182 }
183 } else if (state == SCE_C_COMMENTLINE) {
184 if (ch == '\r' || ch == '\n') {
185 endFoundThisLine = 0;
186 styler.ColourTo(i-1, state);
187 state = SCE_C_DEFAULT;
188 }
189 } else if (state == SCE_C_STRING) {
190 if (ch == '\\') {
191 if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
192 i++;
193 ch = chNext;
194 chNext = styler.SafeGetCharAt(i + 1);
195 }
196 } else if (ch == '\"') {
197 styler.ColourTo(i, state);
198 state = SCE_C_DEFAULT;
199 } else if (chNext == '\r' || chNext == '\n') {
200 endFoundThisLine = 0;
201 styler.ColourTo(i-1, SCE_C_STRINGEOL);
202 state = SCE_C_STRINGEOL;
203 }
204 } else if (state == SCE_C_CHARACTER) {
205 if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
206 endFoundThisLine = 0;
207 styler.ColourTo(i-1, SCE_C_STRINGEOL);
208 state = SCE_C_STRINGEOL;
209 } else if (ch == '\\') {
210 if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
211 i++;
212 ch = chNext;
213 chNext = styler.SafeGetCharAt(i + 1);
214 }
215 } else if (ch == '\'') {
216 styler.ColourTo(i, state);
217 state = SCE_C_DEFAULT;
218 }
219 }
220 chPrev = ch;
221 }
222 styler.ColourTo(lengthDoc - 1, state);
223
224 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
225 if (fold) {
226 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
227 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
228 styler.SetLevel(lineCurrent, levelPrev | flagsNext);
229
230 }
231 }
232
233 LexerModule lmBullant(SCLEX_BULLANT, ColouriseBullantDoc, "bullant");