]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSmalltalk.cxx
265de380382a4538d64d889fc4f7b60fdb48a7ec
1 // Scintilla source code edit control
2 /** @file LexSmalltalk.cxx
3 ** Lexer for Smalltalk language.
4 ** Written by Sergey Philippov, sphilippov-at-gmail-dot-com
6 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
17 #include "StyleContext.h"
19 #include "Scintilla.h"
23 using namespace Scintilla
;
27 | lexTable classificationBlock charClasses |
28 charClasses := #(#DecDigit #Letter #Special #Upper #BinSel).
29 lexTable := ByteArray new: 128.
30 classificationBlock := [ :charClass :chars |
32 flag := 1 bitShift: (charClasses indexOf: charClass) - 1.
33 chars do: [ :char | lexTable at: char codePoint + 1 put: ((lexTable at: char codePoint + 1) bitOr: flag)]].
36 value: #DecDigit value: '0123456789';
37 value: #Letter value: '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
38 value: #Special value: '()[]{};.^:';
39 value: #BinSel value: '~@%&*-+=|\/,<>?!';
40 value: #Upper value: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
42 ((String new: 500) streamContents: [ :stream |
43 stream crLf; nextPutAll: 'static int ClassificationTable[256] = {'.
44 lexTable keysAndValuesDo: [ :index :value |
45 ((index - 1) rem: 16) == 0 ifTrue: [
50 index ~= 256 ifTrue: [
52 stream crLf; nextPutAll: '};'; crLf.
54 charClasses keysAndValuesDo: [ :index :name |
58 ('static inline bool is<1s>(int ch) {return (ch > 0) && (ch %< 0x80) && ((ClassificationTable[ch] & <2p>) != 0);}')
59 expandMacrosWith: name with: (1 bitShift: (index - 1)))
65 static int ClassificationTable
[256] = {
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 16, 0, 0, 0, 16, 16, 0, 4, 4, 16, 16, 16, 16, 4, 16,
69 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 16, 16, 16, 16,
70 16, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
71 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 16, 4, 4, 2,
72 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
73 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 16, 4, 16, 0,
76 static inline bool isDecDigit(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 1) != 0);}
77 static inline bool isLetter(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 2) != 0);}
78 static inline bool isSpecial(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 4) != 0);}
79 static inline bool isUpper(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 8) != 0);}
80 static inline bool isBinSel(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 16) != 0);}
83 static inline bool isAlphaNumeric(int ch
) {
84 return isDecDigit(ch
) || isLetter(ch
);
87 static inline bool isDigitOfRadix(int ch
, int radix
)
90 return (ch
- '0') < radix
;
91 else if (!isUpper(ch
))
94 return (ch
- 'A' + 10) < radix
;
97 static inline void skipComment(StyleContext
& sc
)
99 while (sc
.More() && sc
.ch
!= '\"')
103 static inline void skipString(StyleContext
& sc
)
107 if (sc
.chNext
!= '\'')
115 static void handleHash(StyleContext
& sc
)
117 if (isSpecial(sc
.chNext
)) {
118 sc
.SetState(SCE_ST_SPECIAL
);
122 sc
.SetState(SCE_ST_SYMBOL
);
129 if (isLetter(sc
.ch
)) {
130 while (isAlphaNumeric(sc
.chNext
) || sc
.chNext
== ':')
133 else if (isBinSel(sc
.ch
)) {
134 while (isBinSel(sc
.chNext
))
140 static inline void handleSpecial(StyleContext
& sc
)
142 if (sc
.ch
== ':' && sc
.chNext
== '=') {
143 sc
.SetState(SCE_ST_ASSIGN
);
148 sc
.SetState(SCE_ST_RETURN
);
150 sc
.SetState(SCE_ST_SPECIAL
);
154 static inline void skipInt(StyleContext
& sc
, int radix
)
156 while (isDigitOfRadix(sc
.chNext
, radix
))
160 static void handleNumeric(StyleContext
& sc
)
166 sc
.SetState(SCE_ST_NUMBER
);
167 num
[0] = static_cast<char>(sc
.ch
);
169 while (isDecDigit(sc
.chNext
)) {
170 num
[nl
++] = static_cast<char>(sc
.chNext
);
172 if (nl
+1 == sizeof(num
)/sizeof(num
[0])) // overrun check
175 if (sc
.chNext
== 'r') {
178 radix
= atoi(num
+ 1);
182 if (sc
.chNext
== '-')
188 if (sc
.chNext
!= '.' || !isDigitOfRadix(sc
.GetRelative(2), radix
))
192 if (sc
.chNext
== 's') {
195 while (isDecDigit(sc
.chNext
))
199 else if (sc
.chNext
!= 'e' && sc
.chNext
!= 'd' && sc
.chNext
!= 'q')
202 if (sc
.chNext
== '+' || sc
.chNext
== '-')
207 static inline void handleBinSel(StyleContext
& sc
)
209 sc
.SetState(SCE_ST_BINARY
);
210 while (isBinSel(sc
.chNext
))
214 static void handleLetter(StyleContext
& sc
, WordList
* specialSelectorList
)
219 bool doubleColonPresent
;
221 sc
.SetState(SCE_ST_DEFAULT
);
223 ident
[0] = static_cast<char>(sc
.ch
);
225 while (isAlphaNumeric(sc
.chNext
)) {
226 ident
[il
++] = static_cast<char>(sc
.chNext
);
228 if (il
+2 == sizeof(ident
)/sizeof(ident
[0])) // overrun check
232 if (sc
.chNext
== ':') {
233 doubleColonPresent
= true;
238 doubleColonPresent
= false;
241 if (specialSelectorList
->InList(ident
))
242 state
= SCE_ST_SPEC_SEL
;
243 else if (doubleColonPresent
)
244 state
= SCE_ST_KWSEND
;
245 else if (isUpper(ident
[0]))
246 state
= SCE_ST_GLOBAL
;
248 if (!strcmp(ident
, "self"))
250 else if (!strcmp(ident
, "super"))
251 state
= SCE_ST_SUPER
;
252 else if (!strcmp(ident
, "nil"))
254 else if (!strcmp(ident
, "true") || !strcmp(ident
, "false"))
257 state
= SCE_ST_DEFAULT
;
260 sc
.ChangeState(state
);
263 static void colorizeSmalltalkDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*wordLists
[], Accessor
&styler
)
265 StyleContext
sc(startPos
, length
, initStyle
, styler
);
267 if (initStyle
== SCE_ST_COMMENT
) {
272 else if (initStyle
== SCE_ST_STRING
) {
278 for (; sc
.More(); sc
.Forward()) {
283 sc
.SetState(SCE_ST_COMMENT
);
287 else if (ch
== '\'') {
288 sc
.SetState(SCE_ST_STRING
);
294 else if (ch
== '$') {
295 sc
.SetState(SCE_ST_CHARACTER
);
298 else if (isSpecial(ch
))
300 else if (isDecDigit(ch
))
302 else if (isLetter(ch
))
303 handleLetter(sc
, wordLists
[0]);
304 else if (isBinSel(ch
)) {
305 if (ch
== '-' && isDecDigit(sc
.chNext
))
311 sc
.SetState(SCE_ST_DEFAULT
);
316 static const char* const smalltalkWordListDesc
[] = {
321 LexerModule
lmSmalltalk(SCLEX_SMALLTALK
, colorizeSmalltalkDoc
, "smalltalk", NULL
, smalltalkWordListDesc
);