-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_lexer.cmlex
65 lines (57 loc) · 1.41 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 val_op_char = (or '+ '* '! '?)
set whitechar = (or 32 9 10) /* space, tab, lf */
function lex : t =
(seq digit_start (* digit)) => number
'0 => number
'" => string
'= => equal
': => colon
(seq ': '>) => colon_gt
(seq ': '=) => colon_eq
(seq ': ':) => colon_colon
'| => bar
'_ => underscore
'* => asterisk
', => comma
'$ => dollar
'+ => plus
'- => minus
'> => gt
'< => lt
(seq '> '=) => gt_eq
(seq '< '=) => lt_eq
(seq '> '> '>) => gt_gt_gt
(seq '< '< '<) => lt_lt_lt
(seq '= '=) => equal_equal
(seq '/ '=) => slash_equal
(seq '< '>) => lt_gt
(seq '< '+ '>) => lt_plus_gt
(seq '- '>) => rarrow
'( => lparen
') => rparen
'[ => lbrack
'] => rbrack
'{ => lbrace
'} => rbrace
(seq lower (* ident) (* '')) => lower_ident
(seq upper (* ident) (* '')) => upper_ident
(seq 'r '# lower (* ident) (* '')) => raw_ident
(seq '') => single_quote
(seq "val" (+ val_op_char)) => val_op
'` => backquote_ident
'. => dot
(+ whitechar) => whitespace
(seq '/ '/) => comment
(seq '0 (+ digit)) => leading_zero
epsilon => illegal
eos => eof