]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexAVE.cxx
a7422743faeaae339374bd5dd8d34717e586e60b
1 // SciTE - Scintilla based Text Editor
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
19 #include "Scintilla.h"
22 static void ColouriseAveDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
25 WordList
&keywords
= *keywordlists
[0];
27 styler
.StartAt(startPos
);
29 bool fold
= styler
.GetPropertyInt("fold");
30 int lineCurrent
= styler
.GetLine(startPos
);
31 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
32 int levelCurrent
= levelPrev
;
34 int state
= initStyle
;
35 if (state
== SCE_AVE_STRINGEOL
) // Does not leak onto next line
36 state
= SCE_AVE_DEFAULT
;
37 char chNext
= styler
[startPos
];
38 unsigned int lengthDoc
= startPos
+ length
;
40 styler
.StartSegment(startPos
);
42 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
44 chNext
= styler
.SafeGetCharAt(i
+ 1);
45 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
46 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
47 // Avoid triggering two times on Dos/Win
49 if (state
== SCE_AVE_STRINGEOL
) {
50 styler
.ColourTo(i
, state
);
51 state
= SCE_AVE_DEFAULT
;
55 if (visibleChars
== 0)
56 lev
|= SC_FOLDLEVELWHITEFLAG
;
57 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
58 lev
|= SC_FOLDLEVELHEADERFLAG
;
59 styler
.SetLevel(lineCurrent
, lev
);
61 levelPrev
= levelCurrent
;
67 if (styler
.IsLeadByte(ch
)) {
68 chNext
= styler
.SafeGetCharAt(i
+ 2);
73 if (state
== SCE_AVE_DEFAULT
) {
74 if (iswordstart(ch
) || (ch
== '.') ) {
75 styler
.ColourTo(i
-1, state
);
76 state
= SCE_AVE_IDENTIFIER
;
77 } else if (ch
== '\'') {
78 styler
.ColourTo(i
-1, state
);
79 state
= SCE_AVE_COMMENT
;
80 } else if (ch
== '\"') {
81 styler
.ColourTo(i
-1, state
);
82 state
= SCE_AVE_STRING
;
83 } else if (ch
== '#') {
84 styler
.ColourTo(i
-1, state
);
86 } else if (isoperator(ch
) ) {
87 styler
.ColourTo(i
-1, state
);
88 styler
.ColourTo(i
, SCE_AVE_OPERATOR
);
91 else if (state
== SCE_AVE_COMMENT
) {
92 if (ch
== '\r' || ch
== '\n') {
93 styler
.ColourTo(i
-1, state
);
94 state
= SCE_AVE_DEFAULT
;
97 else if (state
== SCE_AVE_ENUM
) {
98 if (isoperator(ch
) || ch
== ' ' || ch
== '\'' || ch
== '\r' || ch
== '\n') {
99 styler
.ColourTo(i
-1, state
);
100 state
= SCE_AVE_DEFAULT
;
103 else if (state
== SCE_AVE_STRING
) {
105 if (chNext
== '\"') {
108 chNext
= styler
.SafeGetCharAt(i
+ 1);
111 styler
.ColourTo(i
, state
);
112 state
= SCE_AVE_DEFAULT
;
114 } else if (chNext
== '\r' || chNext
== '\n') {
115 styler
.ColourTo(i
-1, SCE_AVE_STRINGEOL
);
116 state
= SCE_AVE_STRINGEOL
;
119 if ((state
== SCE_AVE_IDENTIFIER
)) {
120 if (!iswordchar(ch
) || ch
== '.' ) {
122 unsigned int start
= styler
.GetStartSegment();
123 unsigned int end
= i
- 1;
124 for (unsigned int ii
= 0; ii
< end
- start
+ 1 && ii
< 30; ii
++) {
125 s
[ii
] = static_cast<char>(tolower(styler
[start
+ ii
]));
129 char chAttr
= SCE_AVE_IDENTIFIER
;
132 chAttr
= SCE_AVE_NUMBER
;
134 if ((strcmp(s
, "for") == 0) || (strcmp(s
, "if") == 0) || (strcmp(s
, "while") == 0))
137 chAttr
= SCE_AVE_STATEMENT
;
140 if (strcmp(s
, "end") == 0)
143 chAttr
= SCE_AVE_STATEMENT
;
146 if ( (strcmp(s
, "then") == 0) || (strcmp(s
, "else") == 0) || (strcmp(s
, "break") == 0) ||
147 (strcmp(s
, "each") == 0) ||
148 (strcmp(s
, "exit") == 0) || (strcmp(s
, "continue") == 0) || (strcmp(s
, "return") == 0) ||
149 (strcmp(s
, "by") == 0) || (strcmp(s
, "in") == 0) || (strcmp(s
, "elseif") == 0))
151 chAttr
= SCE_AVE_STATEMENT
;
154 if ((strcmp(s
, "av") == 0) || (strcmp(s
, "self") == 0))
156 chAttr
= SCE_AVE_KEYWORD
;
159 if (keywords
.InList(s
))
161 chAttr
= SCE_AVE_WORD
;
164 styler
.ColourTo(end
, chAttr
);
165 state
= SCE_AVE_DEFAULT
;
168 state
= SCE_AVE_COMMENT
;
169 } else if (ch
== '\"') {
170 state
= SCE_AVE_STRING
;
171 } else if (isoperator(ch
)) {
172 styler
.ColourTo(i
, SCE_AVE_OPERATOR
);
178 styler
.ColourTo(lengthDoc
- 1, state
);
180 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
182 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
183 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
188 LexerModule
lmAVE(SCLEX_AVE
, ColouriseAveDoc
, "ave");