-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.mll
41 lines (39 loc) · 1.34 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
{
open Parser
}
let digit = ['0'-'9']
let lowercase_letter = ['a'-'z']
let uppercase_letter = ['A'-'Z']
let letter = lowercase_letter | uppercase_letter
let atom = lowercase_letter (letter | digit | '_')*
let var = ( uppercase_letter (letter | digit)* ) | '_'
let action = atom '.' (atom | '.')+
rule token = parse
['\r' '\n'] { Lexing.new_line lexbuf; token lexbuf }
| [' ' '\t'] { token lexbuf }
| "do" { DO }
| digit+ as lxm { NUMBER (int_of_string lxm) }
| var as lxm { VARIABLE lxm }
| atom as lxm { ATOM lxm }
| action as lxm { ACTION lxm }
| "\"" ([^ '"'])* "\"" as lxm { STRING (String.sub lxm 1 (String.length lxm - 2)) }
| "<-" { LARROW }
| '(' { LPAR }
| ')' { RPAR }
| '[' { LBRACK }
| ']' { RBRACK }
| '+' { PLUS }
| '-' { MINUS }
| '*' { MUL }
| '/' { DIV }
| '&' { AMPERSAND }
| '|' { PIPE }
| '!' { EMARK }
| "!!" { EMARK2 }
| "?" { QMARK }
| "??" { QMARK2 }
| ',' { COMMA }
| '.' { PERIOD }
| ';' { SEMICOLON }
| ':' { COLON }
| eof { EOF }