-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.mll
55 lines (51 loc) · 3.04 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
{
open Parser
exception Error of Lexing.position * string
}
rule token = parse
| [' ' '\t'] { token lexbuf }
| '\n' { Lexing.new_line lexbuf; token lexbuf }
| '\\' { BACKSLASH }
| '|' { BAR }
| '.' { DOT }
| ':' { COLON }
| '*' { STAR }
| "->" { ARROW }
| "Nat" { NAT }
| "Data" { DATA }
| "Forall" { FORALL }
| "Sigma" { SIGMA }
| "Succ" { SUCC }
| "Zero" { ZERO }
| "Refl" { REFL }
| "Fst" { FST }
| "Snd" { SND }
| "where" { WHERE }
| "nat_elim" { NATELIM }
| "eq_elim" { EQELIM }
| "sum_elim" { SUMELIM }
| "inl" { INL }
| "inr" { INR }
| "Type" { TYPE }
| "Normalize" { CMDNORMAL }
| '<' { LANGLE }
| '>' { RANGLE }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LCURLY }
| '}' { RCURLY }
| ',' { COMMA }
| "::" { DOUBLECOLON }
| ";;" { DOUBLESEMI }
| '=' { EQ }
| ":=" { COLONEQ }
| '#' [^'\n']* '\n' { Lexing.new_line lexbuf; token lexbuf }
| '#' [^'\n']* eof { EOF }
| eof { EOF }
(* expression variables are restricted to start with lowercase letter or underscore *)
| ['0'-'9']+ as x { LEVEL (int_of_string x) }
| ['a'-'z''A'-'Z''0'-'9''\'''_']+ as x { ID x }
| _ {
let msg = Printf.sprintf "unexpected character %C" (Lexing.lexeme_char lexbuf 0)
in raise (Error (Lexing.lexeme_start_p lexbuf, msg))
}