129
//------------------------------------------------------------------------------
130
// 06-27-07 Sergio Lucato
131
// - Included code folding for Ansys APDL lexer
132
// - Copyied from LexBasic.cxx and modified for APDL
133
//------------------------------------------------------------------------------
143
static int character_classification[128] =
145
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
146
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147
1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 10, 6,
148
60, 60, 28, 28, 28, 28, 28, 28, 28, 28, 2, 2, 2, 2, 2, 2,
149
2, 20, 20, 20, 20, 20, 20, 4, 4, 4, 4, 4, 4, 4, 4, 4,
150
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 4,
151
2, 20, 20, 20, 20, 20, 20, 4, 4, 4, 4, 4, 4, 4, 4, 4,
152
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0
155
static bool IsSpace(int c) {
156
return c < 128 && (character_classification[c] & 1);
159
static bool IsIdentifier(int c) {
160
return c < 128 && (character_classification[c] & 4);
163
static int LowerCase(int c)
165
if (c >= 'A' && c <= 'Z')
166
return 'a' + c - 'A';
170
static int CheckAPDLFoldPoint(char const *token, int &level) {
171
if (!strcmp(token, "*if") ||
172
!strcmp(token, "*do") ||
173
!strcmp(token, "*dowhile") ) {
174
level |= SC_FOLDLEVELHEADERFLAG;
177
if (!strcmp(token, "*endif") ||
178
!strcmp(token, "*enddo") ) {
184
static void FoldAPDLDoc(unsigned int startPos, int length, int,
185
WordList *[], Accessor &styler) {
187
int line = styler.GetLine(startPos);
188
int level = styler.LevelAt(line);
189
int go = 0, done = 0;
190
int endPos = startPos + length;
194
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
195
// Scan for tokens at the start of the line (they may include
196
// whitespace, for tokens like "End Function"
197
for (i = startPos; i < endPos; i++) {
198
int c = styler.SafeGetCharAt(i);
200
if (wordlen) { // are we scanning a token already?
201
word[wordlen] = static_cast<char>(LowerCase(c));
202
if (!IsIdentifier(c)) { // done with token
203
word[wordlen] = '\0';
204
go = CheckAPDLFoldPoint(word, level);
206
// Treat any whitespace as single blank, for
207
// things like "End Function".
208
if (IsSpace(c) && IsIdentifier(word[wordlen - 1])) {
213
else // done with this line
216
} else if (wordlen < 255) {
219
} else { // start scanning at first non-whitespace character
221
if (IsIdentifier(c)) {
222
word[0] = static_cast<char>(LowerCase(c));
224
} else // done with this line
229
if (c == '\n') { // line end
230
if (!done && wordlen == 0 && foldCompact) // line was only space
231
level |= SC_FOLDLEVELWHITEFLAG;
232
if (level != styler.LevelAt(line))
233
styler.SetLevel(line, level);
238
level &= ~SC_FOLDLEVELHEADERFLAG;
239
level &= ~SC_FOLDLEVELWHITEFLAG;
126
246
static const char * const apdlWordListDesc[] = {