-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlexer.mll
62 lines (53 loc) · 1.57 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
{
open Parser
open Lexing
let incr_linenum lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <- { pos with
pos_lnum = pos.pos_lnum + 1;
pos_bol = pos.pos_cnum;
}
}
let var = ['_' 'a'-'z' 'A'-'Z'] ['_' 'a'-'z' 'A'-'Z' '0'-'9' '\'']*
rule token = parse
| '#' [^'\n']* '\n' { incr_linenum lexbuf; token lexbuf }
| '\n' { incr_linenum lexbuf; token lexbuf }
| [' ' '\t'] { token lexbuf }
| ['0'-'9']+ { INT (int_of_string(lexeme lexbuf)) }
| 'U' { TFORGET }
| 'F' { TFREE }
| "->" { ARROW }
| "bool" { TBOOL }
| "int" { TINT }
| "do" { DO }
| "else" { ELSE }
| "false" { FALSE }
| "force" { FORCE }
| "fun" { FUN }
| "if" { IF }
| "in" { IN }
| "is" { IS }
| "let" { LET }
| "rec" { REC }
| "return" { RETURN }
| "then" { THEN }
| "thunk" { THUNK }
| "to" { TO }
| "true" { TRUE }
| "$use" { USE }
| "$quit" { QUIT }
| ";;" { SEMICOLON2 }
| '\"' [^'\"']* '\"' { let str = lexeme lexbuf in
STRING (String.sub str 1 (String.length str - 2)) }
| '(' { LPAREN }
| ')' { RPAREN }
| '*' { TIMES }
| '+' { PLUS }
| '-' { MINUS }
| ':' { COLON }
| '<' { LESS }
| '=' { EQUAL }
| var { VAR (lexeme lexbuf) }
| eof { EOF }
{
}