]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/KeyWords.cxx
20f67624702b7e97507a666b206cd4286c605aea
1 // SciTE - Scintilla based Text Editor
2 // KeyWords.cxx - colourise for particular languages
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.
17 #include "Scintilla.h"
20 inline bool IsLeadByte(int codePage
, char ch
) {
22 // TODO: support DBCS under GTK+
25 return codePage
&& IsDBCSLeadByteEx(codePage
, ch
);
31 inline bool iswordchar(char ch
) {
32 return isalnum(ch
) || ch
== '.' || ch
== '_';
35 inline bool iswordstart(char ch
) {
36 return isalnum(ch
) || ch
== '_';
39 enum { wsSpace
= 1, wsTab
= 2, wsSpaceTab
= 4, wsInconsistent
=8};
41 static int IndentAmount(StylingContext
&styler
, int line
, int *flags
) {
42 int end
= styler
.Length();
45 // Determines the indentation level of the current line and also checks for consistent
46 // indentation compared to the previous line.
47 // Indentation is judged consistent when the indentation whitespace of each line lines
48 // the same or the indentation of one line is a prefix of the other.
50 int pos
= styler
.LineStart(line
);
51 char ch
= styler
[pos
];
53 bool inPrevPrefix
= line
> 0;
54 int posPrev
= inPrevPrefix
? styler
.LineStart(line
-1) : 0;
55 while ((ch
== ' ' || ch
== '\t') && (pos
< end
)) {
57 char chPrev
= styler
[posPrev
++];
58 if (chPrev
== ' ' || chPrev
== '\t') {
60 spaceFlags
|= wsInconsistent
;
66 spaceFlags
|= wsSpace
;
70 if (spaceFlags
& wsSpace
)
71 spaceFlags
|= wsSpaceTab
;
72 indent
= (indent
/ 8 + 1) * 8;
78 indent
+= SC_FOLDLEVELBASE
;
79 if (isspace(ch
)) // Completely empty line
80 return indent
| SC_FOLDLEVELWHITEFLAG
;
85 inline bool isoperator(char ch
) {
88 // '.' left out as it is used to make up numbers
89 if (ch
== '%' || ch
== '^' || ch
== '&' || ch
== '*' ||
90 ch
== '(' || ch
== ')' || ch
== '-' || ch
== '+' ||
91 ch
== '=' || ch
== '|' || ch
== '{' || ch
== '}' ||
92 ch
== '[' || ch
== ']' || ch
== ':' || ch
== ';' ||
93 ch
== '<' || ch
== '>' || ch
== ',' || ch
== '/' ||
94 ch
== '?' || ch
== '!' || ch
== '.' || ch
== '~')
99 static void classifyWordCpp(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
101 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
102 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
103 s
[i
] = styler
[start
+ i
];
106 char chAttr
= SCE_C_IDENTIFIER
;
108 chAttr
= SCE_C_NUMBER
;
110 if (keywords
.InList(s
))
113 styler
.ColourSegment(start
, end
, chAttr
);
116 static void ColouriseCppDoc(int codePage
, int startPos
, int length
,
117 int initStyle
, WordList
&keywords
, StylingContext
&styler
) {
119 bool fold
= styler
.GetPropSet().GetInt("fold");
120 int lineCurrent
= styler
.GetLine(startPos
);
121 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
122 int levelCurrent
= levelPrev
;
124 int state
= initStyle
;
126 char chNext
= styler
[startPos
];
127 int startSeg
= startPos
;
128 int lengthDoc
= startPos
+ length
;
130 for (unsigned int i
= startPos
; i
<= lengthDoc
; i
++) {
132 chNext
= styler
.SafeGetCharAt(i
+ 1);
134 if ((fold
) && ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n'))) {
137 lev
|= SC_FOLDLEVELWHITEFLAG
;
138 if ((levelCurrent
> levelPrev
) && (visChars
> 0))
139 lev
|= SC_FOLDLEVELHEADERFLAG
;
140 styler
.SetLevel(lineCurrent
, lev
);
143 levelPrev
= levelCurrent
;
148 if (IsLeadByte(codePage
, ch
)) { // dbcs
149 chNext
= styler
.SafeGetCharAt(i
+ 2);
155 if (state
== SCE_C_STRINGEOL
) {
156 if (ch
!= '\r' && ch
!= '\n') {
157 styler
.ColourSegment(startSeg
, i
- 1, state
);
158 state
= SCE_C_DEFAULT
;
162 if (state
== SCE_C_DEFAULT
) {
163 if (iswordstart(ch
)) {
164 styler
.ColourSegment(startSeg
, i
- 1, state
);
167 } else if (ch
== '/' && chNext
== '*') {
168 styler
.ColourSegment(startSeg
, i
- 1, state
);
169 if (styler
.SafeGetCharAt(i
+ 2) == '*')
170 state
= SCE_C_COMMENTDOC
;
172 state
= SCE_C_COMMENT
;
174 } else if (ch
== '/' && chNext
== '/') {
175 styler
.ColourSegment(startSeg
, i
- 1, state
);
176 state
= SCE_C_COMMENTLINE
;
178 } else if (ch
== '\"') {
179 styler
.ColourSegment(startSeg
, i
- 1, state
);
180 state
= SCE_C_STRING
;
182 } else if (ch
== '\'') {
183 styler
.ColourSegment(startSeg
, i
- 1, state
);
184 state
= SCE_C_CHARACTER
;
186 } else if (ch
== '#') {
187 styler
.ColourSegment(startSeg
, i
- 1, state
);
188 state
= SCE_C_PREPROCESSOR
;
190 } else if (isoperator(ch
)) {
191 styler
.ColourSegment(startSeg
, i
- 1, state
);
192 styler
.ColourSegment(i
, i
, SCE_C_OPERATOR
);
194 if ((ch
== '{') || (ch
== '}')) {
195 levelCurrent
+= (ch
== '{') ? 1 : -1;
198 } else if (state
== SCE_C_WORD
) {
199 if (!iswordchar(ch
)) {
200 classifyWordCpp(startSeg
, i
- 1, keywords
, styler
);
201 state
= SCE_C_DEFAULT
;
203 if (ch
== '/' && chNext
== '*') {
204 if (styler
.SafeGetCharAt(i
+ 2) == '*')
205 state
= SCE_C_COMMENTDOC
;
207 state
= SCE_C_COMMENT
;
208 } else if (ch
== '/' && chNext
== '/') {
209 state
= SCE_C_COMMENTLINE
;
210 } else if (ch
== '\"') {
211 state
= SCE_C_STRING
;
212 } else if (ch
== '\'') {
213 state
= SCE_C_CHARACTER
;
214 } else if (ch
== '#') {
215 state
= SCE_C_PREPROCESSOR
;
216 } else if (isoperator(ch
)) {
217 styler
.ColourSegment(startSeg
, i
, SCE_C_OPERATOR
);
219 if ((ch
== '{') || (ch
== '}')) {
220 levelCurrent
+= (ch
== '{') ? 1 : -1;
225 if (state
== SCE_C_PREPROCESSOR
) {
226 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
227 styler
.ColourSegment(startSeg
, i
- 1, state
);
228 state
= SCE_C_DEFAULT
;
231 } else if (state
== SCE_C_COMMENT
) {
232 if (ch
== '/' && chPrev
== '*' && (
233 (i
> startSeg
+ 2) || ((initStyle
== SCE_C_COMMENT
) && (startSeg
== startPos
)))) {
234 styler
.ColourSegment(startSeg
, i
, state
);
235 state
= SCE_C_DEFAULT
;
238 } else if (state
== SCE_C_COMMENTDOC
) {
239 if (ch
== '/' && chPrev
== '*' && (
240 (i
> startSeg
+ 3) || ((initStyle
== SCE_C_COMMENTDOC
) && (startSeg
== startPos
)))) {
241 styler
.ColourSegment(startSeg
, i
, state
);
242 state
= SCE_C_DEFAULT
;
245 } else if (state
== SCE_C_COMMENTLINE
) {
246 if (ch
== '\r' || ch
== '\n') {
247 styler
.ColourSegment(startSeg
, i
- 1, state
);
248 state
= SCE_C_DEFAULT
;
251 } else if (state
== SCE_C_STRING
) {
252 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
253 styler
.ColourSegment(startSeg
, i
- 1, state
);
254 state
= SCE_C_STRINGEOL
;
256 } else if (ch
== '\\') {
257 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
260 chNext
= styler
.SafeGetCharAt(i
+ 1);
262 } else if (ch
== '\"') {
263 styler
.ColourSegment(startSeg
, i
, state
);
264 state
= SCE_C_DEFAULT
;
267 chNext
= styler
.SafeGetCharAt(i
+ 1);
270 } else if (state
== SCE_C_CHARACTER
) {
271 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
272 styler
.ColourSegment(startSeg
, i
- 1, state
);
273 state
= SCE_C_STRINGEOL
;
275 } else if (ch
== '\\') {
276 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
279 chNext
= styler
.SafeGetCharAt(i
+ 1);
281 } else if (ch
== '\'') {
282 styler
.ColourSegment(startSeg
, i
, state
);
283 state
= SCE_C_DEFAULT
;
286 chNext
= styler
.SafeGetCharAt(i
+ 1);
290 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
291 if (ch
== '/' && chNext
== '*') {
292 if (styler
.SafeGetCharAt(i
+ 2) == '*')
293 state
= SCE_C_COMMENTDOC
;
295 state
= SCE_C_COMMENT
;
296 } else if (ch
== '/' && chNext
== '/') {
297 state
= SCE_C_COMMENTLINE
;
298 } else if (ch
== '\"') {
299 state
= SCE_C_STRING
;
300 } else if (ch
== '\'') {
301 state
= SCE_C_CHARACTER
;
302 } else if (ch
== '#') {
303 state
= SCE_C_PREPROCESSOR
;
304 } else if (iswordstart(ch
)) {
306 } else if (isoperator(ch
)) {
307 styler
.ColourSegment(startSeg
, i
, SCE_C_OPERATOR
);
309 if ((ch
== '{') || (ch
== '}')) {
310 levelCurrent
+= (ch
== '{') ? 1 : -1;
317 if (startSeg
< lengthDoc
)
318 styler
.ColourSegment(startSeg
, lengthDoc
- 1, state
);
319 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
321 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
322 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
323 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
328 inline bool isPerlOperator(char ch
) {
331 // '.' left out as it is used to make up numbers
332 if (ch
== '%' || ch
== '^' || ch
== '&' || ch
== '*' || ch
== '\\' ||
333 ch
== '(' || ch
== ')' || ch
== '-' || ch
== '+' ||
334 ch
== '=' || ch
== '|' || ch
== '{' || ch
== '}' ||
335 ch
== '[' || ch
== ']' || ch
== ':' || ch
== ';' ||
336 ch
== '<' || ch
== '>' || ch
== ',' || ch
== '/' ||
337 ch
== '?' || ch
== '!' || ch
== '.' || ch
== '~')
342 static int classifyWordPerl(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
344 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
345 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
346 s
[i
] = styler
[start
+ i
];
349 char chAttr
= SCE_PL_IDENTIFIER
;
351 chAttr
= SCE_PL_NUMBER
;
353 if (keywords
.InList(s
))
354 chAttr
= SCE_PL_WORD
;
356 styler
.ColourSegment(start
, end
, chAttr
);
360 static bool isEndVar(char ch
) {
361 return !isalnum(ch
) && ch
!= '#' && ch
!= '$' &&
362 ch
!= '_' && ch
!= '\'';
365 static bool isMatch(StylingContext
&styler
, int lengthDoc
, int pos
, const char *val
) {
366 if ((pos
+ static_cast<int>(strlen(val
))) >= lengthDoc
) {
370 if (*val
!= styler
[pos
++]) {
378 static bool isOKQuote(char ch
) {
388 static char opposite(char ch
) {
400 static void ColourisePerlDoc(int codePage
, int startPos
, int length
, int initStyle
,
401 WordList
&keywords
, StylingContext
&styler
) {
404 char quoteDown
= 'd';
408 bool preferRE
= true;
409 sooked
[sookedpos
] = '\0';
410 int state
= initStyle
;
411 int lengthDoc
= startPos
+ length
;
412 // If in a long distance lexical state, seek to the beginning to find quote characters
413 if (state
== SCE_PL_HERE
|| state
== SCE_PL_REGEX
||
414 state
== SCE_PL_REGSUBST
|| state
== SCE_PL_LONGQUOTE
) {
415 while ((startPos
> 1) && (styler
.StyleAt(startPos
- 1) == state
)) {
418 state
= SCE_PL_DEFAULT
;
420 styler
.StartAt(startPos
);
422 char chNext
= styler
[startPos
];
423 int startSeg
= startPos
;
424 for (int i
= startPos
; i
<= lengthDoc
; i
++) {
426 chNext
= styler
.SafeGetCharAt(i
+ 1);
427 char chNext2
= styler
.SafeGetCharAt(i
+ 2);
429 if (IsLeadByte(codePage
, ch
)) { // dbcs
430 chNext
= styler
.SafeGetCharAt(i
+ 2);
436 if (state
== SCE_PL_DEFAULT
) {
437 if (iswordstart(ch
)) {
438 styler
.ColourSegment(startSeg
, i
- 1, state
);
439 if (ch
== 's' && !isalnum(chNext
)) {
440 state
= SCE_PL_REGSUBST
;
446 } else if (ch
== 'm' && !isalnum(chNext
)) {
447 state
= SCE_PL_REGEX
;
453 } else if (ch
== 't' && chNext
== 'r' && !isalnum(chNext2
)) {
454 state
= SCE_PL_REGSUBST
;
462 } else if (ch
== 'q' && (chNext
== 'q' || chNext
== 'r' || chNext
== 'w' || chNext
== 'x') && !isalnum(chNext2
)) {
463 state
= SCE_PL_LONGQUOTE
;
476 } else if (ch
== '#') {
477 styler
.ColourSegment(startSeg
, i
- 1, state
);
478 state
= SCE_PL_COMMENTLINE
;
480 } else if (ch
== '\"') {
481 styler
.ColourSegment(startSeg
, i
- 1, state
);
482 state
= SCE_PL_STRING
;
484 } else if (ch
== '\'') {
487 styler
.ColourSegment(i
, i
, state
);
490 styler
.ColourSegment(startSeg
, i
- 1, state
);
491 state
= SCE_PL_CHARACTER
;
494 } else if (ch
== '`') {
495 styler
.ColourSegment(startSeg
, i
- 1, state
);
496 state
= SCE_PL_BACKTICKS
;
498 } else if (ch
== '$') {
500 styler
.ColourSegment(startSeg
, i
- 1, state
);
501 if (isalnum(chNext
) || chNext
== '#' || chNext
== '$' || chNext
== '_') {
502 state
= SCE_PL_SCALAR
;
504 } else if (chNext
!= '{' && chNext
!= '[') {
505 styler
.ColourSegment(i
- 1, i
, SCE_PL_SCALAR
);
511 styler
.ColourSegment(i
, i
, SCE_PL_SCALAR
);
514 } else if (ch
== '@') {
516 styler
.ColourSegment(startSeg
, i
- 1, state
);
517 if (isalpha(chNext
) || chNext
== '#' || chNext
== '$' || chNext
== '_') {
518 state
= SCE_PL_ARRAY
;
520 } else if (chNext
!= '{' && chNext
!= '[') {
521 styler
.ColourSegment(i
- 1, i
, SCE_PL_ARRAY
);
526 styler
.ColourSegment(i
, i
, SCE_PL_ARRAY
);
529 } else if (ch
== '%') {
531 styler
.ColourSegment(startSeg
, i
- 1, state
);
532 if (isalpha(chNext
) || chNext
== '#' || chNext
== '$' || chNext
== '_') {
535 } else if (chNext
!= '{' && chNext
!= '[') {
536 styler
.ColourSegment(i
- 1, i
, SCE_PL_HASH
);
541 styler
.ColourSegment(i
, i
, SCE_PL_HASH
);
544 } else if (ch
== '*') {
545 styler
.ColourSegment(startSeg
, i
- 1, state
);
546 state
= SCE_PL_SYMBOLTABLE
;
548 } else if (ch
== '/' && preferRE
) {
549 styler
.ColourSegment(startSeg
, i
- 1, state
);
550 state
= SCE_PL_REGEX
;
556 } else if (ch
== '<' && chNext
== '<') {
557 styler
.ColourSegment(startSeg
, i
- 1, state
);
565 sooked
[sookedpos
] = '\0';
566 } else if (ch
== '=' && isalpha(chNext
)) {
567 styler
.ColourSegment(startSeg
, i
- 1, state
);
572 sooked
[sookedpos
] = '\0';
573 } else if (isPerlOperator(ch
)) {
574 if (ch
== ')' || ch
== ']')
578 styler
.ColourSegment(startSeg
, i
- 1, state
);
579 styler
.ColourSegment(i
, i
, SCE_PL_OPERATOR
);
582 } else if (state
== SCE_PL_WORD
) {
583 if (!iswordchar(ch
) && ch
!= '\'') { // Archaic Perl has quotes inside names
584 if (isMatch(styler
, lengthDoc
, startSeg
, "__DATA__")) {
585 styler
.ColourSegment(startSeg
, i
, SCE_PL_DATASECTION
);
586 state
= SCE_PL_DATASECTION
;
587 } else if (isMatch(styler
, lengthDoc
, startSeg
, "__END__")) {
588 styler
.ColourSegment(startSeg
, i
, SCE_PL_DATASECTION
);
589 state
= SCE_PL_DATASECTION
;
591 if (classifyWordPerl(startSeg
, i
- 1, keywords
, styler
) == SCE_PL_WORD
)
593 state
= SCE_PL_DEFAULT
;
596 state
= SCE_PL_COMMENTLINE
;
597 } else if (ch
== '\"') {
598 state
= SCE_PL_STRING
;
599 } else if (ch
== '\'') {
600 state
= SCE_PL_CHARACTER
;
601 } else if (ch
== '<' && chNext
== '<') {
606 sooked
[sookedpos
] = '\0';
607 } else if (isPerlOperator(ch
)) {
608 if (ch
== ')' || ch
== ']')
612 styler
.ColourSegment(startSeg
, i
, SCE_PL_OPERATOR
);
613 state
= SCE_PL_DEFAULT
;
619 if (state
== SCE_PL_COMMENTLINE
) {
620 if (ch
== '\r' || ch
== '\n') {
621 styler
.ColourSegment(startSeg
, i
- 1, state
);
622 state
= SCE_PL_DEFAULT
;
625 } else if (state
== SCE_PL_HERE
) {
626 if (isalnum(ch
) && quotes
< 2) {
627 sooked
[sookedpos
++] = ch
;
628 sooked
[sookedpos
] = '\0';
635 if (quotes
> 1 && isMatch(styler
, lengthDoc
, i
, sooked
)) {
636 styler
.ColourSegment(startSeg
, i
+ sookedpos
- 1, SCE_PL_HERE
);
637 state
= SCE_PL_DEFAULT
;
642 } else if (state
== SCE_PL_STRING
) {
644 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
647 chNext
= styler
.SafeGetCharAt(i
+ 1);
649 } else if (ch
== '\"') {
650 styler
.ColourSegment(startSeg
, i
, state
);
651 state
= SCE_PL_DEFAULT
;
654 chNext
= styler
.SafeGetCharAt(i
+ 1);
657 } else if (state
== SCE_PL_CHARACTER
) {
659 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
662 chNext
= styler
.SafeGetCharAt(i
+ 1);
664 } else if (ch
== '\'') {
665 styler
.ColourSegment(startSeg
, i
, state
);
666 state
= SCE_PL_DEFAULT
;
669 chNext
= styler
.SafeGetCharAt(i
+ 1);
672 } else if (state
== SCE_PL_BACKTICKS
) {
674 styler
.ColourSegment(startSeg
, i
, state
);
675 state
= SCE_PL_DEFAULT
;
678 chNext
= styler
.SafeGetCharAt(i
+ 1);
681 } else if (state
== SCE_PL_POD
) {
683 if (isMatch(styler
, lengthDoc
, i
, "=cut")) {
684 styler
.ColourSegment(startSeg
, i
- 1 + 4, state
);
687 state
= SCE_PL_DEFAULT
;
692 } else if (state
== SCE_PL_SCALAR
) {
694 styler
.ColourSegment(startSeg
, i
- 1, state
);
696 state
= SCE_PL_DEFAULT
;
698 } else if (state
== SCE_PL_ARRAY
) {
700 styler
.ColourSegment(startSeg
, i
- 1, state
);
702 state
= SCE_PL_DEFAULT
;
704 } else if (state
== SCE_PL_HASH
) {
706 styler
.ColourSegment(startSeg
, i
- 1, state
);
708 state
= SCE_PL_DEFAULT
;
710 } else if (state
== SCE_PL_SYMBOLTABLE
) {
712 styler
.ColourSegment(startSeg
, i
- 1, state
);
714 state
= SCE_PL_DEFAULT
;
716 } else if (state
== SCE_PL_REF
) {
718 styler
.ColourSegment(startSeg
, i
- 1, state
);
720 state
= SCE_PL_DEFAULT
;
722 } else if (state
== SCE_PL_REGEX
) {
723 if (!quoteUp
&& !isspace(ch
)) {
725 quoteDown
= opposite(ch
);
728 if (ch
== quoteDown
&& chPrev
!= '\\') {
732 if (quoteUp
== quoteDown
) {
736 if (!isalpha(chNext
)) {
738 styler
.ColourSegment(startSeg
, i
, state
);
740 state
= SCE_PL_DEFAULT
;
744 } else if (ch
== quoteUp
&& chPrev
!= '\\') {
746 } else if (!isalpha(chNext
)) {
748 styler
.ColourSegment(startSeg
, i
, state
);
750 state
= SCE_PL_DEFAULT
;
755 } else if (state
== SCE_PL_REGSUBST
) {
756 if (!quoteUp
&& !isspace(ch
)) {
758 quoteDown
= opposite(ch
);
761 if (ch
== quoteDown
&& chPrev
!= '\\') {
766 if (!isalpha(chNext
)) {
768 styler
.ColourSegment(startSeg
, i
, state
);
770 state
= SCE_PL_DEFAULT
;
774 if (quoteUp
== quoteDown
) {
777 } else if (ch
== quoteUp
&& chPrev
!= '\\') {
779 } else if (!isalpha(chNext
)) {
781 styler
.ColourSegment(startSeg
, i
, state
);
783 state
= SCE_PL_DEFAULT
;
788 } else if (state
== SCE_PL_LONGQUOTE
) {
789 if (!quoteDown
&& !isspace(ch
)) {
791 quoteDown
= opposite(quoteUp
);
793 } else if (ch
== quoteDown
) {
798 styler
.ColourSegment(startSeg
, i
, state
);
800 state
= SCE_PL_DEFAULT
;
803 if (quoteUp
== quoteDown
) {
807 } else if (ch
== quoteUp
) {
812 if (state
== SCE_PL_DEFAULT
) { // One of the above succeeded
814 state
= SCE_PL_COMMENTLINE
;
815 } else if (ch
== '\"') {
816 state
= SCE_PL_STRING
;
817 } else if (ch
== '\'') {
818 state
= SCE_PL_CHARACTER
;
819 } else if (iswordstart(ch
)) {
822 } else if (isoperator(ch
)) {
823 styler
.ColourSegment(startSeg
, i
, SCE_PL_OPERATOR
);
830 if (startSeg
< lengthDoc
)
831 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
835 static int classifyWordVB(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
837 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
838 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
839 s
[i
] = tolower(styler
[start
+ i
]);
842 char chAttr
= SCE_C_DEFAULT
;
844 chAttr
= SCE_C_NUMBER
;
846 if (keywords
.InList(s
)) {
848 if (strcmp(s
, "rem") == 0)
849 chAttr
= SCE_C_COMMENTLINE
;
852 styler
.ColourSegment(start
, end
, chAttr
);
853 if (chAttr
== SCE_C_COMMENTLINE
)
854 return SCE_C_COMMENTLINE
;
856 return SCE_C_DEFAULT
;
859 static void ColouriseVBDoc(int codePage
, int startPos
, int length
, int initStyle
,
860 WordList
&keywords
, StylingContext
&styler
) {
861 int state
= initStyle
;
862 char chNext
= styler
[startPos
];
863 int startSeg
= startPos
;
864 int lengthDoc
= startPos
+ length
;
865 for (int i
= startPos
; i
< lengthDoc
; i
++) {
867 chNext
= styler
.SafeGetCharAt(i
+ 1);
869 if (IsLeadByte(codePage
, ch
)) { // dbcs
870 chNext
= styler
.SafeGetCharAt(i
+ 2);
875 if (state
== SCE_C_DEFAULT
) {
876 if (iswordstart(ch
)) {
877 styler
.ColourSegment(startSeg
, i
- 1, state
);
880 } else if (ch
== '\'') {
881 styler
.ColourSegment(startSeg
, i
- 1, state
);
882 state
= SCE_C_COMMENTLINE
;
884 } else if (ch
== '\"') {
885 styler
.ColourSegment(startSeg
, i
- 1, state
);
886 state
= SCE_C_STRING
;
889 } else if (state
== SCE_C_WORD
) {
890 if (!iswordchar(ch
)) {
891 state
= classifyWordVB(startSeg
, i
- 1, keywords
, styler
);
892 if (state
== SCE_C_DEFAULT
) {
895 state
= SCE_C_COMMENTLINE
;
896 } else if (ch
== '\"') {
897 state
= SCE_C_STRING
;
902 if (state
== SCE_C_COMMENTLINE
) {
903 if (ch
== '\r' || ch
== '\n') {
904 styler
.ColourSegment(startSeg
, i
- 1, state
);
905 state
= SCE_C_DEFAULT
;
908 } else if (state
== SCE_C_STRING
) {
909 // VB doubles quotes to preserve them
911 styler
.ColourSegment(startSeg
, i
, state
);
912 state
= SCE_C_DEFAULT
;
915 chNext
= styler
.SafeGetCharAt(i
+ 1);
919 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
921 state
= SCE_C_COMMENTLINE
;
922 } else if (ch
== '\"') {
923 state
= SCE_C_STRING
;
924 } else if (iswordstart(ch
)) {
930 if (startSeg
< lengthDoc
)
931 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
934 static void classifyWordPy(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
, char *prevWord
) {
936 bool wordIsNumber
= isdigit(styler
[start
]);
937 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
938 s
[i
] = styler
[start
+ i
];
941 char chAttr
= SCE_P_IDENTIFIER
;
942 if (0 == strcmp(prevWord
, "class"))
943 chAttr
= SCE_P_CLASSNAME
;
944 else if (0 == strcmp(prevWord
, "def"))
945 chAttr
= SCE_P_DEFNAME
;
946 else if (wordIsNumber
)
947 chAttr
= SCE_P_NUMBER
;
948 else if (keywords
.InList(s
))
950 styler
.ColourSegment(start
, end
, chAttr
);
954 static void ColourisePyDoc(int codePage
, int startPos
, int length
, int initStyle
, WordList
&keywords
, StylingContext
&styler
) {
955 //Platform::DebugPrintf("Python coloured\n");
956 bool fold
= styler
.GetPropSet().GetInt("fold");
957 int whingeLevel
= styler
.GetPropSet().GetInt("tab.timmy.whinge.level");
962 int lineCurrent
= styler
.GetLine(startPos
);
964 // TODO: Need to check previous line for indentation for both folding and bad indentation
965 int indentCurrent
= IndentAmount(styler
, lineCurrent
, &spaceFlags
);
967 int state
= initStyle
& 31;
970 char chNext
= styler
[startPos
];
971 char chNext2
= styler
[startPos
];
972 int startSeg
= startPos
;
973 int lengthDoc
= startPos
+ length
;
974 bool atStartLine
= true;
975 for (int i
= startPos
; i
<= lengthDoc
; i
++) {
978 if (whingeLevel
== 1) {
979 styler
.SetFlags((spaceFlags
& wsInconsistent
) ? 64 : 0, state
);
980 } else if (whingeLevel
== 2) {
981 styler
.SetFlags((spaceFlags
& wsSpaceTab
) ? 64 : 0, state
);
982 } else if (whingeLevel
== 3) {
983 styler
.SetFlags((spaceFlags
& wsSpace
) ? 64 : 0, state
);
984 } else if (whingeLevel
== 4) {
985 styler
.SetFlags((spaceFlags
& wsTab
) ? 64 : 0, state
);
991 chNext
= styler
.SafeGetCharAt(i
+ 1);
992 chNext2
= styler
.SafeGetCharAt(i
+ 2);
994 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
995 if ((state
== SCE_P_DEFAULT
) || (state
== SCE_P_TRIPLE
) || (state
== SCE_P_TRIPLEDOUBLE
)) {
996 // Perform colourisation of white space and triple quoted strings at end of each line to allow
997 // tab marking to work inside white space and triple quoted strings
998 styler
.ColourSegment(startSeg
, i
, state
);
1002 int lev
= indentCurrent
;
1003 int indentNext
= IndentAmount(styler
, lineCurrent
+ 1, &spaceFlags
);
1004 if (!(indentCurrent
& SC_FOLDLEVELWHITEFLAG
)) {
1005 // Only non whitespace lines can be headers
1006 if ((indentCurrent
& SC_FOLDLEVELNUMBERMASK
) < (indentNext
& SC_FOLDLEVELNUMBERMASK
)) {
1007 lev
|= SC_FOLDLEVELHEADERFLAG
;
1010 indentCurrent
= indentNext
;
1012 styler
.SetLevel(lineCurrent
, lev
);
1018 if (IsLeadByte(codePage
, ch
)) { // dbcs
1019 chNext
= styler
.SafeGetCharAt(i
+ 2);
1026 if (state
== SCE_P_DEFAULT
) {
1027 if (iswordstart(ch
)) {
1028 styler
.ColourSegment(startSeg
, i
- 1, state
);
1031 } else if (ch
== '#') {
1032 styler
.ColourSegment(startSeg
, i
- 1, state
);
1033 state
= SCE_P_COMMENTLINE
;
1035 } else if (ch
== '\"') {
1036 styler
.ColourSegment(startSeg
, i
- 1, state
);
1038 if (chNext
== '\"' && chNext2
== '\"') {
1040 state
= SCE_P_TRIPLEDOUBLE
;
1043 chNext
= styler
.SafeGetCharAt(i
+ 1);
1045 state
= SCE_P_STRING
;
1047 } else if (ch
== '\'') {
1048 styler
.ColourSegment(startSeg
, i
- 1, state
);
1050 if (chNext
== '\'' && chNext2
== '\'') {
1052 state
= SCE_P_TRIPLE
;
1055 chNext
= styler
.SafeGetCharAt(i
+ 1);
1057 state
= SCE_P_CHARACTER
;
1059 } else if (isoperator(ch
)) {
1060 styler
.ColourSegment(startSeg
, i
- 1, state
);
1061 styler
.ColourSegment(i
, i
, SCE_P_OPERATOR
);
1064 } else if (state
== SCE_P_WORD
) {
1065 if (!iswordchar(ch
)) {
1066 classifyWordPy(startSeg
, i
- 1, keywords
, styler
, prevWord
);
1067 state
= SCE_P_DEFAULT
;
1070 state
= SCE_P_COMMENTLINE
;
1071 } else if (ch
== '\"') {
1072 if (chNext
== '\"' && chNext2
== '\"') {
1074 state
= SCE_P_TRIPLEDOUBLE
;
1077 chNext
= styler
.SafeGetCharAt(i
+ 1);
1079 state
= SCE_P_STRING
;
1081 } else if (ch
== '\'') {
1082 if (chNext
== '\'' && chNext2
== '\'') {
1084 state
= SCE_P_TRIPLE
;
1087 chNext
= styler
.SafeGetCharAt(i
+ 1);
1089 state
= SCE_P_CHARACTER
;
1091 } else if (isoperator(ch
)) {
1092 styler
.ColourSegment(startSeg
, i
, SCE_P_OPERATOR
);
1097 if (state
== SCE_P_COMMENTLINE
) {
1098 if (ch
== '\r' || ch
== '\n') {
1099 styler
.ColourSegment(startSeg
, i
- 1, state
);
1100 state
= SCE_P_DEFAULT
;
1103 } else if (state
== SCE_P_STRING
) {
1105 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1108 chNext
= styler
.SafeGetCharAt(i
+ 1);
1110 } else if (ch
== '\"') {
1111 styler
.ColourSegment(startSeg
, i
, state
);
1112 state
= SCE_P_DEFAULT
;
1115 } else if (state
== SCE_P_CHARACTER
) {
1117 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1120 chNext
= styler
.SafeGetCharAt(i
+ 1);
1122 } else if (ch
== '\'') {
1123 styler
.ColourSegment(startSeg
, i
, state
);
1124 state
= SCE_P_DEFAULT
;
1127 } else if (state
== SCE_P_TRIPLE
) {
1128 if (ch
== '\'' && chPrev
== '\'' && chPrev2
== '\'') {
1129 styler
.ColourSegment(startSeg
, i
, state
);
1130 state
= SCE_P_DEFAULT
;
1133 } else if (state
== SCE_P_TRIPLEDOUBLE
) {
1134 if (ch
== '\"' && chPrev
== '\"' && chPrev2
== '\"') {
1135 styler
.ColourSegment(startSeg
, i
, state
);
1136 state
= SCE_P_DEFAULT
;
1144 if (startSeg
<= lengthDoc
) {
1145 if (state
== SCE_P_DEFAULT
) {
1146 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1147 } else if (state
== SCE_P_WORD
) {
1148 classifyWordPy(startSeg
, lengthDoc
, keywords
, styler
, prevWord
);
1149 } else if (state
== SCE_P_COMMENTLINE
) {
1150 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1151 } else if (state
== SCE_P_STRING
) {
1152 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1153 } else if (state
== SCE_P_CHARACTER
) {
1154 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1155 } else if (state
== SCE_P_TRIPLE
) {
1156 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1157 } else if (state
== SCE_P_TRIPLEDOUBLE
) {
1158 styler
.ColourSegment(startSeg
, lengthDoc
, state
);
1163 static void ColouriseBatchLine(char *lineBuffer
, int lengthLine
, StylingContext
&styler
) {
1164 if (0 == strncmp(lineBuffer
, "REM", 3)) {
1165 styler
.ColourSegment(0, lengthLine
- 1, 1);
1166 } else if (0 == strncmp(lineBuffer
, "rem", 3)) {
1167 styler
.ColourSegment(0, lengthLine
- 1, 1);
1168 } else if (0 == strncmp(lineBuffer
, "SET", 3)) {
1169 styler
.ColourSegment(0, lengthLine
- 1, 2);
1170 } else if (0 == strncmp(lineBuffer
, "set", 3)) {
1171 styler
.ColourSegment(0, lengthLine
- 1, 2);
1172 } else if (lineBuffer
[0] == ':') {
1173 styler
.ColourSegment(0, lengthLine
- 1, 3);
1175 styler
.ColourSegment(0, lengthLine
- 1, 0);
1179 static void ColouriseBatchDoc(int startPos
, int length
, int, StylingContext
&styler
) {
1180 char lineBuffer
[1024];
1181 unsigned int linePos
= 0;
1182 for (int i
= startPos
; i
< startPos
+ length
; i
++) {
1183 lineBuffer
[linePos
++] = styler
[i
];
1184 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
1185 ColouriseBatchLine(lineBuffer
, linePos
, styler
);
1190 ColouriseBatchLine(lineBuffer
, linePos
, styler
);
1193 enum { eScriptNone
, eScriptJS
, eScriptVBS
, eScriptPython
};
1194 static int segIsScriptingIndicator(StylingContext
&styler
, unsigned int start
, unsigned int end
, int prevValue
) {
1197 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
1198 s
[i
] = tolower(styler
[start
+ i
]);
1201 Platform::DebugPrintf("Scripting indicator [%s]\n", s
);
1202 if (strstr(s
, "vbs"))
1204 if (strstr(s
, "pyth"))
1205 return eScriptPython
;
1206 if (strstr(s
, "javas"))
1208 if (strstr(s
, "jscr"))
1214 static void classifyAttribHTML(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
1215 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.') ||
1216 (styler
[start
] == '-') || (styler
[start
] == '#');
1217 char chAttr
= SCE_H_ATTRIBUTEUNKNOWN
;
1219 chAttr
= SCE_H_NUMBER
;
1223 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
1224 s
[i
] = tolower(styler
[start
+ i
]);
1227 if (keywords
.InList(s
))
1228 chAttr
= SCE_H_ATTRIBUTE
;
1230 styler
.ColourTo(end
, chAttr
);
1233 static int classifyTagHTML(unsigned int start
, unsigned int end
,
1234 WordList
&keywords
, StylingContext
&styler
) {
1236 // Copy after the '<'
1238 for (int cPos
=start
; cPos
<= end
&& i
< 30; cPos
++) {
1239 char ch
= styler
[cPos
];
1241 s
[i
++] = tolower(ch
);
1244 char chAttr
= SCE_H_TAGUNKNOWN
;
1245 if (s
[0] == '!' && s
[1] == '-' && s
[2] == '-') { //Comment
1246 chAttr
= SCE_H_COMMENT
;
1247 } else if (s
[0] == '/') { // Closing tag
1248 if (keywords
.InList(s
+ 1))
1251 if (keywords
.InList(s
)) {
1253 if (0 == strcmp(s
, "script"))
1254 chAttr
= SCE_H_SCRIPT
;
1257 styler
.ColourTo(end
, chAttr
);
1261 static void classifyWordHTJS(unsigned int start
, unsigned int end
,
1262 WordList
&keywords
, StylingContext
&styler
) {
1264 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
1265 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
1266 s
[i
] = styler
[start
+ i
];
1269 char chAttr
= SCE_HJ_WORD
;
1271 chAttr
= SCE_HJ_NUMBER
;
1273 if (keywords
.InList(s
))
1274 chAttr
= SCE_HJ_KEYWORD
;
1276 styler
.ColourTo(end
, chAttr
);
1279 static int classifyWordHTVB(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
1281 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
1282 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
1283 s
[i
] = tolower(styler
[start
+ i
]);
1286 char chAttr
= SCE_HB_IDENTIFIER
;
1288 chAttr
= SCE_HB_NUMBER
;
1290 if (keywords
.InList(s
)) {
1291 chAttr
= SCE_HB_WORD
;
1292 if (strcmp(s
, "rem") == 0)
1293 chAttr
= SCE_HB_COMMENTLINE
;
1296 styler
.ColourTo(end
, chAttr
);
1297 if (chAttr
== SCE_HB_COMMENTLINE
)
1298 return SCE_HB_COMMENTLINE
;
1300 return SCE_HB_DEFAULT
;
1303 static void classifyWordHTPy(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
, char *prevWord
) {
1305 bool wordIsNumber
= isdigit(styler
[start
]);
1306 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
1307 s
[i
] = styler
[start
+ i
];
1310 char chAttr
= SCE_HP_IDENTIFIER
;
1311 if (0 == strcmp(prevWord
, "class"))
1312 chAttr
= SCE_HP_CLASSNAME
;
1313 else if (0 == strcmp(prevWord
, "def"))
1314 chAttr
= SCE_HP_DEFNAME
;
1315 else if (wordIsNumber
)
1316 chAttr
= SCE_HP_NUMBER
;
1317 else if (keywords
.InList(s
))
1318 chAttr
= SCE_HP_WORD
;
1319 styler
.ColourTo(end
, chAttr
);
1320 strcpy(prevWord
, s
);
1323 inline bool ishtmlwordchar(char ch
) {
1324 return isalnum(ch
) || ch
== '.' || ch
== '-' || ch
== '_' || ch
== ':' || ch
== '!' || ch
== '#';
1327 static bool InTagState(int state
) {
1328 return state
== SCE_H_TAG
|| state
== SCE_H_TAGUNKNOWN
||
1329 state
== SCE_H_SCRIPT
||
1330 state
== SCE_H_ATTRIBUTE
|| state
== SCE_H_ATTRIBUTEUNKNOWN
||
1331 state
== SCE_H_NUMBER
|| state
== SCE_H_OTHER
||
1332 state
== SCE_H_DOUBLESTRING
|| state
== SCE_H_SINGLESTRING
;
1335 static bool isLineEnd(char ch
) {
1336 return ch
== '\r' || ch
== '\n';
1339 static void ColouriseHyperTextDoc(int codePage
, int startPos
, int length
,
1340 int initStyle
, WordList
&keywords
, WordList
&keywords2
, WordList
&keywords3
, WordList
&keywords4
,
1341 StylingContext
&styler
) {
1343 styler
.StartAt(startPos
, 63);
1344 bool lastTagWasScript
= false;
1347 int scriptLanguage
= eScriptJS
;
1348 int state
= initStyle
;
1349 // If inside a tag, it may be a script tage, so reread from the start to ensure any language tas are seen
1350 if (InTagState(state
)) {
1351 while ((startPos
> 1) && (InTagState(styler
.StyleAt(startPos
- 1)))) {
1354 state
= SCE_H_DEFAULT
;
1356 styler
.StartAt(startPos
, 63);
1358 int lineState
= eScriptVBS
;
1359 int lineCurrent
= styler
.GetLine(startPos
);
1360 if (lineCurrent
> 0)
1361 lineState
= styler
.GetLineState(lineCurrent
);
1362 int defaultScript
= lineState
&0xff;
1363 int beforeASP
= (lineState
>> 8) &0xff;
1364 int inASP
= (lineState
>> 16) &0xff;
1368 styler
.StartSegment(startPos
);
1369 int lengthDoc
= startPos
+ length
;
1370 for (int i
= startPos
; i
<= lengthDoc
; i
++) {
1371 char ch
= styler
[i
];
1372 char chNext
= styler
.SafeGetCharAt(i
+ 1);
1373 char chNext2
= styler
.SafeGetCharAt(i
+ 2);
1375 if (IsLeadByte(codePage
, ch
)) { // dbcs
1382 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
1383 // New line -> record any line state onto /next/ line
1385 styler
.SetLineState(lineCurrent
,
1386 defaultScript
| (beforeASP
<< 8) | (inASP
<< 16));
1389 // Handle ASP even within other constructs as it is a preprocessor
1390 if ((ch
== '<') && (chNext
== '%')) {
1392 styler
.ColourTo(i
- 1, state
);
1393 if (chNext2
== '@') {
1394 styler
.ColourTo(i
+ 2, SCE_H_ASP
);
1395 state
= SCE_H_ASPAT
;
1398 if (defaultScript
== eScriptVBS
)
1399 state
= SCE_HB_START
;
1400 else if (defaultScript
== eScriptPython
)
1401 state
= SCE_HP_START
;
1403 state
= SCE_HJ_START
;
1404 if (chNext2
== '=') {
1405 styler
.ColourTo(i
+ 2, SCE_H_ASP
);
1408 styler
.ColourTo(i
+ 1, SCE_H_ASP
);
1415 if (inASP
&& (ch
== '%') && (chNext
== '>')) {
1416 if (state
== SCE_H_ASPAT
)
1417 defaultScript
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
-1, defaultScript
);
1418 // Bounce out of any ASP mode
1419 styler
.ColourTo(i
- 1, state
);
1420 //if (state == SCE_H_ASPAT)
1421 // styler.ColourTo(i+1, SCE_H_ASPAT);
1423 styler
.ColourTo(i
+1, SCE_H_ASP
);
1426 beforeASP
= SCE_H_DEFAULT
;
1431 if (state
== SCE_H_DEFAULT
) {
1433 styler
.ColourTo(i
- 1, state
);
1434 state
= SCE_H_TAGUNKNOWN
;
1435 if (chNext
== '?') {
1436 styler
.ColourTo(i
+ 1, SCE_H_XMLSTART
);
1440 } else if (ch
== '&') {
1441 styler
.ColourTo(i
- 1, SCE_H_DEFAULT
);
1442 state
= SCE_H_ENTITY
;
1444 } else if (state
== SCE_H_COMMENT
) {
1445 if ((ch
== '>') && (chPrev
== '-')) {
1446 styler
.ColourTo(i
, state
);
1447 state
= SCE_H_DEFAULT
;
1449 } else if (state
== SCE_H_ENTITY
) {
1451 styler
.ColourTo(i
, state
);
1452 state
= SCE_H_DEFAULT
;
1454 } else if (state
== SCE_H_TAGUNKNOWN
) {
1455 if (!ishtmlwordchar(ch
) && ch
!= '/' && ch
!= '-') {
1456 int eClass
= classifyTagHTML(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
1457 lastTagWasScript
= eClass
== SCE_H_SCRIPT
;
1458 if (lastTagWasScript
) {
1459 scriptLanguage
= eScriptJS
;
1463 styler
.ColourTo(i
, SCE_H_TAG
);
1464 if (lastTagWasScript
) {
1465 if (scriptLanguage
== eScriptVBS
)
1466 state
= SCE_HB_START
;
1467 else if (scriptLanguage
== eScriptPython
)
1468 state
= SCE_HP_START
;
1470 state
= SCE_HJ_START
;
1472 state
= SCE_H_DEFAULT
;
1475 if (eClass
== SCE_H_COMMENT
) {
1476 state
= SCE_H_COMMENT
;
1478 state
= SCE_H_OTHER
;
1482 } else if (state
== SCE_H_ATTRIBUTE
) {
1483 if (!ishtmlwordchar(ch
) && ch
!= '/' && ch
!= '-') {
1484 if (lastTagWasScript
)
1485 scriptLanguage
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
-1, scriptLanguage
);
1486 classifyAttribHTML(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
1488 styler
.ColourTo(i
, SCE_H_TAG
);
1489 if (lastTagWasScript
) {
1490 if (scriptLanguage
== eScriptVBS
)
1491 state
= SCE_HB_START
;
1492 else if (scriptLanguage
== eScriptPython
)
1493 state
= SCE_HP_START
;
1495 state
= SCE_HJ_START
;
1497 state
= SCE_H_DEFAULT
;
1500 state
= SCE_H_OTHER
;
1503 } else if (state
== SCE_H_ASP
) {
1504 if ((ch
== '>') && (chPrev
== '%')) {
1505 styler
.ColourTo(i
, state
);
1506 state
= SCE_H_DEFAULT
;
1508 } else if (state
== SCE_H_ASPAT
) {
1509 if ((ch
== '>') && (chPrev
== '%')) {
1510 styler
.ColourTo(i
, state
);
1511 state
= SCE_H_DEFAULT
;
1513 } else if (state
== SCE_H_OTHER
) {
1515 styler
.ColourTo(i
- 1, state
);
1516 styler
.ColourTo(i
, SCE_H_TAG
);
1517 if (lastTagWasScript
) {
1518 if (scriptLanguage
== eScriptVBS
)
1519 state
= SCE_HB_START
;
1520 else if (scriptLanguage
== eScriptPython
)
1521 state
= SCE_HP_START
;
1523 state
= SCE_HJ_START
;
1525 state
= SCE_H_DEFAULT
;
1527 } else if (ch
== '\"') {
1528 styler
.ColourTo(i
- 1, state
);
1529 state
= SCE_H_DOUBLESTRING
;
1530 } else if (ch
== '\'') {
1531 styler
.ColourTo(i
- 1, state
);
1532 state
= SCE_H_SINGLESTRING
;
1533 } else if (ch
== '/' && chNext
== '>') {
1534 styler
.ColourTo(i
- 1, state
);
1535 styler
.ColourTo(i
+ 1, SCE_H_TAGEND
);
1538 state
= SCE_H_DEFAULT
;
1539 } else if (ch
== '?' && chNext
== '>') {
1540 styler
.ColourTo(i
- 1, state
);
1541 styler
.ColourTo(i
+ 1, SCE_H_XMLEND
);
1544 state
= SCE_H_DEFAULT
;
1545 } else if (ishtmlwordchar(ch
)) {
1546 styler
.ColourTo(i
- 1, state
);
1547 state
= SCE_H_ATTRIBUTE
;
1549 } else if (state
== SCE_H_DOUBLESTRING
) {
1551 if (lastTagWasScript
)
1552 scriptLanguage
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
, scriptLanguage
);
1553 styler
.ColourTo(i
, SCE_H_DOUBLESTRING
);
1554 state
= SCE_H_OTHER
;
1556 } else if (state
== SCE_H_SINGLESTRING
) {
1558 if (lastTagWasScript
)
1559 scriptLanguage
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
, scriptLanguage
);
1560 styler
.ColourTo(i
, SCE_H_SINGLESTRING
);
1561 state
= SCE_H_OTHER
;
1563 } else if (state
== SCE_HJ_DEFAULT
|| state
== SCE_HJ_START
) {
1564 if (iswordstart(ch
)) {
1565 styler
.ColourTo(i
- 1, state
);
1566 state
= SCE_HJ_WORD
;
1567 } else if (ch
== '/' && chNext
== '*') {
1568 styler
.ColourTo(i
- 1, state
);
1570 state
= SCE_HJ_COMMENTDOC
;
1572 state
= SCE_HJ_COMMENT
;
1573 } else if (ch
== '/' && chNext
== '/') {
1574 styler
.ColourTo(i
- 1, state
);
1575 state
= SCE_HJ_COMMENTLINE
;
1576 } else if (ch
== '\"') {
1577 styler
.ColourTo(i
- 1, state
);
1578 state
= SCE_HJ_DOUBLESTRING
;
1579 } else if (ch
== '\'') {
1580 styler
.ColourTo(i
- 1, state
);
1581 state
= SCE_HJ_SINGLESTRING
;
1582 } else if ((ch
== '<') && (chNext
== '/')) {
1583 styler
.ColourTo(i
- 1, state
);
1584 state
= SCE_H_TAGUNKNOWN
;
1585 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1586 styler
.SafeGetCharAt(i
+ 3) == '-') {
1587 styler
.ColourTo(i
- 1, state
);
1588 state
= SCE_HJ_COMMENTLINE
;
1589 } else if (isoperator(ch
)) {
1590 styler
.ColourTo(i
- 1, state
);
1591 styler
.ColourTo(i
, SCE_HJ_SYMBOLS
);
1592 state
= SCE_HJ_DEFAULT
;
1593 } else if ((ch
== ' ') || (ch
== '\t')) {
1594 if (state
== SCE_HJ_START
) {
1595 styler
.ColourTo(i
- 1, state
);
1596 state
= SCE_HJ_DEFAULT
;
1599 } else if (state
== SCE_HJ_WORD
) {
1600 if (!iswordchar(ch
)) {
1601 classifyWordHTJS(styler
.GetStartSegment(), i
- 1, keywords2
, styler
);
1602 //styler.ColourTo(i - 1, eHTJSKeyword);
1603 state
= SCE_HJ_DEFAULT
;
1604 if (ch
== '/' && chNext
== '*') {
1606 state
= SCE_HJ_COMMENTDOC
;
1608 state
= SCE_HJ_COMMENT
;
1609 } else if (ch
== '/' && chNext
== '/') {
1610 state
= SCE_HJ_COMMENTLINE
;
1611 } else if (ch
== '\"') {
1612 state
= SCE_HJ_DOUBLESTRING
;
1613 } else if (ch
== '\'') {
1614 state
= SCE_HJ_SINGLESTRING
;
1615 } else if (isoperator(ch
)) {
1616 styler
.ColourTo(i
, SCE_HJ_SYMBOLS
);
1617 state
= SCE_HJ_DEFAULT
;
1620 } else if (state
== SCE_HJ_COMMENT
) {
1621 if (ch
== '/' && chPrev
== '*') {
1622 state
= SCE_HJ_DEFAULT
;
1623 styler
.ColourTo(i
, SCE_HJ_COMMENT
);
1624 } else if ((ch
== '<') && (chNext
== '/')) {
1625 styler
.ColourTo(i
- 1, state
);
1626 styler
.ColourTo(i
+ 1, SCE_H_TAGEND
);
1629 state
= SCE_H_DEFAULT
;
1631 } else if (state
== SCE_HJ_COMMENTDOC
) {
1632 if (ch
== '/' && chPrev
== '*') {
1633 state
= SCE_HJ_DEFAULT
;
1634 styler
.ColourTo(i
, SCE_HJ_COMMENTDOC
);
1635 } else if ((ch
== '<') && (chNext
== '/')) {
1636 styler
.ColourTo(i
- 1, state
);
1637 styler
.ColourTo(i
+ 1, SCE_H_TAGEND
);
1640 state
= SCE_H_DEFAULT
;
1642 } else if (state
== SCE_HJ_COMMENTLINE
) {
1643 if (ch
== '\r' || ch
== '\n') {
1644 styler
.ColourTo(i
- 1, SCE_HJ_COMMENTLINE
);
1645 state
= SCE_HJ_DEFAULT
;
1646 } else if ((ch
== '<') && (chNext
== '/')) {
1647 // Common to hide end script tag in comment
1648 styler
.ColourTo(i
- 1, SCE_HJ_COMMENTLINE
);
1649 state
= SCE_H_TAGUNKNOWN
;
1651 } else if (state
== SCE_HJ_DOUBLESTRING
) {
1653 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1656 } else if (ch
== '\"') {
1657 styler
.ColourTo(i
, SCE_HJ_DOUBLESTRING
);
1658 state
= SCE_HJ_DEFAULT
;
1661 } else if (isLineEnd(ch
)) {
1662 styler
.ColourTo(i
-1, state
);
1663 state
= SCE_HJ_STRINGEOL
;
1665 } else if (state
== SCE_HJ_SINGLESTRING
) {
1667 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1670 } else if (ch
== '\'') {
1671 styler
.ColourTo(i
, SCE_HJ_SINGLESTRING
);
1672 state
= SCE_HJ_DEFAULT
;
1675 } else if (isLineEnd(ch
)) {
1676 styler
.ColourTo(i
-1, state
);
1677 state
= SCE_HJ_STRINGEOL
;
1679 } else if (state
== SCE_HJ_STRINGEOL
) {
1680 if (!isLineEnd(ch
)) {
1681 styler
.ColourTo(i
- 1, state
);
1682 state
= SCE_HJ_DEFAULT
;
1684 } else if (state
== SCE_HB_DEFAULT
|| state
== SCE_HB_START
) {
1685 if (iswordstart(ch
)) {
1686 styler
.ColourTo(i
- 1, state
);
1687 state
= SCE_HB_WORD
;
1688 } else if (ch
== '\'') {
1689 styler
.ColourTo(i
- 1, state
);
1690 state
= SCE_HB_COMMENTLINE
;
1691 } else if (ch
== '\"') {
1692 styler
.ColourTo(i
- 1, state
);
1693 state
= SCE_HB_STRING
;
1694 } else if ((ch
== '<') && (chNext
== '/')) {
1695 styler
.ColourTo(i
- 1, state
);
1696 state
= SCE_H_TAGUNKNOWN
;
1697 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1698 styler
.SafeGetCharAt(i
+ 3) == '-') {
1699 styler
.ColourTo(i
- 1, state
);
1700 state
= SCE_HB_COMMENTLINE
;
1701 } else if (isoperator(ch
)) {
1702 styler
.ColourTo(i
- 1, state
);
1703 styler
.ColourTo(i
, SCE_HB_DEFAULT
);
1704 state
= SCE_HB_DEFAULT
;
1705 } else if ((ch
== ' ') || (ch
== '\t')) {
1706 if (state
== SCE_HB_START
) {
1707 styler
.ColourTo(i
- 1, state
);
1708 state
= SCE_HB_DEFAULT
;
1711 } else if (state
== SCE_HB_WORD
) {
1712 if (!iswordchar(ch
)) {
1713 state
= classifyWordHTVB(styler
.GetStartSegment(), i
- 1, keywords3
, styler
);
1714 if (state
== SCE_HB_DEFAULT
) {
1716 state
= SCE_HB_STRING
;
1717 } else if (ch
== '\'') {
1718 state
= SCE_HB_COMMENTLINE
;
1719 } else if (isoperator(ch
)) {
1720 styler
.ColourTo(i
, SCE_HB_DEFAULT
);
1721 state
= SCE_HB_DEFAULT
;
1725 } else if (state
== SCE_HB_STRING
) {
1727 styler
.ColourTo(i
, state
);
1728 state
= SCE_HB_DEFAULT
;
1731 } else if (ch
== '\r' || ch
== '\n') {
1732 styler
.ColourTo(i
-1, state
);
1733 state
= SCE_HB_STRINGEOL
;
1735 } else if (state
== SCE_HB_COMMENTLINE
) {
1736 if (ch
== '\r' || ch
== '\n') {
1737 styler
.ColourTo(i
- 1, state
);
1738 state
= SCE_HB_DEFAULT
;
1739 } else if ((ch
== '<') && (chNext
== '/')) {
1740 // Common to hide end script tag in comment
1741 styler
.ColourTo(i
- 1, state
);
1742 state
= SCE_H_TAGUNKNOWN
;
1744 } else if (state
== SCE_HB_STRINGEOL
) {
1745 if (!isLineEnd(ch
)) {
1746 styler
.ColourTo(i
- 1, state
);
1747 state
= SCE_HB_DEFAULT
;
1749 } else if (state
== SCE_HP_DEFAULT
|| state
== SCE_HP_START
) {
1750 if (iswordstart(ch
)) {
1751 styler
.ColourTo(i
- 1, state
);
1752 state
= SCE_HP_WORD
;
1753 } else if ((ch
== '<') && (chNext
== '/')) {
1754 styler
.ColourTo(i
- 1, state
);
1755 state
= SCE_H_TAGUNKNOWN
;
1756 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1757 styler
.SafeGetCharAt(i
+ 3) == '-') {
1758 styler
.ColourTo(i
- 1, state
);
1759 state
= SCE_HP_COMMENTLINE
;
1760 } else if (ch
== '#') {
1761 styler
.ColourTo(i
- 1, state
);
1762 state
= SCE_HP_COMMENTLINE
;
1763 } else if (ch
== '\"') {
1764 styler
.ColourTo(i
- 1, state
);
1765 if (chNext
== '\"' && chNext2
== '\"') {
1767 state
= SCE_HP_TRIPLEDOUBLE
;
1770 chNext
= styler
.SafeGetCharAt(i
+ 1);
1772 state
= SCE_HP_STRING
;
1774 } else if (ch
== '\'') {
1775 styler
.ColourTo(i
- 1, state
);
1776 if (chNext
== '\'' && chNext2
== '\'') {
1778 state
= SCE_HP_TRIPLE
;
1781 chNext
= styler
.SafeGetCharAt(i
+ 1);
1783 state
= SCE_HP_CHARACTER
;
1785 } else if (isoperator(ch
)) {
1786 styler
.ColourTo(i
- 1, state
);
1787 styler
.ColourTo(i
, SCE_HP_OPERATOR
);
1788 } else if ((ch
== ' ') || (ch
== '\t')) {
1789 if (state
== SCE_HP_START
) {
1790 styler
.ColourTo(i
- 1, state
);
1791 state
= SCE_HP_DEFAULT
;
1794 } else if (state
== SCE_HP_WORD
) {
1795 if (!iswordchar(ch
)) {
1796 classifyWordHTPy(styler
.GetStartSegment(), i
- 1, keywords4
, styler
, prevWord
);
1797 state
= SCE_HP_DEFAULT
;
1799 state
= SCE_HP_COMMENTLINE
;
1800 } else if (ch
== '\"') {
1801 if (chNext
== '\"' && chNext2
== '\"') {
1803 state
= SCE_HP_TRIPLEDOUBLE
;
1806 chNext
= styler
.SafeGetCharAt(i
+ 1);
1808 state
= SCE_HP_STRING
;
1810 } else if (ch
== '\'') {
1811 if (chNext
== '\'' && chNext2
== '\'') {
1813 state
= SCE_HP_TRIPLE
;
1816 chNext
= styler
.SafeGetCharAt(i
+ 1);
1818 state
= SCE_HP_CHARACTER
;
1820 } else if (isoperator(ch
)) {
1821 styler
.ColourTo(i
, SCE_HP_OPERATOR
);
1825 if (state
== SCE_HP_COMMENTLINE
) {
1826 if (ch
== '\r' || ch
== '\n') {
1827 styler
.ColourTo(i
- 1, state
);
1828 state
= SCE_HP_DEFAULT
;
1830 } else if (state
== SCE_HP_STRING
) {
1832 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1835 chNext
= styler
.SafeGetCharAt(i
+ 1);
1837 } else if (ch
== '\"') {
1838 styler
.ColourTo(i
, state
);
1839 state
= SCE_HP_DEFAULT
;
1841 } else if (state
== SCE_HP_CHARACTER
) {
1843 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1846 chNext
= styler
.SafeGetCharAt(i
+ 1);
1848 } else if (ch
== '\'') {
1849 styler
.ColourTo(i
, state
);
1850 state
= SCE_HP_DEFAULT
;
1852 } else if (state
== SCE_HP_TRIPLE
) {
1853 if (ch
== '\'' && chPrev
== '\'' && chPrev2
== '\'') {
1854 styler
.ColourTo(i
, state
);
1855 state
= SCE_HP_DEFAULT
;
1857 } else if (state
== SCE_HP_TRIPLEDOUBLE
) {
1858 if (ch
== '\"' && chPrev
== '\"' && chPrev2
== '\"') {
1859 styler
.ColourTo(i
, state
);
1860 state
= SCE_HP_DEFAULT
;
1864 if (state
== SCE_HB_DEFAULT
) { // One of the above succeeded
1866 state
= SCE_HB_STRING
;
1867 } else if (ch
== '\'') {
1868 state
= SCE_HB_COMMENTLINE
;
1869 } else if (iswordstart(ch
)) {
1870 state
= SCE_HB_WORD
;
1871 } else if (isoperator(ch
)) {
1872 styler
.ColourTo(i
, SCE_HB_DEFAULT
);
1875 if (state
== SCE_HJ_DEFAULT
) { // One of the above succeeded
1876 if (ch
== '/' && chNext
== '*') {
1877 if (styler
.SafeGetCharAt(i
+ 2) == '*')
1878 state
= SCE_HJ_COMMENTDOC
;
1880 state
= SCE_HJ_COMMENT
;
1881 } else if (ch
== '/' && chNext
== '/') {
1882 state
= SCE_HJ_COMMENTLINE
;
1883 } else if (ch
== '\"') {
1884 state
= SCE_HJ_DOUBLESTRING
;
1885 } else if (ch
== '\'') {
1886 state
= SCE_HJ_SINGLESTRING
;
1887 } else if (iswordstart(ch
)) {
1888 state
= SCE_HJ_WORD
;
1889 } else if (isoperator(ch
)) {
1890 styler
.ColourTo(i
, SCE_HJ_SYMBOLS
);
1896 styler
.ColourTo(lengthDoc
- 1, state
);
1899 static void ColourisePropsLine(char *lineBuffer
, int lengthLine
, StylingContext
&styler
) {
1901 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
)) // Skip initial spaces
1903 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!' || lineBuffer
[i
] == ';') {
1904 styler
.ColourSegment(0, lengthLine
- 1, 1);
1905 } else if (lineBuffer
[i
] == '[') {
1906 styler
.ColourSegment(0, lengthLine
- 1, 2);
1907 } else if (lineBuffer
[i
] == '@') {
1908 styler
.ColourSegment(0, i
, 4);
1909 if (lineBuffer
[++i
] == '=')
1910 styler
.ColourSegment(i
, i
, 3);
1911 if (++i
< lengthLine
)
1912 styler
.ColourSegment(i
, lengthLine
- 1, 0);
1914 while (lineBuffer
[i
] != '=' && (i
< lengthLine
)) // Search the '=' character
1916 if (lineBuffer
[i
] == '=') {
1917 styler
.ColourSegment(0, i
- 1, 0);
1918 styler
.ColourSegment(i
, i
, 3);
1919 if (++i
< lengthLine
)
1920 styler
.ColourSegment(i
, lengthLine
- 1, 0);
1922 styler
.ColourSegment(0, lengthLine
- 1, 0);
1926 static void ColourisePropsDoc(int startPos
, int length
, int, StylingContext
&styler
) {
1927 char lineBuffer
[1024];
1928 unsigned int linePos
= 0;
1929 for (int i
= startPos
; i
<= startPos
+ length
; i
++) {
1930 lineBuffer
[linePos
++] = styler
[i
];
1931 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
1932 lineBuffer
[linePos
] = '\0';
1933 ColourisePropsLine(lineBuffer
, linePos
, styler
);
1938 ColourisePropsLine(lineBuffer
, linePos
, styler
);
1941 static void ColouriseMakeLine(char *lineBuffer
, int lengthLine
, StylingContext
&styler
) {
1943 while (isspace(lineBuffer
[i
]) && (i
< lengthLine
))
1945 if (lineBuffer
[i
] == '#' || lineBuffer
[i
] == '!') {
1946 styler
.ColourSegment(0, lengthLine
- 1, 1);
1948 styler
.ColourSegment(0, lengthLine
- 1, 0);
1952 static void ColouriseMakeDoc(int startPos
, int length
, int, StylingContext
&styler
) {
1953 char lineBuffer
[1024];
1954 unsigned int linePos
= 0;
1955 for (int i
= startPos
; i
<= startPos
+ length
; i
++) {
1956 lineBuffer
[linePos
++] = styler
[i
];
1957 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
1958 ColouriseMakeLine(lineBuffer
, linePos
, styler
);
1963 ColouriseMakeLine(lineBuffer
, linePos
, styler
);
1966 static void ColouriseErrorListLine(char *lineBuffer
, int lengthLine
, StylingContext
&styler
) {
1967 if (lineBuffer
[0] == '>') {
1968 // Command or return status
1969 styler
.ColourSegment(0, lengthLine
- 1, 4);
1970 } else if (strstr(lineBuffer
, "File \"") && strstr(lineBuffer
, ", line ")) {
1971 styler
.ColourSegment(0, lengthLine
- 1, 1);
1972 } else if (0 == strncmp(lineBuffer
, "Error ", strlen("Error "))) {
1973 // Borland error message
1974 styler
.ColourSegment(0, lengthLine
- 1, 5);
1975 } else if (0 == strncmp(lineBuffer
, "Warning ", strlen("Warning "))) {
1976 // Borland warning message
1977 styler
.ColourSegment(0, lengthLine
- 1, 5);
1979 // Look for <filename>:<line>:message
1980 // Look for <filename>(line)message
1981 // Look for <filename>(line,pos)message
1983 for (int i
= 0; i
< lengthLine
; i
++) {
1984 if (state
== 0 && lineBuffer
[i
] == ':' && isdigit(lineBuffer
[i
+ 1])) {
1986 } else if (state
== 0 && lineBuffer
[i
] == '(') {
1988 } else if (state
== 1 && isdigit(lineBuffer
[i
])) {
1990 } else if (state
== 2 && lineBuffer
[i
] == ':') {
1993 } else if (state
== 2 && !isdigit(lineBuffer
[i
])) {
1995 } else if (state
== 10 && isdigit(lineBuffer
[i
])) {
1997 } else if (state
== 11 && lineBuffer
[i
] == ',') {
1999 } else if (state
== 11 && lineBuffer
[i
] == ')') {
2002 } else if (state
== 12 && lineBuffer
[i
] == ':') {
2004 } else if (state
== 14 && lineBuffer
[i
] == ')') {
2007 } else if (((state
== 11) || (state
== 14)) && !((lineBuffer
[i
] == ' ') || isdigit(lineBuffer
[i
]))) {
2012 styler
.ColourSegment(0, lengthLine
- 1, 2);
2013 } else if ((state
== 14) || (state
== 15)) {
2014 styler
.ColourSegment(0, lengthLine
- 1, 3);
2016 styler
.ColourSegment(0, lengthLine
- 1, 0);
2021 static void ColouriseErrorListDoc(int startPos
, int length
, int, StylingContext
&styler
) {
2022 char lineBuffer
[1024];
2023 unsigned int linePos
= 0;
2024 for (int i
= startPos
; i
<= startPos
+ length
; i
++) {
2025 lineBuffer
[linePos
++] = styler
[i
];
2026 if (styler
[i
] == '\r' || styler
[i
] == '\n' || (linePos
>= sizeof(lineBuffer
) - 1)) {
2027 ColouriseErrorListLine(lineBuffer
, linePos
, styler
);
2032 ColouriseErrorListLine(lineBuffer
, linePos
, styler
);
2035 static void classifyWordSQL(unsigned int start
, unsigned int end
, WordList
&keywords
, StylingContext
&styler
) {
2037 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
2038 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
2039 s
[i
] = toupper(styler
[start
+ i
]);
2042 char chAttr
= SCE_C_IDENTIFIER
;
2044 chAttr
= SCE_C_NUMBER
;
2046 if (keywords
.InList(s
))
2047 chAttr
= SCE_C_WORD
;
2049 styler
.ColourSegment(start
, end
, chAttr
);
2052 static void ColouriseSQLDoc(int codePage
, int startPos
, int length
,
2053 int initStyle
, WordList
&keywords
, StylingContext
&styler
) {
2055 bool fold
= styler
.GetPropSet().GetInt("fold");
2056 int lineCurrent
= styler
.GetLine(startPos
);
2058 int indentCurrent
= 0;
2060 int state
= initStyle
;
2062 char chNext
= styler
[startPos
];
2063 int startSeg
= startPos
;
2064 int lengthDoc
= startPos
+ length
;
2065 bool prevCr
= false;
2066 for (int i
= startPos
; i
<= lengthDoc
; i
++) {
2068 chNext
= styler
.SafeGetCharAt(i
+ 1);
2070 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
2071 indentCurrent
= IndentAmount(styler
, lineCurrent
, &spaceFlags
);
2072 int lev
= indentCurrent
;
2073 if (!(indentCurrent
& SC_FOLDLEVELWHITEFLAG
)) {
2074 // Only non whitespace lines can be headers
2075 int indentNext
= IndentAmount(styler
, lineCurrent
+ 1, &spaceFlags
);
2076 if (indentCurrent
< (indentNext
& ~SC_FOLDLEVELWHITEFLAG
)) {
2077 lev
|= SC_FOLDLEVELHEADERFLAG
;
2081 styler
.SetLevel(lineCurrent
, lev
);
2085 if (IsLeadByte(codePage
, ch
)) { // dbcs
2086 chNext
= styler
.SafeGetCharAt(i
+ 2);
2092 if (state
== SCE_C_DEFAULT
) {
2093 if (iswordstart(ch
)) {
2094 styler
.ColourSegment(startSeg
, i
- 1, state
);
2097 } else if (ch
== '/' && chNext
== '*') {
2098 styler
.ColourSegment(startSeg
, i
- 1, state
);
2099 state
= SCE_C_COMMENT
;
2101 } else if (ch
== '-' && chNext
== '-') {
2102 styler
.ColourSegment(startSeg
, i
- 1, state
);
2103 state
= SCE_C_COMMENTLINE
;
2105 } else if (ch
== '\'') {
2106 styler
.ColourSegment(startSeg
, i
- 1, state
);
2107 state
= SCE_C_STRING
;
2109 } else if (isoperator(ch
)) {
2110 styler
.ColourSegment(startSeg
, i
- 1, state
);
2111 styler
.ColourSegment(i
, i
, SCE_C_OPERATOR
);
2114 } else if (state
== SCE_C_WORD
) {
2115 if (!iswordchar(ch
)) {
2116 classifyWordSQL(startSeg
, i
- 1, keywords
, styler
);
2117 state
= SCE_C_DEFAULT
;
2119 if (ch
== '/' && chNext
== '*') {
2120 state
= SCE_C_COMMENT
;
2121 } else if (ch
== '-' && chNext
== '-') {
2122 state
= SCE_C_COMMENTLINE
;
2123 } else if (ch
== '\'') {
2124 state
= SCE_C_STRING
;
2125 } else if (isoperator(ch
)) {
2126 styler
.ColourSegment(startSeg
, i
, SCE_C_OPERATOR
);
2131 if (state
== SCE_C_COMMENT
) {
2132 if (ch
== '/' && chPrev
== '*' && (
2133 (i
> startSeg
+ 2) || ((initStyle
== SCE_C_COMMENT
) && (startSeg
== startPos
)))) {
2134 state
= SCE_C_DEFAULT
;
2135 styler
.ColourSegment(startSeg
, i
, state
);
2138 } else if (state
== SCE_C_COMMENTLINE
) {
2139 if (ch
== '\r' || ch
== '\n') {
2140 styler
.ColourSegment(startSeg
, i
- 1, state
);
2141 state
= SCE_C_DEFAULT
;
2144 } else if (state
== SCE_C_STRING
) {
2146 if ( chNext
== '\'' ) {
2149 styler
.ColourSegment(startSeg
, i
, state
);
2150 state
= SCE_C_DEFAULT
;
2155 chNext
= styler
.SafeGetCharAt(i
+ 1);
2158 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
2159 if (ch
== '/' && chNext
== '*') {
2160 state
= SCE_C_COMMENT
;
2161 } else if (ch
== '-' && chNext
== '-') {
2162 state
= SCE_C_COMMENTLINE
;
2163 } else if (ch
== '\'') {
2164 state
= SCE_C_STRING
;
2165 } else if (iswordstart(ch
)) {
2167 } else if (isoperator(ch
)) {
2168 styler
.ColourSegment(startSeg
, i
, SCE_C_OPERATOR
);
2175 if (startSeg
< lengthDoc
)
2176 styler
.ColourSegment(startSeg
, lengthDoc
- 1, state
);
2179 void ColouriseDoc(int codePage
, int startPos
, int lengthDoc
, int initStyle
,
2180 int language
, WordList
*keywordlists
[], StylingContext
&styler
) {
2181 //Platform::DebugPrintf("ColouriseDoc <%s>\n", language);
2182 if (language
== SCLEX_PYTHON
) {
2183 // Python uses a different mask because bad indentation is marked by oring with 32
2184 styler
.StartAt(startPos
, 127);
2185 ColourisePyDoc(codePage
, startPos
, lengthDoc
, initStyle
, *keywordlists
[0], styler
);
2186 } else if (language
== SCLEX_PERL
) {
2187 // Lexer for perl often has to backtrack to start of current style to determine
2188 // which characters are being used as quotes, how deeply nested is the
2189 // start position and what the termination string is for here documents
2190 ColourisePerlDoc(codePage
, startPos
, lengthDoc
, initStyle
, *keywordlists
[0], styler
);
2191 } else if ((language
== SCLEX_HTML
) || (language
== SCLEX_XML
)) {
2192 // Lexer for HTML requires more lexical states (6 bits worth) than most lexers
2193 ColouriseHyperTextDoc(codePage
, startPos
, lengthDoc
, initStyle
,
2194 *keywordlists
[0], *keywordlists
[1], *keywordlists
[2], *keywordlists
[3], styler
);
2196 styler
.StartAt(startPos
);
2197 if (language
== SCLEX_CPP
) {
2198 ColouriseCppDoc(codePage
, startPos
, lengthDoc
, initStyle
, *keywordlists
[0], styler
);
2199 } else if (language
== SCLEX_SQL
) {
2200 ColouriseSQLDoc(codePage
, startPos
, lengthDoc
, initStyle
, *keywordlists
[0], styler
);
2201 } else if (language
== SCLEX_VB
) {
2202 ColouriseVBDoc(codePage
, startPos
, lengthDoc
, initStyle
, *keywordlists
[0], styler
);
2203 } else if (language
== SCLEX_PROPERTIES
) {
2204 ColourisePropsDoc(startPos
, lengthDoc
, initStyle
, styler
);
2205 } else if (language
== SCLEX_ERRORLIST
) {
2206 ColouriseErrorListDoc(startPos
, lengthDoc
, initStyle
, styler
);
2207 } else if (language
== SCLEX_MAKEFILE
) {
2208 ColouriseMakeDoc(startPos
, lengthDoc
, initStyle
, styler
);
2209 } else if (language
== SCLEX_BATCH
) {
2210 ColouriseBatchDoc(startPos
, lengthDoc
, initStyle
, styler
);
2212 // Null language means all style bytes are 0 so just mark the end - no need to fill in.
2213 styler
.StartAt(startPos
+ lengthDoc
- 1);
2214 styler
.ColourSegment(0, 0, 0);