*** empty log message ***
[anjuta-git-plugin.git] / scintilla / LexBullant.cxx
blob902f89c1e481b34037dec8d71cac87aeb559e046
1 // SciTE - Scintilla based Text Editor
2 // LexBullant.cxx - lexer for Bullant
4 #include <stdlib.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <stdarg.h>
10 #include "Platform.h"
12 #include "PropSet.h"
13 #include "Accessor.h"
14 #include "KeyWords.h"
15 #include "Scintilla.h"
16 #include "SciLexer.h"
19 static int classifyWordBullant(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
20 char s[100];
21 for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
22 s[i] = static_cast<char>(tolower(styler[start + i]));
23 s[i + 1] = '\0';
25 int lev= 0;
26 char chAttr = SCE_C_IDENTIFIER;
27 if (isdigit(s[0]) || (s[0] == '.')){
28 chAttr = SCE_C_NUMBER;
30 else {
31 if (keywords.InList(s)) {
32 chAttr = SCE_C_WORD;
33 if (strcmp(s, "end") == 0)
34 lev = -1;
35 else if (strcmp(s, "method") == 0 ||
36 strcmp(s, "case") == 0 ||
37 strcmp(s, "class") == 0 ||
38 strcmp(s, "debug") == 0 ||
39 strcmp(s, "test") == 0 ||
40 strcmp(s, "if") == 0 ||
41 strcmp(s, "lock") == 0 ||
42 strcmp(s, "transaction") == 0 ||
43 strcmp(s, "trap") == 0 ||
44 strcmp(s, "until") == 0 ||
45 strcmp(s, "while") == 0)
46 lev = 1;
49 styler.ColourTo(end, chAttr);
50 return lev;
53 static void ColouriseBullantDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
54 Accessor &styler) {
55 WordList &keywords = *keywordlists[0];
57 styler.StartAt(startPos);
59 bool fold = styler.GetPropertyInt("fold") != 0;
60 int lineCurrent = styler.GetLine(startPos);
61 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
62 int levelCurrent = levelPrev;
64 int state = initStyle;
65 if (state == SCE_C_STRINGEOL) // Does not leak onto next line
66 state = SCE_C_DEFAULT;
67 char chPrev = ' ';
68 char chNext = styler[startPos];
69 unsigned int lengthDoc = startPos + length;
70 int visibleChars = 0;
71 styler.StartSegment(startPos);
72 int endFoundThisLine = 0;
73 for (unsigned int i = startPos; i < lengthDoc; i++) {
74 char ch = chNext;
75 chNext = styler.SafeGetCharAt(i + 1);
77 if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
78 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
79 // Avoid triggering two times on Dos/Win
80 // End of line
81 endFoundThisLine = 0;
82 if (state == SCE_C_STRINGEOL) {
83 styler.ColourTo(i, state);
84 state = SCE_C_DEFAULT;
86 if (fold) {
87 int lev = levelPrev;
88 if (visibleChars == 0)
89 lev |= SC_FOLDLEVELWHITEFLAG;
90 if ((levelCurrent > levelPrev) && (visibleChars > 0))
91 lev |= SC_FOLDLEVELHEADERFLAG;
92 styler.SetLevel(lineCurrent, lev);
93 lineCurrent++;
94 levelPrev = levelCurrent;
96 visibleChars = 0;
98 /* int indentBlock = GetLineIndentation(lineCurrent);
99 if (blockChange==1){
100 lineCurrent++;
101 int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
102 } else if (blockChange==-1) {
103 indentBlock -= indentSize;
104 if (indentBlock < 0)
105 indentBlock = 0;
106 SetLineIndentation(lineCurrent, indentBlock);
107 lineCurrent++;
109 blockChange=0;
110 */ }
111 if (!isspace(ch))
112 visibleChars++;
114 if (styler.IsLeadByte(ch)) {
115 chNext = styler.SafeGetCharAt(i + 2);
116 chPrev = ' ';
117 i += 1;
118 continue;
121 if (state == SCE_C_DEFAULT) {
122 if (iswordstart(ch)) {
123 styler.ColourTo(i-1, state);
124 state = SCE_C_IDENTIFIER;
125 } else if (ch == '@' && chNext == 'o') {
126 if ((styler.SafeGetCharAt(i+2) =='f') && (styler.SafeGetCharAt(i+3) == 'f')) {
127 styler.ColourTo(i-1, state);
128 state = SCE_C_COMMENT;
130 } else if (ch == '#') {
131 styler.ColourTo(i-1, state);
132 state = SCE_C_COMMENTLINE;
133 } else if (ch == '\"') {
134 styler.ColourTo(i-1, state);
135 state = SCE_C_STRING;
136 } else if (ch == '\'') {
137 styler.ColourTo(i-1, state);
138 state = SCE_C_CHARACTER;
139 } else if (isoperator(ch)) {
140 styler.ColourTo(i-1, state);
141 styler.ColourTo(i, SCE_C_OPERATOR);
143 } else if (state == SCE_C_IDENTIFIER) {
144 if (!iswordchar(ch)) {
145 int levelChange = classifyWordBullant(styler.GetStartSegment(), i - 1, keywords, styler);
146 state = SCE_C_DEFAULT;
147 chNext = styler.SafeGetCharAt(i + 1);
148 if (ch == '#') {
149 state = SCE_C_COMMENTLINE;
150 } else if (ch == '\"') {
151 state = SCE_C_STRING;
152 } else if (ch == '\'') {
153 state = SCE_C_CHARACTER;
154 } else if (isoperator(ch)) {
155 styler.ColourTo(i, SCE_C_OPERATOR);
157 if (endFoundThisLine == 0)
158 levelCurrent+=levelChange;
159 if (levelChange == -1)
160 endFoundThisLine=1;
162 } else if (state == SCE_C_COMMENT) {
163 if (ch == '@' && chNext == 'o') {
164 if (styler.SafeGetCharAt(i+2) == 'n') {
165 styler.ColourTo(i+2, state);
166 state = SCE_C_DEFAULT;
167 i+=2;
170 } else if (state == SCE_C_COMMENTLINE) {
171 if (ch == '\r' || ch == '\n') {
172 endFoundThisLine = 0;
173 styler.ColourTo(i-1, state);
174 state = SCE_C_DEFAULT;
176 } else if (state == SCE_C_STRING) {
177 if (ch == '\\') {
178 if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
179 i++;
180 ch = chNext;
181 chNext = styler.SafeGetCharAt(i + 1);
183 } else if (ch == '\"') {
184 styler.ColourTo(i, state);
185 state = SCE_C_DEFAULT;
186 } else if (chNext == '\r' || chNext == '\n') {
187 endFoundThisLine = 0;
188 styler.ColourTo(i-1, SCE_C_STRINGEOL);
189 state = SCE_C_STRINGEOL;
191 } else if (state == SCE_C_CHARACTER) {
192 if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
193 endFoundThisLine = 0;
194 styler.ColourTo(i-1, SCE_C_STRINGEOL);
195 state = SCE_C_STRINGEOL;
196 } else if (ch == '\\') {
197 if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
198 i++;
199 ch = chNext;
200 chNext = styler.SafeGetCharAt(i + 1);
202 } else if (ch == '\'') {
203 styler.ColourTo(i, state);
204 state = SCE_C_DEFAULT;
207 chPrev = ch;
209 styler.ColourTo(lengthDoc - 1, state);
211 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
212 if (fold) {
213 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
214 //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
215 styler.SetLevel(lineCurrent, levelPrev | flagsNext);
220 static const char * const bullantWordListDesc[] = {
221 "Keywords",
225 LexerModule lmBullant(SCLEX_BULLANT, ColouriseBullantDoc, "bullant", 0, bullantWordListDesc);