remove old code
[sqlgg.git] / main.ml
blob58f283b3fbdc56c4db1b7b77539b8a6f480827bf
1 (*
2 Main
3 *)
5 open Printf
6 open Operators
7 open ListMore
8 open ExtString
10 module L = List
11 module S = String
13 let statements s =
14 let lexbuf = Lexing.from_string s in
15 let rec loop l =
16 match (try Sql_lexer.ruleStatement Props.empty lexbuf with exn -> None) with
17 | Some x -> loop (x::l)
18 | None -> l
20 L.rev (loop [])
22 let parse_one (stmt,props) =
23 try
24 (* print_endline stmt; *)
25 Some ((Parser.parse_stmt stmt), Props.set props "sql" stmt)
26 with
27 | exn ->
28 begin
29 prerr_endline (Printexc.to_string exn);
30 None
31 end
33 let show_one ((s,p),props) =
34 RA.Scheme.print s;
35 print_endline (Stmt.params_to_string p)
37 let catch f x = try Some (f x) with _ -> None
39 let tee f x = f x; x
41 let parse_sql s =
42 s >> statements >> L.map parse_one
43 >> L.filter_valid
44 (* >> tee (L.iter show_one) *)
45 >> Gen.process
47 let with_file filename f =
48 match catch Std.input_file filename with
49 | None -> Error.log "cannot open file : %s" filename
50 | Some s -> f s