~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/src/LexAPDL.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "Scintilla.h"
22
22
#include "SciLexer.h"
23
23
 
 
24
#ifdef SCI_NAMESPACE
 
25
using namespace Scintilla;
 
26
#endif
24
27
 
25
28
static inline bool IsAWordChar(const int ch) {
26
29
        return (ch < 0x80 && (isalnum(ch) || ch == '_'));
123
126
        sc.Complete();
124
127
}
125
128
 
 
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
//------------------------------------------------------------------------------
 
134
 
 
135
/* Bits:
 
136
 * 1  - whitespace
 
137
 * 2  - operator
 
138
 * 4  - identifier
 
139
 * 8  - decimal digit
 
140
 * 16 - hex digit
 
141
 * 32 - bin digit
 
142
 */
 
143
static int character_classification[128] =
 
144
{
 
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
 
153
};
 
154
 
 
155
static bool IsSpace(int c) {
 
156
        return c < 128 && (character_classification[c] & 1);
 
157
}
 
158
 
 
159
static bool IsIdentifier(int c) {
 
160
        return c < 128 && (character_classification[c] & 4);
 
161
}
 
162
 
 
163
static int LowerCase(int c)
 
164
{
 
165
        if (c >= 'A' && c <= 'Z')
 
166
                return 'a' + c - 'A';
 
167
        return c;
 
168
}
 
169
 
 
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;
 
175
                return 1;
 
176
        }
 
177
        if (!strcmp(token, "*endif") ||
 
178
                !strcmp(token, "*enddo") ) {
 
179
                return -1;
 
180
        }
 
181
        return 0;
 
182
}
 
183
 
 
184
static void FoldAPDLDoc(unsigned int startPos, int length, int,
 
185
        WordList *[], Accessor &styler) {
 
186
 
 
187
        int line = styler.GetLine(startPos);
 
188
        int level = styler.LevelAt(line);
 
189
        int go = 0, done = 0;
 
190
        int endPos = startPos + length;
 
191
        char word[256];
 
192
        int wordlen = 0;
 
193
        int i;
 
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);
 
199
                if (!done && !go) {
 
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);
 
205
                                        if (!go) {
 
206
                                                // Treat any whitespace as single blank, for
 
207
                                                // things like "End   Function".
 
208
                                                if (IsSpace(c) && IsIdentifier(word[wordlen - 1])) {
 
209
                                                        word[wordlen] = ' ';
 
210
                                                        if (wordlen < 255)
 
211
                                                                wordlen++;
 
212
                                                }
 
213
                                                else // done with this line
 
214
                                                        done = 1;
 
215
                                        }
 
216
                                } else if (wordlen < 255) {
 
217
                                        wordlen++;
 
218
                                }
 
219
                        } else { // start scanning at first non-whitespace character
 
220
                                if (!IsSpace(c)) {
 
221
                                        if (IsIdentifier(c)) {
 
222
                                                word[0] = static_cast<char>(LowerCase(c));
 
223
                                                wordlen = 1;
 
224
                                        } else // done with this line
 
225
                                                done = 1;
 
226
                                }
 
227
                        }
 
228
                }
 
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);
 
234
                        level += go;
 
235
                        line++;
 
236
                        // reset state
 
237
                        wordlen = 0;
 
238
                        level &= ~SC_FOLDLEVELHEADERFLAG;
 
239
                        level &= ~SC_FOLDLEVELWHITEFLAG;
 
240
                        go = 0;
 
241
                        done = 0;
 
242
                }
 
243
        }
 
244
}
 
245
 
126
246
static const char * const apdlWordListDesc[] = {
127
247
    "processors",
128
248
    "commands",
133
253
    0
134
254
};
135
255
 
136
 
LexerModule lmAPDL(SCLEX_APDL, ColouriseAPDLDoc, "apdl", 0, apdlWordListDesc);
 
256
LexerModule lmAPDL(SCLEX_APDL, ColouriseAPDLDoc, "apdl", FoldAPDLDoc, apdlWordListDesc);