tweak build
[sqlgg.git] / main.ml
blob7d66859145b7dc2f1b387f2b70b959e048cc26db
1 (*
2 Main
3 *)
5 open Printf
6 open Operators
7 open ListMore
8 open ExtString
9 open Apply
11 module L = List
12 module S = String
14 let statements s =
15 let lexbuf = Lexing.from_string s in
16 let rec loop l =
17 match (try Sql_lexer.ruleStatement Props.empty lexbuf with exn -> None) with
18 | Some x -> loop (x::l)
19 | None -> l
21 L.rev (loop [])
23 let parse_one (stmt,props) =
24 try
25 (* print_endline stmt; *)
26 Some ((Parser.parse_stmt stmt), Props.set props "sql" stmt)
27 with
28 | exn ->
29 begin
30 Error.log "==> %s" stmt;
31 None
32 end
34 let show_one ((s,p),props) =
35 RA.Scheme.print s;
36 print_endline (Stmt.params_to_string p)
38 let parse_sql s =
39 (* Tables.reset (); *)
40 s >> statements >> L.map parse_one
41 >> L.filter_valid
42 (* >> tee (L.iter show_one) *)
44 let with_file filename f =
45 match catch Std.input_file filename with
46 | None -> Error.log "cannot open file : %s" filename
47 | Some s -> f s