-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.mll
35 lines (32 loc) · 1.04 KB
/
scanner.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
(* Lexical analysis of chase input *)
{
open Parser
open Lexing
let keyword_table = Hashtbl.create 8
let () =
List.iter (fun (kwd, tok) -> Hashtbl.add keyword_table kwd tok)
[ "true", TRUE;
"false", FALSE ]
}
let start = ['a' - 'z' 'A' - 'Z']
let part = start | ['$' '_' '0' - '9']
rule token = parse
[' ' '\t'] { token lexbuf }
| ['\n'] { new_line lexbuf; token lexbuf }
| '%' [^ '\n']* { token lexbuf }
| "=>" { IMPLIES }
| '.' { PERIOD }
| ['|' ';'] { VBAR } (* Allow Prolog syntax too *)
| '&' { AMP }
| '=' { EQUAL }
| ',' { COMMA }
| '(' { LPAR }
| ')' { RPAR }
| '[' { LBRA }
| ']' { RBRA }
| ['0' - '9']+ as d { DIGITS (int_of_string d) }
| start part* as s { match Hashtbl.find_opt keyword_table s with
| None -> SYMBOL s
| Some t -> t }
| eof { EOF }
| _ { raise Parsing.Parse_error }