~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-07-29 19:42:47 UTC
  • mfrom: (1.1.9 upstream) (18.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100729194247-cuibfk03wog33nxq
Tags: 2.6.0.4189~dfsg-1
* New upstream release.
* Bump Standards.
* Refresh patches.
* Add license information about files under ./Debugger/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// SciTE - Scintilla based Text Editor
2
 
/** @file LexAVE.cxx
3
 
 ** Lexer for Avenue.
4
 
 **
5
 
  ** Written by Alexey Yutkin <yutkin@geol.msu.ru>.
6
 
 **/
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.
9
 
 
10
 
#include <stdlib.h>
11
 
#include <string.h>
12
 
#include <ctype.h>
13
 
#include <stdarg.h>
14
 
#include <stdio.h>
15
 
 
16
 
#include "Platform.h"
17
 
 
18
 
#include "PropSet.h"
19
 
#include "Accessor.h"
20
 
#include "StyleContext.h"
21
 
#include "KeyWords.h"
22
 
#include "Scintilla.h"
23
 
#include "SciLexer.h"
24
 
 
25
 
#ifdef SCI_NAMESPACE
26
 
using namespace Scintilla;
27
 
#endif
28
 
 
29
 
 
30
 
static inline bool IsAWordChar(const int ch) {
31
 
        return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
32
 
}
33
 
static inline bool IsEnumChar(const int ch) {
34
 
        return (ch < 0x80) && (isalnum(ch)|| ch == '_');
35
 
}
36
 
static inline bool IsANumberChar(const int ch) {
37
 
        return (ch < 0x80) && (isalnum(ch) || ch == '.' );
38
 
}
39
 
 
40
 
inline bool IsAWordStart(const int ch) {
41
 
        return (ch < 0x80) && (isalnum(ch) || ch == '_');
42
 
}
43
 
 
44
 
inline bool isAveOperator(char ch) {
45
 
        if (isalnum(ch))
46
 
                return false;
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 == ',' ||
53
 
                ch == '.'  )
54
 
                return true;
55
 
        return false;
56
 
}
57
 
 
58
 
static void ColouriseAveDoc(
59
 
        unsigned int startPos,
60
 
        int length,
61
 
        int initStyle,
62
 
        WordList *keywordlists[],
63
 
        Accessor &styler) {
64
 
 
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];
71
 
 
72
 
        // Do not leak onto next line
73
 
        if (initStyle == SCE_AVE_STRINGEOL) {
74
 
                initStyle = SCE_AVE_DEFAULT;
75
 
        }
76
 
 
77
 
        StyleContext sc(startPos, length, initStyle, styler);
78
 
 
79
 
        for (; sc.More(); sc.Forward()) {
80
 
                if (sc.atLineEnd) {
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);
84
 
                }
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);
88
 
                }
89
 
 
90
 
 
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);
97
 
                        }
98
 
                } else if (sc.state == SCE_AVE_ENUM) {
99
 
                        if (!IsEnumChar(sc.ch)) {
100
 
                                sc.SetState(SCE_AVE_DEFAULT);
101
 
                        }
102
 
                } else if (sc.state == SCE_AVE_IDENTIFIER) {
103
 
                        if (!IsAWordChar(sc.ch) || (sc.ch == '.')) {
104
 
                                char s[100];
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);
119
 
                                }
120
 
                                sc.SetState(SCE_AVE_DEFAULT);
121
 
                        }
122
 
                } else if (sc.state == SCE_AVE_COMMENT) {
123
 
                        if (sc.atLineEnd) {
124
 
                                sc.SetState(SCE_AVE_DEFAULT);
125
 
                        }
126
 
                } else if (sc.state == SCE_AVE_STRING) {
127
 
                         if (sc.ch == '\"') {
128
 
                                sc.ForwardSetState(SCE_AVE_DEFAULT);
129
 
                        } else if (sc.atLineEnd) {
130
 
                                sc.ChangeState(SCE_AVE_STRINGEOL);
131
 
                                sc.ForwardSetState(SCE_AVE_DEFAULT);
132
 
                        }
133
 
                }
134
 
 
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);
145
 
                                sc.Forward();
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);
150
 
                                sc.Forward();
151
 
                        }
152
 
                }
153
 
        }
154
 
        sc.Complete();
155
 
}
156
 
 
157
 
