]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAVE.cxx
a7422743faeaae339374bd5dd8d34717e586e60b
[wxWidgets.git] / src / stc / scintilla / src / LexAVE.cxx
1 // SciTE - Scintilla based Text Editor
2 /** @file LexAVE.cxx
3 ** Lexer for Avenue.
4 **/
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <stdarg.h>
13
14 #include "Platform.h"
15
16 #include "PropSet.h"
17 #include "Accessor.h"
18 #include "KeyWords.h"
19 #include "Scintilla.h"
20 #include "SciLexer.h"
21
22 static void ColouriseAveDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
23 Accessor &styler) {
24
25 WordList &keywords = *keywordlists[0];
26
27 styler.StartAt(startPos);
28
29 bool fold = styler.GetPropertyInt("fold");
30 int lineCurrent = styler.GetLine(startPos);
31 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
32 int levelCurrent = levelPrev;
33
34 int state = initStyle;
35 if (state == SCE_AVE_STRINGEOL) // Does not leak onto next line
36 state = SCE_AVE_DEFAULT;
37 char chNext = styler[startPos];
38 unsigned int lengthDoc = startPos + length;
39 int visibleChars = 0;
40 styler.StartSegment(startPos);
41
42 for (unsigned int i = startPos; i < lengthDoc; i++) {
43 char ch = chNext;
44 chNext = styler.SafeGetCharAt(i + 1);
45 if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
46 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
47 // Avoid triggering two times on Dos/Win
48 // End of line
49 if (state == SCE_AVE_STRINGEOL) {
50 styler.ColourTo(i, state);
51 state = SCE_AVE_DEFAULT;
52 }
53 if (fold) {
54 int lev = levelPrev;
55 if (visibleChars == 0)
56 lev |= SC_FOLDLEVELWHITEFLAG;
57 if ((levelCurrent > levelPrev) && (visibleChars > 0))
58 lev |= SC_FOLDLEVELHEADERFLAG;
59 styler.SetLevel(lineCurrent, lev);
60 lineCurrent++;
61 levelPrev = levelCurrent;
62 }
63 visibleChars = 0;
64 }
65 if (!isspace(ch))
66 visibleChars++;
67 if (styler.IsLeadByte(ch)) {
68 chNext = styler.SafeGetCharAt(i + 2);
69 i += 1;
70 continue;
71 }
72
73 if (state == SCE_AVE_DEFAULT) {
74 if (iswordstart(ch) || (ch == '.') ) {
75 styler.ColourTo(i-1, state);
76 state = SCE_AVE_IDENTIFIER;
77 } else if (ch == '\'') {
78 styler.ColourTo(i-1, state);
79 state = SCE_AVE_COMMENT;
80 } else if (ch == '\"') {
81 styler.ColourTo(i-1, state);
82 state = SCE_AVE_STRING;
83 } else if (ch == '#') {
84 styler.ColourTo(i-1, state);
85 state = SCE_AVE_ENUM;
86 } else if (isoperator(ch) ) {
87 styler.ColourTo(i-1, state);
88 styler.ColourTo(i, SCE_AVE_OPERATOR);
89 }
90 }
91 else if (state == SCE_AVE_COMMENT) {
92 if (ch == '\r' || ch == '\n') {
93 styler.ColourTo(i-1, state);
94 state = SCE_AVE_DEFAULT;
95 }
96 }
97 else if (state == SCE_AVE_ENUM) {
98 if (isoperator(ch) || ch == ' ' || ch == '\'' || ch == '\r' || ch == '\n') {
99 styler.ColourTo(i-1, state);
100 state = SCE_AVE_DEFAULT;
101 }
102 }
103 else if (state == SCE_AVE_STRING) {
104 if (ch == '\"') {
105 if (chNext == '\"') {
106 i++;
107 ch = chNext;
108 chNext = styler.SafeGetCharAt(i + 1);
109 } else
110 {
111 styler.ColourTo(i, state);
112 state = SCE_AVE_DEFAULT;
113 }
114 } else if (chNext == '\r' || chNext == '\n') {
115 styler.ColourTo(i-1, SCE_AVE_STRINGEOL);
116 state = SCE_AVE_STRINGEOL;
117 }
118 }
119 if ((state == SCE_AVE_IDENTIFIER)) {
120 if (!iswordchar(ch) || ch == '.' ) {
121 char s[100];
122 unsigned int start = styler.GetStartSegment();
123 unsigned int end = i - 1;
124 for (unsigned int ii = 0; ii < end - start + 1 && ii < 30; ii++) {
125 s[ii] = static_cast<char>(tolower(styler[start + ii]));
126 s[ii + 1] = '\0';
127 }
128
129 char chAttr = SCE_AVE_IDENTIFIER;
130
131 if (isdigit(s[0]))
132 chAttr = SCE_AVE_NUMBER;
133 else {
134 if ((strcmp(s, "for") == 0) || (strcmp(s, "if") == 0) || (strcmp(s, "while") == 0))
135 {
136 levelCurrent +=1;
137 chAttr = SCE_AVE_STATEMENT;
138 }
139
140 if (strcmp(s, "end") == 0)
141 {
142 levelCurrent -=1;
143 chAttr = SCE_AVE_STATEMENT;
144 }
145
146 if ( (strcmp(s, "then") == 0) || (strcmp(s, "else") == 0) || (strcmp(s, "break") == 0) ||
147 (strcmp(s, "each") == 0) ||
148 (strcmp(s, "exit") == 0) || (strcmp(s, "continue") == 0) || (strcmp(s, "return") == 0) ||
149 (strcmp(s, "by") == 0) || (strcmp(s, "in") == 0) || (strcmp(s, "elseif") == 0))
150 {
151 chAttr = SCE_AVE_STATEMENT;
152 }
153
154 if ((strcmp(s, "av") == 0) || (strcmp(s, "self") == 0))
155 {
156 chAttr = SCE_AVE_KEYWORD;
157 }
158
159 if (keywords.InList(s))
160 {
161 chAttr = SCE_AVE_WORD;
162 }
163 }
164 styler.ColourTo(end, chAttr);
165 state = SCE_AVE_DEFAULT;
166
167 if (ch == '\'') {
168 state = SCE_AVE_COMMENT;
169 } else if (ch == '\"') {
170 state = SCE_AVE_STRING;
171 } else if (isoperator(ch)) {
172 styler.ColourTo(i, SCE_AVE_OPERATOR);
173 }
174 }
175 }
176
177 }
178 styler.ColourTo(lengthDoc - 1, state);
179
180 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
181 if (fold) {
182 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
183 styler.SetLevel(lineCurrent, levelPrev | flagsNext);
184
185 }
186 }
187
188 LexerModule lmAVE(SCLEX_AVE, ColouriseAveDoc, "ave");