]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSmalltalk.cxx
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 | lexTable classificationBlock charClasses |
24 charClasses := #(#DecDigit #Letter #Special #Upper #BinSel).
25 lexTable := ByteArray new: 128.
26 classificationBlock := [ :charClass :chars |
28 flag := 1 bitShift: (charClasses indexOf: charClass) - 1.
29 chars do: [ :char | lexTable at: char codePoint + 1 put: ((lexTable at: char codePoint + 1) bitOr: flag)]].
32 value: #DecDigit value: '0123456789';
33 value: #Letter value: '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
34 value: #Special value: '()[]{};.^:';
35 value: #BinSel value: '~@%&*-+=|\/,<>?!';
36 value: #Upper value: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
38 ((String new: 500) streamContents: [ :stream |
39 stream crLf; nextPutAll: 'static int ClassificationTable[256] = {'.
40 lexTable keysAndValuesDo: [ :index :value |
41 ((index - 1) rem: 16) == 0 ifTrue: [
46 index ~= 256 ifTrue: [
48 stream crLf; nextPutAll: '};'; crLf.
50 charClasses keysAndValuesDo: [ :index :name |
54 ('static inline bool is<1s>(int ch) {return (ch > 0) && (ch %< 0x80) && ((ClassificationTable[ch] & <2p>) != 0);}')
55 expandMacrosWith: name with: (1 bitShift: (index - 1)))
61 static int ClassificationTable
[256] = {
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 16, 0, 0, 0, 16, 16, 0, 4, 4, 16, 16, 16, 16, 4, 16,
65 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 16, 16, 16, 16,
66 16, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
67 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 16, 4, 4, 2,
68 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
69 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 16, 4, 16, 0,
72 static inline bool isDecDigit(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 1) != 0);}
73 static inline bool isLetter(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 2) != 0);}
74 static inline bool isSpecial(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 4) != 0);}
75 static inline bool isUpper(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 8) != 0);}
76 static inline bool isBinSel(int ch
) {return (ch
> 0) && (ch
< 0x80) && ((ClassificationTable
[ch
] & 16) != 0);}
79 static inline bool isAlphaNumeric(int ch
) {
80 return isDecDigit(ch
) || isLetter(ch
);
83 static inline bool isDigitOfRadix(int ch
, int radix
)
86 return (ch
- '0') < radix
;
87 else if (!isUpper(ch
))
90 return (ch
- 'A' + 10) < radix
;
93 static inline void skipComment(StyleContext
& sc
)
95 while (sc
.More() && sc
.ch
!= '\"')
99 static inline void skipString(StyleContext
& sc
)
103 if (sc
.chNext
!= '\'')
111 static void handleHash(StyleContext
& sc
)
113 if (isSpecial(sc
.chNext
)) {
114 sc
.SetState(SCE_ST_SPECIAL
);
118 sc
.SetState(SCE_ST_SYMBOL
);
125 if (isLetter(sc
.ch
)) {
126 while (isAlphaNumeric(sc
.chNext
) || sc
.chNext
== ':')
129 else if (isBinSel(sc
.ch
)) {
130 while (isBinSel(sc
.chNext
))
136 static inline void handleSpecial(StyleContext
& sc
)
138 if (sc
.ch
== ':' && sc
.chNext
== '=') {
139 sc
.SetState(SCE_ST_ASSIGN
);
144 sc
.SetState(SCE_ST_RETURN
);
146 sc
.SetState(SCE_ST_SPECIAL
);
150 static inline void skipInt(StyleContext
& sc
, int radix
)
152 while (isDigitOfRadix(sc
.chNext
, radix
))
156 static void handleNumeric(StyleContext
& sc
)
162 sc
.SetState(SCE_ST_NUMBER
);
163 num
[0] = static_cast<char>(sc
.ch
);
165 while (isDecDigit(sc
.chNext
)) {
166 num
[nl
++] = static_cast<char>(sc
.chNext
);
168 if (nl
+1 == sizeof(num
)/sizeof(num
[0])) // overrun check
171 if (sc
.chNext
== 'r') {
174 radix
= atoi(num
+ 1);
178 if (sc
.chNext
== '-')
184 if (sc
.chNext
!= '.' || !isDigitOfRadix(sc
.GetRelative(2), radix
))
188 if (sc
.chNext
== 's') {
191 while (isDecDigit(sc
.chNext
))
195 else if (sc
.chNext
!= 'e' && sc
.chNext
!= 'd' && sc
.chNext
!= 'q')
198 if (sc
.chNext
== '+' || sc
.chNext
== '-')
203 static inline void handleBinSel(StyleContext
& sc
)
205 sc
.SetState(SCE_ST_BINARY
);
206 while (isBinSel(sc
.chNext
))
210 static void handleLetter(StyleContext
& sc
, WordList
* specialSelectorList
)
215 bool doubleColonPresent
;
217 sc
.SetState(SCE_ST_DEFAULT
);
219 ident
[0] = static_cast<char>(sc
.ch
);
221 while (isAlphaNumeric(sc
.chNext
)) {
222 ident
[il
++] = static_cast<char>(sc
.chNext
);
224 if (il
+2 == sizeof(ident
)/sizeof(ident
[0])) // overrun check
228 if (sc
.chNext
== ':') {
229 doubleColonPresent
= true;
234 doubleColonPresent
= false;
237 if (specialSelectorList
->InList(ident
))
238 state
= SCE_ST_SPEC_SEL
;
239 else if (doubleColonPresent
)
240 state
= SCE_ST_KWSEND
;
241 else if (isUpper(ident
[0]))
242 state
= SCE_ST_GLOBAL
;
244 if (!strcmp(ident
, "self"))
246 else if (!strcmp(ident
, "super"))
247 state
= SCE_ST_SUPER
;
248 else if (!strcmp(ident
, "nil"))
250 else if (!strcmp(ident
, "true") || !strcmp(ident
, "false"))
253 state
= SCE_ST_DEFAULT
;
256 sc
.ChangeState(state
);
259 static void colorizeSmalltalkDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*wordLists
[], Accessor
&styler
)
261 StyleContext
sc(startPos
, length
, initStyle
, styler
);
263 if (initStyle
== SCE_ST_COMMENT
) {
268 else if (initStyle
== SCE_ST_STRING
) {
274 for (; sc
.More(); sc
.Forward()) {
279 sc
.SetState(SCE_ST_COMMENT
);
283 else if (ch
== '\'') {
284 sc
.SetState(SCE_ST_STRING
);
290 else if (ch
== '$') {
291 sc
.SetState(SCE_ST_CHARACTER
);
294 else if (isSpecial(ch
))
296 else if (isDecDigit(ch
))
298 else if (isLetter(ch
))
299 handleLetter(sc
, wordLists
[0]);
300 else if (isBinSel(ch
)) {
301 if (ch
== '-' && isDecDigit(sc
.chNext
))
307 sc
.SetState(SCE_ST_DEFAULT
);
312 static const char* const smalltalkWordListDesc
[] = {
317 LexerModule
lmSmalltalk(SCLEX_SMALLTALK
, colorizeSmalltalkDoc
, "smalltalk", NULL
, smalltalkWordListDesc
);