14 let lexbuf = Lexing.from_string s
in
16 match (try Sql_lexer.ruleStatement
Props.empty
lexbuf with exn
-> None
) with
17 | Some x
-> loop (x
::l
)
22 let parse_one (stmt
,props
) =
25 Some
((Parser.parse_stmt stmt
), Props.set props
"sql" stmt
)
29 print_endline
(Printexc.to_string exn
);
33 let show_one ((s
,p
),props
) =
35 print_endline
(Show.show
<Stmt.Raw.params
>(p
))
37 let catch f x
= try Some
(f x
) with _
-> None
39 let with_file filename f
=
40 match catch Std.input_file filename
with
41 | None
-> Error.log
"cannot open file : %s" filename
47 with_file filename
(fun s
-> s
48 >> statements >> L.map
parse_one >> L.filter_valid
49 >> tee (L.iter
show_one) >> Gen.process
)
52 Error.log
"SQL to C++ Code Generator Version %s (%s)" Version.version
(Version.revision
>> S.explode
>> L.take
8 >> S.implode
);
54 Error.log
" Usage: %s file_with_statements.sql" (Filename.basename
Sys.executable_name
);
56 Error.log
" Parse given file (treating content as SQL statements) and emit corresponding code to stdout"
59 match Array.to_list
Sys.argv
with
60 | _
::"-test"::_
-> Test.run
()
61 | _
::[file
] -> work file
64 let _ = Printexc.print
main ()