forked from dbp/funtal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexer.mll
64 lines (59 loc) · 1.52 KB
/
lexer.mll
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
{
open Parser
exception Error of string * Lexing.position
let lexing_error lexbuf =
let invalid_input = String.make 1 (Lexing.lexeme_char lexbuf 0) in
raise (Error (invalid_input, lexbuf.Lexing.lex_curr_p))
let classify_identifier ident =
match ident.[0] with
| 'a' -> A_IDENTIFIER ident
| c -> if Char.compare c 'Z' > 0 then OTHER_IDENTIFIER ident else CAP_IDENTIFIER ident
}
let int_literal = ['0'-'9'] ['0'-'9']*
let blank = [' ' '\t']+
let newline = ('\r'* '\n')
let identifier = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_' '\'']*
rule token = parse
| newline { Lexing.new_line lexbuf; token lexbuf }
| blank+ { token lexbuf }
| int_literal { INTEGER (int_of_string (Lexing.lexeme lexbuf)) }
| "int" { INT }
| "bool" { BOOL }
| "." { DOT }
| "<" { LANGLE }
| "," { COMMA }
| ">" { RANGLE }
| "(" { LPAREN }
| ")" { RPAREN }
| "[" { LBRACKET }
| "]" { RBRACKET }
| "forall" { FORALL }
| "exists" { EXISTS }
| "{" { LBRACKET }
| "}" { RBRACKET }
| ":" { COLON }
| "true" { TRUE }
| "false" { FALSE }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "let" { LET }
| "in" { IN }
| "pi1" { PI1 }
| "pi2" { PI2 }
| "fst" { PI1 }
| "snd" { PI2 }
| "=" { EQUAL }
| "+" { PLUS }
| "-" { MINUS }
| "*" { TIMES }
| "lam" { LAMBDA }
| "Lam" { BIGLAMBDA }
| "pack" { PACK }
| "unpack" { UNPACK }
| "->" { ARROW }
| "=>" { CAST }
| "blame" { BLAME }
| identifier { classify_identifier (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ { lexing_error lexbuf }