]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexBullant.cxx
1 // SciTE - Scintilla based Text Editor
2 // LexBullant.cxx - lexer for Bullant
12 #include "Scintilla.h"
16 #include "LexAccessor.h"
18 #include "StyleContext.h"
19 #include "CharacterSet.h"
20 #include "LexerModule.h"
23 using namespace Scintilla
;
26 static int classifyWordBullant(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
29 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
30 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
34 char chAttr
= SCE_C_IDENTIFIER
;
35 if (isdigit(s
[0]) || (s
[0] == '.')){
36 chAttr
= SCE_C_NUMBER
;
39 if (keywords
.InList(s
)) {
41 if (strcmp(s
, "end") == 0)
43 else if (strcmp(s
, "method") == 0 ||
44 strcmp(s
, "case") == 0 ||
45 strcmp(s
, "class") == 0 ||
46 strcmp(s
, "debug") == 0 ||
47 strcmp(s
, "test") == 0 ||
48 strcmp(s
, "if") == 0 ||
49 strcmp(s
, "lock") == 0 ||
50 strcmp(s
, "transaction") == 0 ||
51 strcmp(s
, "trap") == 0 ||
52 strcmp(s
, "until") == 0 ||
53 strcmp(s
, "while") == 0)
57 styler
.ColourTo(end
, chAttr
);
61 static void ColouriseBullantDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
63 WordList
&keywords
= *keywordlists
[0];
65 styler
.StartAt(startPos
);
67 bool fold
= styler
.GetPropertyInt("fold") != 0;
68 int lineCurrent
= styler
.GetLine(startPos
);
69 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
70 int levelCurrent
= levelPrev
;
72 int state
= initStyle
;
73 if (state
== SCE_C_STRINGEOL
) // Does not leak onto next line
74 state
= SCE_C_DEFAULT
;
76 char chNext
= styler
[startPos
];
77 unsigned int lengthDoc
= startPos
+ length
;
79 styler
.StartSegment(startPos
);
80 int endFoundThisLine
= 0;
81 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
83 chNext
= styler
.SafeGetCharAt(i
+ 1);
85 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
86 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
87 // Avoid triggering two times on Dos/Win
90 if (state
== SCE_C_STRINGEOL
) {
91 styler
.ColourTo(i
, state
);
92 state
= SCE_C_DEFAULT
;
96 if (visibleChars
== 0)
97 lev
|= SC_FOLDLEVELWHITEFLAG
;
98 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
99 lev
|= SC_FOLDLEVELHEADERFLAG
;
100 styler
.SetLevel(lineCurrent
, lev
);
102 levelPrev
= levelCurrent
;
106 /* int indentBlock = GetLineIndentation(lineCurrent);
109 int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
110 } else if (blockChange==-1) {
111 indentBlock -= indentSize;
114 SetLineIndentation(lineCurrent, indentBlock);
119 if (!(isascii(ch
) && isspace(ch
)))
122 if (styler
.IsLeadByte(ch
)) {
123 chNext
= styler
.SafeGetCharAt(i
+ 2);
129 if (state
== SCE_C_DEFAULT
) {
130 if (iswordstart(ch
)) {
131 styler
.ColourTo(i
-1, state
);
132 state
= SCE_C_IDENTIFIER
;
133 } else if (ch
== '@' && chNext
== 'o') {
134 if ((styler
.SafeGetCharAt(i
+2) =='f') && (styler
.SafeGetCharAt(i
+3) == 'f')) {
135 styler
.ColourTo(i
-1, state
);
136 state
= SCE_C_COMMENT
;
138 } else if (ch
== '#') {
139 styler
.ColourTo(i
-1, state
);
140 state
= SCE_C_COMMENTLINE
;
141 } else if (ch
== '\"') {
142 styler
.ColourTo(i
-1, state
);
143 state
= SCE_C_STRING
;
144 } else if (ch
== '\'') {
145 styler
.ColourTo(i
-1, state
);
146 state
= SCE_C_CHARACTER
;
147 } else if (isoperator(ch
)) {
148 styler
.ColourTo(i
-1, state
);
149 styler
.ColourTo(i
, SCE_C_OPERATOR
);
151 } else if (state
== SCE_C_IDENTIFIER
) {
152 if (!iswordchar(ch
)) {
153 int levelChange
= classifyWordBullant(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
154 state
= SCE_C_DEFAULT
;
155 chNext
= styler
.SafeGetCharAt(i
+ 1);
157 state
= SCE_C_COMMENTLINE
;
158 } else if (ch
== '\"') {
159 state
= SCE_C_STRING
;
160 } else if (ch
== '\'') {
161 state
= SCE_C_CHARACTER
;
162 } else if (isoperator(ch
)) {
163 styler
.ColourTo(i
, SCE_C_OPERATOR
);
165 if (endFoundThisLine
== 0)
166 levelCurrent
+=levelChange
;
167 if (levelChange
== -1)
170 } else if (state
== SCE_C_COMMENT
) {
171 if (ch
== '@' && chNext
== 'o') {
172 if (styler
.SafeGetCharAt(i
+2) == 'n') {
173 styler
.ColourTo(i
+2, state
);
174 state
= SCE_C_DEFAULT
;
178 } else if (state
== SCE_C_COMMENTLINE
) {
179 if (ch
== '\r' || ch
== '\n') {
180 endFoundThisLine
= 0;
181 styler
.ColourTo(i
-1, state
);
182 state
= SCE_C_DEFAULT
;
184 } else if (state
== SCE_C_STRING
) {
186 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
189 chNext
= styler
.SafeGetCharAt(i
+ 1);
191 } else if (ch
== '\"') {
192 styler
.ColourTo(i
, state
);
193 state
= SCE_C_DEFAULT
;
194 } else if (chNext
== '\r' || chNext
== '\n') {
195 endFoundThisLine
= 0;
196 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
197 state
= SCE_C_STRINGEOL
;
199 } else if (state
== SCE_C_CHARACTER
) {
200 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
201 endFoundThisLine
= 0;
202 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
203 state
= SCE_C_STRINGEOL
;
204 } else if (ch
== '\\') {
205 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
208 chNext
= styler
.SafeGetCharAt(i
+ 1);
210 } else if (ch
== '\'') {
211 styler
.ColourTo(i
, state
);
212 state
= SCE_C_DEFAULT
;
217 styler
.ColourTo(lengthDoc
- 1, state
);
219 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
221 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
222 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
223 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
228 static const char * const bullantWordListDesc
[] = {
233 LexerModule
lmBullant(SCLEX_BULLANT
, ColouriseBullantDoc
, "bullant", 0, bullantWordListDesc
);