1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
// Scintilla source code edit control
/** @file LexSmalltalk.cxx
** Lexer for Smalltalk language.
** Written by Sergey Philippov, sphilippov-at-gmail-dot-com
**/
// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "Platform.h"
#include "PropSet.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "KeyWords.h"
#include "Scintilla.h"
#include "SciLexer.h"
/*
| lexTable classificationBlock charClasses |
charClasses := #(#DecDigit #Letter #Special #Upper #BinSel).
lexTable := ByteArray new: 128.
classificationBlock := [ :charClass :chars |
| flag |
flag := 1 bitShift: (charClasses indexOf: charClass) - 1.
chars do: [ :char | lexTable at: char codePoint + 1 put: ((lexTable at: char codePoint + 1) bitOr: flag)]].
classificationBlock
value: #DecDigit value: '0123456789';
value: #Letter value: '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPTQRSTUVWXYZ';
value: #Special value: '()[]{};.^:';
value: #BinSel value: '~@%&*-+=|\/,<>?!';
value: #Upper value: 'ABCDEFGHIJKLMNOPTQRSTUVWXYZ'.
((String new: 500) streamContents: [ :stream |
stream crLf; nextPutAll: 'static int ClassificationTable[256] = {'.
lexTable keysAndValuesDo: [ :index :value |
((index - 1) rem: 16) == 0 ifTrue: [
stream crLf; tab]
ifFalse: [
stream space].
stream print: value.
index ~= 256 ifTrue: [
stream nextPut: $,]].
stream crLf; nextPutAll: '};'; crLf.
charClasses keysAndValuesDo: [ :index :name |
stream
crLf;
nextPutAll: (
('static inline bool is<1s>(int ch) {return (ch > 0) && (ch %< 0x80) && ((ClassificationTable[ch] & <2p>) != 0);}')
expandMacrosWith: name with: (1 bitShift: (index - 1)))
]]) edit
*/
// autogenerated {{{{
static int ClassificationTable[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 16, 0, 0, 0, 16, 16, 0, 4, 4, 16, 16, 16, 16, 4, 16,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 16, 16, 16, 16,
16, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 16, 4, 4, 2,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 16, 4, 16, 0,
};
static inline bool isDecDigit(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 1) != 0);}
static inline bool isLetter(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 2) != 0);}
static inline bool isSpecial(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 4) != 0);}
static inline bool isUpper(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 8) != 0);}
static inline bool isBinSel(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 16) != 0);}
// autogenerated }}}}
static inline bool isAlphaNumeric(int ch) {
return isDecDigit(ch) || isLetter(ch);
}
static inline bool isDigitOfRadix(int ch, int radix)
{
if (isDecDigit(ch))
return (ch - '0') < radix;
else if (!isUpper(ch))
return false;
else
return (ch - 'A' + 10) < radix;
}
static inline void skipComment(StyleContext& sc)
{
while (sc.More() && sc.ch != '\"')
sc.Forward();
}
static inline void skipString(StyleContext& sc)
{
while (sc.More()) {
if (sc.ch == '\'') {
if (sc.chNext != '\'')
return;
sc.Forward();
}
sc.Forward();
}
}
static void handleHash(StyleContext& sc)
{
if (isSpecial(sc.chNext)) {
sc.SetState(SCE_ST_SPECIAL);
return;
}
sc.SetState(SCE_ST_SYMBOL);
sc.Forward();
if (sc.ch == '\'') {
sc.Forward();
skipString(sc);
}
else {
if (isLetter(sc.ch)) {
while (isAlphaNumeric(sc.chNext) || sc.chNext == ':')
sc.Forward();
}
else if (isBinSel(sc.ch)) {
while (isBinSel(sc.chNext))
sc.Forward();
}
}
}
static inline void handleSpecial(StyleContext& sc)
{
if (sc.ch == ':' && sc.chNext == '=') {
sc.SetState(SCE_ST_ASSIGN);
sc.Forward();
}
else {
if (sc.ch == '^')
sc.SetState(SCE_ST_RETURN);
else
sc.SetState(SCE_ST_SPECIAL);
}
}
static inline void skipInt(StyleContext& sc, int radix)
{
while (isDigitOfRadix(sc.chNext, radix))
sc.Forward();
}
static void handleNumeric(StyleContext& sc)
{
char num[256];
int nl;
int radix;
sc.SetState(SCE_ST_NUMBER);
num[0] = static_cast<char>(sc.ch);
nl = 1;
while (isDecDigit(sc.chNext)) {
num[nl++] = static_cast<char>(sc.chNext);
sc.Forward();
if (nl+1 == sizeof(num)/sizeof(num[0])) // overrun check
break;
}
if (sc.chNext == 'r') {
num[nl] = 0;
if (num[0] == '-')
radix = atoi(num + 1);
else
radix = atoi(num);
sc.Forward();
if (sc.chNext == '-')
sc.Forward();
skipInt(sc, radix);
}
else
radix = 10;
if (sc.chNext != '.' || !isDigitOfRadix(sc.GetRelative(2), radix))
return;
sc.Forward();
skipInt(sc, radix);
if (sc.chNext == 's') {
// ScaledDecimal
sc.Forward();
while (isDecDigit(sc.chNext))
sc.Forward();
return;
}
else if (sc.chNext != 'e' && sc.chNext != 'd' && sc.chNext != 'q')
return;
sc.Forward();
if (sc.chNext == '+' || sc.chNext == '-')
sc.Forward();
skipInt(sc, radix);
}
static inline void handleBinSel(StyleContext& sc)
{
sc.SetState(SCE_ST_BINARY);
while (isBinSel(sc.chNext))
sc.Forward();
}
static void handleLetter(StyleContext& sc, WordList* specialSelectorList)
{
char ident[256];
int il;
int state;
bool doubleColonPresent;
sc.SetState(SCE_ST_DEFAULT);
ident[0] = static_cast<char>(sc.ch);
il = 1;
while (isAlphaNumeric(sc.chNext)) {
ident[il++] = static_cast<char>(sc.chNext);
sc.Forward();
if (il+2 == sizeof(ident)/sizeof(ident[0])) // overrun check
break;
}
if (sc.chNext == ':') {
doubleColonPresent = true;
ident[il++] = ':';
sc.Forward();
}
else
doubleColonPresent = false;
ident[il] = 0;
if (specialSelectorList->InList(ident))
state = SCE_ST_SPEC_SEL;
else if (doubleColonPresent)
state = SCE_ST_KWSEND;
else if (isUpper(ident[0]))
state = SCE_ST_GLOBAL;
else {
if (!strcmp(ident, "self"))
state = SCE_ST_SELF;
else if (!strcmp(ident, "super"))
state = SCE_ST_SUPER;
else if (!strcmp(ident, "nil"))
state = SCE_ST_NIL;
else if (!strcmp(ident, "true") || !strcmp(ident, "false"))
state = SCE_ST_BOOL;
else
state = SCE_ST_DEFAULT;
}
sc.ChangeState(state);
}
static void colorizeSmalltalkDoc(unsigned int startPos, int length, int initStyle, WordList *wordLists[], Accessor &styler)
{
StyleContext sc(startPos, length, initStyle, styler);
if (initStyle == SCE_ST_COMMENT) {
skipComment(sc);
if (sc.More())
sc.Forward();
}
else if (initStyle == SCE_ST_STRING) {
skipString(sc);
if (sc.More())
sc.Forward();
}
for (; sc.More(); sc.Forward()) {
int ch;
ch = sc.ch;
if (ch == '\"') {
sc.SetState(SCE_ST_COMMENT);
sc.Forward();
skipComment(sc);
}
else if (ch == '\'') {
sc.SetState(SCE_ST_STRING);
sc.Forward();
skipString(sc);
}
else if (ch == '#')
handleHash(sc);
else if (ch == '$') {
sc.SetState(SCE_ST_CHARACTER);
sc.Forward();
}
else if (isSpecial(ch))
handleSpecial(sc);
else if (isDecDigit(ch))
handleNumeric(sc);
else if (isLetter(ch))
handleLetter(sc, wordLists[0]);
else if (isBinSel(ch)) {
if (ch == '-' && isDecDigit(sc.chNext))
handleNumeric(sc);
else
handleBinSel(sc);
}
else
sc.SetState(SCE_ST_DEFAULT);
}
sc.Complete();
}
static const char* const smalltalkWordListDesc[] = {
"Special selectors",
0
};
LexerModule lmSmalltalk(SCLEX_SMALLTALK, colorizeSmalltalkDoc, "smalltalk", NULL, smalltalkWordListDesc);
|