File: ClassificationTable.st

package info (click to toggle)
scite 5.5.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,176 kB
  • sloc: cpp: 175,852; ansic: 21,482; python: 7,014; makefile: 934; sh: 257; perl: 252; ruby: 217; sql: 194; php: 63; vhdl: 51; erlang: 47; objc: 22; modula3: 21; cobol: 18; lisp: 18; asm: 17; fortran: 12; ml: 11; xml: 7; tcl: 6
file content (52 lines) | stat: -rw-r--r-- 1,897 bytes parent folder | download | duplicates (2)
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
" File contains examples of all SCE_ST_* lexical states 0-16 "
" Smalltalk code from the lexer that generates the character classification table."
| 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: '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    value: #Special value: '()[]{};.^:';
    value: #BinSel value: '~@%&*-+=|\/,<>?!';
    value: #Upper value: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

((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>(unsigned char ch) {return (ch %< 0x80) && ((ClassificationTable[ch] & <2p>) != 0);}')
                    expandMacrosWith: name with: (1 bitShift: (index - 1)))
    ]]) edit

" Some more syntax examples:
  ^ is return (SCE_ST_RETURN)
  true or false is bool (SCE_ST_BOOL)
  self (SCE_ST_SELF)
  super (SCE_ST_SUPER)
  nil (SCE_ST_NIL)
"
foo
  ^ Array with: 1 with: 2 with: false with: self with: super with: nil.

" Issue 274: A decimal separator is not required for scaled decimal numbers"
32.0s2
4.0e3
32s2
4e3