]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexBullant.cxx
1 // SciTE - Scintilla based Text Editor
2 // LexBullant.cxx - lexer for Bullant
15 #include "Scintilla.h"
19 using namespace Scintilla
;
22 static int classifyWordBullant(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
24 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
25 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
29 char chAttr
= SCE_C_IDENTIFIER
;
30 if (isdigit(s
[0]) || (s
[0] == '.')){
31 chAttr
= SCE_C_NUMBER
;
34 if (keywords
.InList(s
)) {
36 if (strcmp(s
, "end") == 0)
38 else if (strcmp(s
, "method") == 0 ||
39 strcmp(s
, "case") == 0 ||
40 strcmp(s
, "class") == 0 ||
41 strcmp(s
, "debug") == 0 ||
42 strcmp(s
, "test") == 0 ||
43 strcmp(s
, "if") == 0 ||
44 strcmp(s
, "lock") == 0 ||
45 strcmp(s
, "transaction") == 0 ||
46 strcmp(s
, "trap") == 0 ||
47 strcmp(s
, "until") == 0 ||
48 strcmp(s
, "while") == 0)
52 styler
.ColourTo(end
, chAttr
);
56 static void ColouriseBullantDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
58 WordList
&keywords
= *keywordlists
[0];
60 styler
.StartAt(startPos
);
62 bool fold
= styler
.GetPropertyInt("fold") != 0;
63 int lineCurrent
= styler
.GetLine(startPos
);
64 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
65 int levelCurrent
= levelPrev
;
67 int state
= initStyle
;
68 if (state
== SCE_C_STRINGEOL
) // Does not leak onto next line
69 state
= SCE_C_DEFAULT
;
71 char chNext
= styler
[startPos
];
72 unsigned int lengthDoc
= startPos
+ length
;
74 styler
.StartSegment(startPos
);
75 int endFoundThisLine
= 0;
76 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
78 chNext
= styler
.SafeGetCharAt(i
+ 1);
80 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
81 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
82 // Avoid triggering two times on Dos/Win
85 if (state
== SCE_C_STRINGEOL
) {
86 styler
.ColourTo(i
, state
);
87 state
= SCE_C_DEFAULT
;
91 if (visibleChars
== 0)
92 lev
|= SC_FOLDLEVELWHITEFLAG
;
93 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
94 lev
|= SC_FOLDLEVELHEADERFLAG
;
95 styler
.SetLevel(lineCurrent
, lev
);
97 levelPrev
= levelCurrent
;
101 /* int indentBlock = GetLineIndentation(lineCurrent);
104 int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
105 } else if (blockChange==-1) {
106 indentBlock -= indentSize;
109 SetLineIndentation(lineCurrent, indentBlock);
117 if (styler
.IsLeadByte(ch
)) {
118 chNext
= styler
.SafeGetCharAt(i
+ 2);
124 if (state
== SCE_C_DEFAULT
) {
125 if (iswordstart(ch
)) {
126 styler
.ColourTo(i
-1, state
);
127 state
= SCE_C_IDENTIFIER
;
128 } else if (ch
== '@' && chNext
== 'o') {
129 if ((styler
.SafeGetCharAt(i
+2) =='f') && (styler
.SafeGetCharAt(i
+3) == 'f')) {
130 styler
.ColourTo(i
-1, state
);
131 state
= SCE_C_COMMENT
;
133 } else if (ch
== '#') {
134 styler
.ColourTo(i
-1, state
);
135 state
= SCE_C_COMMENTLINE
;
136 } else if (ch
== '\"') {
137 styler
.ColourTo(i
-1, state
);
138 state
= SCE_C_STRING
;
139 } else if (ch
== '\'') {
140 styler
.ColourTo(i
-1, state
);
141 state
= SCE_C_CHARACTER
;
142 } else if (isoperator(ch
)) {
143 styler
.ColourTo(i
-1, state
);
144 styler
.ColourTo(i
, SCE_C_OPERATOR
);
146 } else if (state
== SCE_C_IDENTIFIER
) {
147 if (!iswordchar(ch
)) {
148 int levelChange
= classifyWordBullant(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
149 state
= SCE_C_DEFAULT
;
150 chNext
= styler
.SafeGetCharAt(i
+ 1);
152 state
= SCE_C_COMMENTLINE
;
153 } else if (ch
== '\"') {
154 state
= SCE_C_STRING
;
155 } else if (ch
== '\'') {
156 state
= SCE_C_CHARACTER
;
157 } else if (isoperator(ch
)) {
158 styler
.ColourTo(i
, SCE_C_OPERATOR
);
160 if (endFoundThisLine
== 0)
161 levelCurrent
+=levelChange
;
162 if (levelChange
== -1)
165 } else if (state
== SCE_C_COMMENT
) {
166 if (ch
== '@' && chNext
== 'o') {
167 if (styler
.SafeGetCharAt(i
+2) == 'n') {
168 styler
.ColourTo(i
+2, state
);
169 state
= SCE_C_DEFAULT
;
173 } else if (state
== SCE_C_COMMENTLINE
) {
174 if (ch
== '\r' || ch
== '\n') {
175 endFoundThisLine
= 0;
176 styler
.ColourTo(i
-1, state
);
177 state
= SCE_C_DEFAULT
;
179 } else if (state
== SCE_C_STRING
) {
181 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
184 chNext
= styler
.SafeGetCharAt(i
+ 1);
186 } else if (ch
== '\"') {
187 styler
.ColourTo(i
, state
);
188 state
= SCE_C_DEFAULT
;
189 } else if (chNext
== '\r' || chNext
== '\n') {
190 endFoundThisLine
= 0;
191 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
192 state
= SCE_C_STRINGEOL
;
194 } else if (state
== SCE_C_CHARACTER
) {
195 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
196 endFoundThisLine
= 0;
197 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
198 state
= SCE_C_STRINGEOL
;
199 } else if (ch
== '\\') {
200 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
203 chNext
= styler
.SafeGetCharAt(i
+ 1);
205 } else if (ch
== '\'') {
206 styler
.ColourTo(i
, state
);
207 state
= SCE_C_DEFAULT
;
212 styler
.ColourTo(lengthDoc
- 1, state
);
214 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
216 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
217 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
218 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
223 static const char * const bullantWordListDesc
[] = {
228 LexerModule
lmBullant(SCLEX_BULLANT
, ColouriseBullantDoc
, "bullant", 0, bullantWordListDesc
);