static void FoldAveDoc(unsigned int startPos, int length, int /* initStyle */, WordList *[],
158
 
                       Accessor &styler) {
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);
167
 
        char s[10];
168
 
 
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])) {
179
 
                                                break;
180
 
                                        }
181
 
                                        s[j] = static_cast<char>(tolower(styler[i + j]));
182
 
                                        s[j + 1] = '\0';
183
 
                                }
184
 
 
185
 
                                if ((strcmp(s, "then") == 0) || (strcmp(s, "for") == 0) || (strcmp(s, "while") == 0)) {
186
 
                                        levelCurrent++;
187
 
                                }
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.
191
 
                                        levelCurrent--;
192
 
                                }
193
 
                        }
194
 
                } else if (style == SCE_AVE_OPERATOR) {
195
 
                        if (ch == '{' || ch == '(') {
196
 
                                levelCurrent++;
197
 
                        } else if (ch == '}' || ch == ')') {
198
 
                                levelCurrent--;
199
 
                        }
200
 
                }
201
 
 
202
 
                if (atEOL) {
203
 
                        int lev = levelPrev;
204
 
                        if (visibleChars == 0 && foldCompact) {
205
 
                                lev |= SC_FOLDLEVELWHITEFLAG;
206
 
                        }
207
 
                        if ((levelCurrent > levelPrev) && (visibleChars > 0)) {
208
 
                                lev |= SC_FOLDLEVELHEADERFLAG;
209
 
                        }
210
 
                        if (lev != styler.LevelAt(lineCurrent)) {
211
 
                                styler.SetLevel(lineCurrent, lev);
212
 
                        }
213
 
                        lineCurrent++;
214
 
                        levelPrev = levelCurrent;
215
 
                        visibleChars = 0;
216
 
                }
217
 
                if (!isspacechar(ch)) {
218
 
                        visibleChars++;
219
 
                }
220
 
        }
221
 
        // Fill in the real level of the next line, keeping the current flags as they will be filled in later
222
 
 
223
 
        int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
224
 
        styler.SetLevel(lineCurrent, levelPrev | flagsNext);
225
 
}
226
 
 
227
 
LexerModule lmAVE(SCLEX_AVE, ColouriseAveDoc, "ave", FoldAveDoc);
228
 
 
 
1
// SciTE - Scintilla based Text Editor
 
2
/** @file LexAVE.cxx
 
3
 ** Lexer for Avenue.
 
4
 **
 
5
  ** Written by Alexey Yutkin <yutkin@geol.msu.ru>.
 
6
 **/
 
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.
 
9
 
 
10
#include <stdlib.h>
 
11
#include <string.h>
 
12
#include <ctype.h>
 
13
#include <stdarg.h>
 
14
#include <stdio.h>
 
15
 
 
16
#include "Platform.h"
 
17
 
 
18
#include "PropSet.h"
 
19
#include "Accessor.h"
 
20
#include "StyleContext.h"
 
21
#include "KeyWords.h"
 
22
#include "Scintilla.h"
 
23
#include "SciLexer.h"
 
24
 
 
25
#ifdef SCI_NAMESPACE
 
26
using namespace Scintilla;
 
27
#endif
 
28
 
 
29
 
 
30
static inline bool IsAWordChar(const int ch) {
 
31
        return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
 
32
}
 
33
static inline bool IsEnumChar(const int ch) {
 
34
        return (ch < 0x80) && (isalnum(ch)|| ch == '_');
 
35
}
 
36
static inline bool IsANumberChar(const int ch) {
 
37
        return (ch < 0x80) && (isalnum(ch) || ch == '.' );
 
38
}
 
39
 
 
40
inline bool IsAWordStart(const int ch) {
 
41
        return (ch < 0x80) && (isalnum(ch) || ch == '_');
 
42
}
 
43
 
 
44
inline bool isAveOperator(char ch) {
 
45
        if (isascii(ch) && isalnum(ch))
 
46
                return false;
 
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 == ',' ||
 
53
                ch == '.'  )
 
54
                return true;
 
55
        return false;
 
56
}
 
57
 
 
58
static void ColouriseAveDoc(
 
59
        unsigned int startPos,
 
60
        int length,
 
61
        int initStyle,
 
62
        WordList *keywordlists[],
 
63
        Accessor &styler) {
 
64
 
 
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];
 
