-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_lexer.cmlex
45 lines (38 loc) · 921 Bytes
/
make_lexer.cmlex
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
sml
name MakeLexer
alphabet 128 /* 1024 is maximum */
set digit = (range '0 '9)
set digit_start = (range '1 '9)
set lower = (range 'a 'z)
set upper = (range 'A 'Z)
set alpha = (or lower upper)
set alphanumeric = (or digit alpha)
set ident = (or '_ alphanumeric)
set whitechar = (or 32 9 10) /* space, tab, lf */
function lex : t =
'= => equal
': => colon
'* => asterisk
', => comma
'/ => slash
'1 => one
(+ digit) => number
(seq '- '>) => rarrow
(seq '< '-) => larrow
'( => lparen
') => rparen
'[ => lbrack
'] => rbrack
"(|" => lwhiteparen
"|)" => rwhiteparen
"<|" => lwhiteangle
"|>" => rwhiteangle
":>" => seal
(seq lower (* ident) (* '')) => lower_ident
(seq upper (* ident) (* '')) => upper_ident
(seq '' lower (* ident)) => quote_ident
(seq '\ (* alphanumeric)) => backslash_ident
'. => dot
(+ whitechar) => whitespace
epsilon => illegal
eos => eof