show version in generated code
[sqlgg.git] / main.ml
blobe517f43bde8877fef692d9a954784fe760f84b2c
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 prerr_endline (Printexc.to_string exn);
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 s >> statements >> L.map parse_one
40 >> L.filter_valid
41 (* >> tee (L.iter show_one) *)
42 >> Gen.process
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