altos/scheme: Allow unicode in lexer
[fw/altos] / src / scheme / ao_scheme_char.scheme
1 ;
2 ; Copyright © 2018 Keith Packard <keithp@keithp.com>
3 ;
4 ; This program is free software; you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation, either version 2 of the License, or
7 ; (at your option) any later version.
8 ;
9 ; This program is distributed in the hope that it will be useful, but
10 ; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ; General Public License for more details.
13 ;
14 ; Char primitives placed in ROM
15
16 (define char? integer?)
17
18 (char? #\q)
19 (char? "h")
20
21 (define (char-upper-case? c) (<= #\A c #\Z))
22
23 (char-upper-case? #\a)
24 (char-upper-case? #\B)
25 (char-upper-case? #\0)
26 (char-upper-case? #\space)
27
28 (define (char-lower-case? c) (<= #\a c #\a))
29
30 (char-lower-case? #\a)
31 (char-lower-case? #\B)
32 (char-lower-case? #\0)
33 (char-lower-case? #\space)
34
35 (define (char-alphabetic? c) (or (char-upper-case? c) (char-lower-case? c)))
36
37 (char-alphabetic? #\a)
38 (char-alphabetic? #\B)
39 (char-alphabetic? #\0)
40 (char-alphabetic? #\space)
41
42 (define (char-numeric? c) (<= #\0 c #\9))
43
44 (char-numeric? #\a)
45 (char-numeric? #\B)
46 (char-numeric? #\0)
47 (char-numeric? #\space)
48
49 (define (char-whitespace? c) (or (<= #\tab c #\return) (= #\space c)))
50
51 (char-whitespace? #\a)
52 (char-whitespace? #\B)
53 (char-whitespace? #\0)
54 (char-whitespace? #\space)
55
56 (define char->integer (macro (v) v))
57 (define integer->char char->integer)
58
59 (define (char-upcase c) (if (char-lower-case? c) (+ c (- #\A #\a)) c))
60
61 (char-upcase #\a)
62 (char-upcase #\B)
63 (char-upcase #\0)
64 (char-upcase #\space)
65
66 (define (char-downcase c) (if (char-upper-case? c) (+ c (- #\a #\A)) c))
67
68 (char-downcase #\a)
69 (char-downcase #\B)
70 (char-downcase #\0)
71 (char-downcase #\space)
72
73 (define (digit-value c)
74   (if (char-numeric? c)
75       (- c #\0)
76       #f)
77   )
78
79 (digit-value #\1)
80 (digit-value #\a)