71
 
 
72
        // Do not leak onto next line
 
73
        if (initStyle == SCE_AVE_STRINGEOL) {
 
74
                initStyle = SCE_AVE_DEFAULT;
 
75
        }
 
76
 
 
77
        StyleContext sc(startPos, length, initStyle, styler);
 
78
 
 
79
        for (; sc.More(); sc.Forward()) {
 
80
                if (sc.atLineEnd) {
 
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);
 
84
                }
 
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);
 
88
                }
 
89
 
 
90
 
 
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);
 
97
                        }
 
98
                } else if (sc.state == SCE_AVE_ENUM) {
 
99
                        if (!IsEnumChar(sc.ch)) {
 
100
                                sc.SetState(SCE_AVE_DEFAULT);
 
101
                        }
 
102
                } else if (sc.state == SCE_AVE_IDENTIFIER) {
 
103
                        if (!IsAWordChar(sc.ch) || (sc.ch == '.')) {
 
104
                                char s[100];
 
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);
 
119
                                }
 
120
                                sc.SetState(SCE_AVE_DEFAULT);
 
121
                        }
 
122
                } else if (sc.state == SCE_AVE_COMMENT) {
 
123
                        if (sc.atLineEnd) {
 
124
                                sc.SetState(SCE_AVE_DEFAULT);
 
125
                        }
 
126
                } else if (sc.state == SCE_AVE_STRING) {
 
127
                         if (sc.ch == '\"') {
 
128
                                sc.ForwardSetState(SCE_AVE_DEFAULT);
 
129
                        } else if (sc.atLineEnd) {
 
130
                                sc.ChangeState(SCE_AVE_STRINGEOL);
 
131
                                sc.ForwardSetState(SCE_AVE_DEFAULT);
 
132
                        }
 
133
                }
 
134
 
 
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);
 
145
                                sc.Forward();
 
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);
 
150
                                sc.Forward();
 
151
                        }
 
152
                }
 
153
        }
 
154
        sc.Complete();
 
155
}
 
156
 
 
157
static void FoldAveDoc(unsigned int startPos, int length, int /* initStyle */, WordList *[],
 
158
                       Accessor &styler) {
 
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);
 
167
        char s[10];
 
168
 
 
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])) {
 
179
                                                break;
 
180
                                        }
 
181
                                        s[j] = static_cast<char>(tolower(styler[i + j]));
 
182
                                        s[j + 1] = '\0';
 
183
                                }
 
184
 
 
185
                                if ((strcmp(s, "then") == 0) || (strcmp(s, "for") == 0) || (strcmp(s, "while") == 0)) {
 
186
                                        levelCurrent++;
 
187
                                }
 
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.
 
191
                                        levelCurrent--;
 
192
                                }
 
193
                        }
 
194
                } else if (style == SCE_AVE_OPERATOR) {
 
195
                        if (ch == '{' || ch == '(') {
 
196
                                levelCurrent++;
 
197
                        } else if (ch == '}' || ch == ')') {
 
198
                                levelCurrent--;
 
199
                        }
 
200
                }
 
201
 
 
202
                if (atEOL) {
 
203
                        int lev = levelPrev;
 
204
                        if (visibleChars == 0 && foldCompact) {
 
205
                                lev |= SC_FOLDLEVELWHITEFLAG;
 
206
                        }
 
207
                        if ((levelCurrent > levelPrev) && (visibleChars > 0)) {
 
208
                                lev |= SC_FOLDLEVELHEADERFLAG;
 
209
                        }
 
210
                        if (lev != styler.LevelAt(lineCurrent)) {
 
211
                                styler.SetLevel(lineCurrent, lev);
 
212
                        }
 
213
                        lineCurrent++;
 
214
                        levelPrev = levelCurrent;
 
215
                        visibleChars = 0;
 
216
                }
 
217
                if (!isspacechar(ch)) {
 
218
                        visibleChars++;
 
219
                }
 
220
        }
 
221
        // Fill in the real level of the next line, keeping the current flags as they will be filled in later
 
222
 
 
223
        int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
 
224
        styler.SetLevel(lineCurrent, levelPrev | flagsNext);
 
225
}
 
226
 
 
227
LexerModule lmAVE(SCLEX_AVE, ColouriseAveDoc, "ave", FoldAveDoc);
 
228