]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexBullant.cxx
1f76ffcf00189795df47952d5b0b377664fa308e
1 // SciTE - Scintilla based Text Editor
2 // LexBullant.cxx - lexer for Bullant
15 #include "Scintilla.h"
19 static int classifyWordBullant(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
21 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
22 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
26 char chAttr
= SCE_C_IDENTIFIER
;
27 if (isdigit(s
[0]) || (s
[0] == '.')){
28 chAttr
= SCE_C_NUMBER
;
31 if (keywords
.InList(s
)) {
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)
45 if (strcmp(s
, "end") == 0)
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)
61 styler
.ColourTo(end
, chAttr
);
65 static void ColouriseBullantDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
67 WordList
&keywords
= *keywordlists
[0];
69 styler
.StartAt(startPos
);
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
;
76 int state
= initStyle
;
77 if (state
== SCE_C_STRINGEOL
) // Does not leak onto next line
78 state
= SCE_C_DEFAULT
;
80 char chNext
= styler
[startPos
];
81 unsigned int lengthDoc
= startPos
+ length
;
83 // int blockChange = 0;
84 styler
.StartSegment(startPos
);
85 int endFoundThisLine
= 0;
86 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
88 chNext
= styler
.SafeGetCharAt(i
+ 1);
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
95 if (state
== SCE_C_STRINGEOL
) {
96 styler
.ColourTo(i
, state
);
97 state
= SCE_C_DEFAULT
;
101 if (visibleChars
== 0)
102 lev
|= SC_FOLDLEVELWHITEFLAG
;
103 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
104 lev
|= SC_FOLDLEVELHEADERFLAG
;
105 styler
.SetLevel(lineCurrent
, lev
);
107 levelPrev
= levelCurrent
;
111 /* int indentBlock = GetLineIndentation(lineCurrent);
114 int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
115 } else if (blockChange==-1) {
116 indentBlock -= indentSize;
119 SetLineIndentation(lineCurrent, indentBlock);
127 if (styler
.IsLeadByte(ch
)) {
128 chNext
= styler
.SafeGetCharAt(i
+ 2);
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
;
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
);
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);
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
);
170 if (endFoundThisLine
== 0)
171 levelCurrent
+=levelChange
;
172 if (levelChange
== -1)
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
;
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
;
189 } else if (state
== SCE_C_STRING
) {
191 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
194 chNext
= styler
.SafeGetCharAt(i
+ 1);
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
;
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
== '\\') {
213 chNext
= styler
.SafeGetCharAt(i
+ 1);
215 } else if (ch
== '\'') {
216 styler
.ColourTo(i
, state
);
217 state
= SCE_C_DEFAULT
;
222 styler
.ColourTo(lengthDoc
- 1, state
);
224 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
226 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
227 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
228 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
233 LexerModule
lmBullant(SCLEX_BULLANT
, ColouriseBullantDoc
, "bullant");