]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAVE.cxx
2b7029b1ac700c715f0ed954fe7898c4bb530a6c
1 // SciTE - Scintilla based Text Editor
5 ** Written by Alexey Yutkin <yutkin@geol.msu.ru>.
7 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
8 // The License.txt file describes the conditions under which this software may be distributed.
20 #include "StyleContext.h"
22 #include "Scintilla.h"
26 using namespace Scintilla
;
30 static inline bool IsAWordChar(const int ch
) {
31 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_');
33 static inline bool IsEnumChar(const int ch
) {
34 return (ch
< 0x80) && (isalnum(ch
)|| ch
== '_');
36 static inline bool IsANumberChar(const int ch
) {
37 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' );
40 inline bool IsAWordStart(const int ch
) {
41 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
44 inline bool isAveOperator(char ch
) {
47 // '.' left out as it is used to make up numbers
48 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
49 ch
== '(' || ch
== ')' || ch
== '=' ||
50 ch
== '{' || ch
== '}' ||
51 ch
== '[' || ch
== ']' || ch
== ';' ||
52 ch
== '<' || ch
== '>' || ch
== ',' ||
58 static void ColouriseAveDoc(
59 unsigned int startPos
,
62 WordList
*keywordlists
[],
65 WordList
&keywords
= *keywordlists
[0];
66 WordList
&keywords2
= *keywordlists
[1];
67 WordList
&keywords3
= *keywordlists
[2];
68 WordList
&keywords4
= *keywordlists
[3];
69 WordList
&keywords5
= *keywordlists
[4];
70 WordList
&keywords6
= *keywordlists
[5];
72 // Do not leak onto next line
73 if (initStyle
== SCE_AVE_STRINGEOL
) {
74 initStyle
= SCE_AVE_DEFAULT
;
77 StyleContext
sc(startPos
, length
, initStyle
, styler
);
79 for (; sc
.More(); sc
.Forward()) {
81 // Update the line state, so it can be seen by next line
82 int currentLine
= styler
.GetLine(sc
.currentPos
);
83 styler
.SetLineState(currentLine
, 0);
85 if (sc
.atLineStart
&& (sc
.state
== SCE_AVE_STRING
)) {
86 // Prevent SCE_AVE_STRINGEOL from leaking back to previous line
87 sc
.SetState(SCE_AVE_STRING
);
91 // Determine if the current state should terminate.
92 if (sc
.state
== SCE_AVE_OPERATOR
) {
93 sc
.SetState(SCE_AVE_DEFAULT
);
94 } else if (sc
.state
== SCE_AVE_NUMBER
) {
95 if (!IsANumberChar(sc
.ch
)) {
96 sc
.SetState(SCE_AVE_DEFAULT
);
98 } else if (sc
.state
== SCE_AVE_ENUM
) {
99 if (!IsEnumChar(sc
.ch
)) {
100 sc
.SetState(SCE_AVE_DEFAULT
);
102 } else if (sc
.state
== SCE_AVE_IDENTIFIER
) {
103 if (!IsAWordChar(sc
.ch
) || (sc
.ch
== '.')) {
105 //sc.GetCurrent(s, sizeof(s));
106 sc
.GetCurrentLowered(s
, sizeof(s
));
107 if (keywords
.InList(s
)) {
108 sc
.ChangeState(SCE_AVE_WORD
);
109 } else if (keywords2
.InList(s
)) {
110 sc
.ChangeState(SCE_AVE_WORD2
);
111 } else if (keywords3
.InList(s
)) {
112 sc
.ChangeState(SCE_AVE_WORD3
);
113 } else if (keywords4
.InList(s
)) {
114 sc
.ChangeState(SCE_AVE_WORD4
);
115 } else if (keywords5
.InList(s
)) {
116 sc
.ChangeState(SCE_AVE_WORD5
);
117 } else if (keywords6
.InList(s
)) {
118 sc
.ChangeState(SCE_AVE_WORD6
);
120 sc
.SetState(SCE_AVE_DEFAULT
);
122 } else if (sc
.state
== SCE_AVE_COMMENT
) {
124 sc
.SetState(SCE_AVE_DEFAULT
);
126 } else if (sc
.state
== SCE_AVE_STRING
) {
128 sc
.ForwardSetState(SCE_AVE_DEFAULT
);
129 } else if (sc
.atLineEnd
) {
130 sc
.ChangeState(SCE_AVE_STRINGEOL
);
131 sc
.ForwardSetState(SCE_AVE_DEFAULT
);
135 // Determine if a new state should be entered.
136 if (sc
.state
== SCE_AVE_DEFAULT
) {
137 if (IsADigit(sc
.ch
) || (sc
.ch
== '.' && IsADigit(sc
.chNext
))) {
138 sc
.SetState(SCE_AVE_NUMBER
);
139 } else if (IsAWordStart(sc
.ch
)) {
140 sc
.SetState(SCE_AVE_IDENTIFIER
);
141 } else if (sc
.Match('\"')) {
142 sc
.SetState(SCE_AVE_STRING
);
143 } else if (sc
.Match('\'')) {
144 sc
.SetState(SCE_AVE_COMMENT
);
146 } else if (isAveOperator(static_cast<char>(sc
.ch
))) {
147 sc
.SetState(SCE_AVE_OPERATOR
);
148 } else if (sc
.Match('#')) {
149 sc
.SetState(SCE_AVE_ENUM
);
157 static void FoldAveDoc(unsigned int startPos
, int length
, int /* initStyle */, WordList
*[],
159 unsigned int lengthDoc
= startPos
+ length
;
160 int visibleChars
= 0;
161 int lineCurrent
= styler
.GetLine(startPos
);
162 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
163 int levelCurrent
= levelPrev
;
164 char chNext
= static_cast<char>(tolower(styler
[startPos
]));
165 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
166 int styleNext
= styler
.StyleAt(startPos
);
169 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
170 char ch
= static_cast<char>(tolower(chNext
));
171 chNext
= static_cast<char>(tolower(styler
.SafeGetCharAt(i
+ 1)));
172 int style
= styleNext
;
173 styleNext
= styler
.StyleAt(i
+ 1);
174 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
175 if (style
== SCE_AVE_WORD
) {
176 if (ch
== 't' || ch
== 'f' || ch
== 'w' || ch
== 'e') {
177 for (unsigned int j
= 0; j
< 6; j
++) {
178 if (!iswordchar(styler
[i
+ j
])) {
181 s
[j
] = static_cast<char>(tolower(styler
[i
+ j
]));
185 if ((strcmp(s
, "then") == 0) || (strcmp(s
, "for") == 0) || (strcmp(s
, "while") == 0)) {
188 if ((strcmp(s
, "end") == 0) || (strcmp(s
, "elseif") == 0)) {
189 // Normally "elseif" and "then" will be on the same line and will cancel
190 // each other out. // As implemented, this does not support fold.at.else.
194 } else if (style
== SCE_AVE_OPERATOR
) {
195 if (ch
== '{' || ch
== '(') {
197 } else if (ch
== '}' || ch
== ')') {
204 if (visibleChars
== 0 && foldCompact
) {
205 lev
|= SC_FOLDLEVELWHITEFLAG
;
207 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0)) {
208 lev
|= SC_FOLDLEVELHEADERFLAG
;
210 if (lev
!= styler
.LevelAt(lineCurrent
)) {
211 styler
.SetLevel(lineCurrent
, lev
);
214 levelPrev
= levelCurrent
;
217 if (!isspacechar(ch
)) {
221 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
223 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
224 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
227 LexerModule
lmAVE(SCLEX_AVE
, ColouriseAveDoc
, "ave", FoldAveDoc
);