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
open Util
open Genlex
let store = Hashtbl.create 10
let required = ["asterisk_conf"; "test_call_conf";
"dbname"; "dbhost"; "dbuser";
"dbpass"; "default_host";
"default_port"; "peer_format"]
let file_lexer = make_lexer ["="; ";"; "\n"] $ Stream.of_channel $ open_in
let rec parse_conf = parser
[<'Ident name;'Kwd "=";'Ident value;'Kwd ";";'Kwd "\n"; rest >] ->
Hashtbl.add store name value; parse_conf rest
| [< >] -> ()
let parse_file = parse_conf $ file_lexer
let option = Hashtbl.find store
let check_config = flip (List.fold_right ((&&) $ (Hashtbl.mem store))) true
let init_config = (fun () -> if check_config required
then ()
else failwith "Not all required options are provided in config file!"
) $ parse_file