]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexAVE.cxx
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"
27 static inline bool IsAWordChar(const int ch
) {
28 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_');
30 static inline bool IsEnumChar(const int ch
) {
31 return (ch
< 0x80) && (isalnum(ch
)|| ch
== '_');
33 static inline bool IsANumberChar(const int ch
) {
34 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' );
37 inline bool IsAWordStart(const int ch
) {
38 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
41 inline bool isAveOperator(char ch
) {
44 // '.' left out as it is used to make up numbers
45 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
46 ch
== '(' || ch
== ')' || ch
== '=' ||
47 ch
== '{' || ch
== '}' ||
48 ch
== '[' || ch
== ']' || ch
== ';' ||
49 ch
== '<' || ch
== '>' || ch
== ',' ||
55 static void ColouriseAveDoc(
56 unsigned int startPos
,
59 WordList
*keywordlists
[],
62 WordList
&keywords
= *keywordlists
[0];
63 WordList
&keywords2
= *keywordlists
[1];
64 WordList
&keywords3
= *keywordlists
[2];
65 WordList
&keywords4
= *keywordlists
[3];
66 WordList
&keywords5
= *keywordlists
[4];
67 WordList
&keywords6
= *keywordlists
[5];
69 // Do not leak onto next line
70 if (initStyle
== SCE_AVE_STRINGEOL
) {
71 initStyle
= SCE_AVE_DEFAULT
;
74 StyleContext
sc(startPos
, length
, initStyle
, styler
);
76 for (; sc
.More(); sc
.Forward()) {
78 // Update the line state, so it can be seen by next line
79 int currentLine
= styler
.GetLine(sc
.currentPos
);
80 styler
.SetLineState(currentLine
, 0);
82 if (sc
.atLineStart
&& (sc
.state
== SCE_AVE_STRING
)) {
83 // Prevent SCE_AVE_STRINGEOL from leaking back to previous line
84 sc
.SetState(SCE_AVE_STRING
);
88 // Determine if the current state should terminate.
89 if (sc
.state
== SCE_AVE_OPERATOR
) {
90 sc
.SetState(SCE_AVE_DEFAULT
);
91 } else if (sc
.state
== SCE_AVE_NUMBER
) {
92 if (!IsANumberChar(sc
.ch
)) {
93 sc
.SetState(SCE_AVE_DEFAULT
);
95 } else if (sc
.state
== SCE_AVE_ENUM
) {
96 if (!IsEnumChar(sc
.ch
)) {
97 sc
.SetState(SCE_AVE_DEFAULT
);
99 } else if (sc
.state
== SCE_AVE_IDENTIFIER
) {
100 if (!IsAWordChar(sc
.ch
) || (sc
.ch
== '.')) {
102 //sc.GetCurrent(s, sizeof(s));
103 sc
.GetCurrentLowered(s
, sizeof(s
));
104 if (keywords
.InList(s
)) {
105 sc
.ChangeState(SCE_AVE_WORD
);
106 } else if (keywords2
.InList(s
)) {
107 sc
.ChangeState(SCE_AVE_WORD2
);
108 } else if (keywords3
.InList(s
)) {
109 sc
.ChangeState(SCE_AVE_WORD3
);
110 } else if (keywords4
.InList(s
)) {
111 sc
.ChangeState(SCE_AVE_WORD4
);
112 } else if (keywords5
.InList(s
)) {
113 sc
.ChangeState(SCE_AVE_WORD5
);
114 } else if (keywords6
.InList(s
)) {
115 sc
.ChangeState(SCE_AVE_WORD6
);
117 sc
.SetState(SCE_AVE_DEFAULT
);
119 } else if (sc
.state
== SCE_AVE_COMMENT
) {
121 sc
.SetState(SCE_AVE_DEFAULT
);
123 } else if (sc
.state
== SCE_AVE_STRING
) {
125 sc
.ForwardSetState(SCE_AVE_DEFAULT
);
126 } else if (sc
.atLineEnd
) {
127 sc
.ChangeState(SCE_AVE_STRINGEOL
);
128 sc
.ForwardSetState(SCE_AVE_DEFAULT
);
132 // Determine if a new state should be entered.
133 if (sc
.state
== SCE_AVE_DEFAULT
) {
134 if (IsADigit(sc
.ch
) || (sc
.ch
== '.' && IsADigit(sc
.chNext
))) {
135 sc
.SetState(SCE_AVE_NUMBER
);
136 } else if (IsAWordStart(sc
.ch
)) {
137 sc
.SetState(SCE_AVE_IDENTIFIER
);
138 } else if (sc
.Match('\"')) {
139 sc
.SetState(SCE_AVE_STRING
);
140 } else if (sc
.Match('\'')) {
141 sc
.SetState(SCE_AVE_COMMENT
);
143 } else if (isAveOperator(static_cast<char>(sc
.ch
))) {
144 sc
.SetState(SCE_AVE_OPERATOR
);
145 } else if (sc
.Match('#')) {
146 sc
.SetState(SCE_AVE_ENUM
);
154 static void FoldAveDoc(unsigned int startPos
, int length
, int /* initStyle */, WordList
*[],
156 unsigned int lengthDoc
= startPos
+ length
;
157 int visibleChars
= 0;
158 int lineCurrent
= styler
.GetLine(startPos
);
159 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
160 int levelCurrent
= levelPrev
;
161 char chNext
= static_cast<char>(tolower(styler
[startPos
]));
162 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
163 int styleNext
= styler
.StyleAt(startPos
);
166 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
167 char ch
= static_cast<char>(tolower(chNext
));
168 chNext
= static_cast<char>(tolower(styler
.SafeGetCharAt(i
+ 1)));
169 int style
= styleNext
;
170 styleNext
= styler
.StyleAt(i
+ 1);
171 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
172 if (style
== SCE_AVE_WORD
) {
173 if (ch
== 't' || ch
== 'f' || ch
== 'w' || ch
== 'e') {
174 for (unsigned int j
= 0; j
< 6; j
++) {
175 if (!iswordchar(styler
[i
+ j
])) {
178 s
[j
] = static_cast<char>(tolower(styler
[i
+ j
]));
182 if ((strcmp(s
, "then") == 0) || (strcmp(s
, "for") == 0) || (strcmp(s
, "while") == 0)) {
185 if ((strcmp(s
, "end") == 0) || (strcmp(s
, "elseif") == 0)) {
186 // Normally "elseif" and "then" will be on the same line and will cancel
187 // each other out. // As implemented, this does not support fold.at.else.
191 } else if (style
== SCE_AVE_OPERATOR
) {
192 if (ch
== '{' || ch
== '(') {
194 } else if (ch
== '}' || ch
== ')') {
201 if (visibleChars
== 0 && foldCompact
) {
202 lev
|= SC_FOLDLEVELWHITEFLAG
;
204 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0)) {
205 lev
|= SC_FOLDLEVELHEADERFLAG
;
207 if (lev
!= styler
.LevelAt(lineCurrent
)) {
208 styler
.SetLevel(lineCurrent
, lev
);
211 levelPrev
= levelCurrent
;
214 if (!isspacechar(ch
)) {
218 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
220 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
221 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
224 LexerModule
lmAVE(SCLEX_AVE
, ColouriseAveDoc
, "ave", FoldAveDoc
);