-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudon.lex
54 lines (42 loc) · 1.24 KB
/
udon.lex
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
structure Tokens = Tokens
open Tokens
type pos = unit
type svalue = svalue
type ('a, 'b) token = ('a, 'b) token
type lexresult = (svalue, pos) token
fun eof () = SEMICOLON((),())
fun error (e, pos, _) = (print e; print "\n")
%%
%header (functor UdonLexFun(structure Tokens : Udon_TOKENS));
space=[\ \t\n\r];
digit=[0-9];
letter=[a-z];
alpha=[A-Za-z];
%%
"case" => (CASE((),()));
"else" => (ELSE((),()));
"end" => (END((),()));
"fn" => (FN((),()));
"if" => (IF((),()));
"in" => (IN((),()));
"infix" => (INFIX((),()));
"infixr" => (INFIXR((),()));
"let" => (LET((),()));
"nonfix" => (NONFIX((),()));
"of" => (OF((),()));
"op" => (OP((),()));
"rec" => (REC((),()));
"then" => (THEN((),()));
"val" => (VAL((),()));
"true" => (BOOL(true,(),()));
"false" => (BOOL(false,(),()));
"=" => (EQUAL((),()));
"," => (COMMA((),()));
"(" => (LPAREN((),()));
")" => (RPAREN((),()));
"=>" => (FATARROW((),()));
";" => (SEMICOLON((),()));
"~"? {digit}+ => (DIGIT(valOf(Int.fromString yytext),(),()));
{letter} ({alpha} | {digit} | "'" | "_")* => (IDENT(yytext,(),()));
("!" | "%" | "&" | "$" | "#" | "+" | "-" | "/" | ":" | "<" | "=" | ">" | "?" | "@" | "\\" | "~" | "`" | "^" | "|" | "*")+ => (IDENT(yytext,(),()));
{space}+ => (lex()(* skip spaces and continue lexing *));