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
)
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.map
show_one) >> Gen.process
)
54 (fun (str,props) -> match P.parse_string str with
55 | Some ((k,n,placeholders) as stmt) ->
56 (*Error.logs (Show.show<Stmt.Raw.parsed> stmt); *)
57 Some
(k
,n
,placeholders
,props
,str
)
58 | None
-> Error.log
"Failed to parse : %s" str
; None
)
62 Gen.process
(Stmt.resolve
stmts)
66 Error.log
"SQL to C++ Code Generator Version %s (%s)" Version.version
(Version.revision
>> S.explode
>> L.take
8 >> S.implode
);
68 Error.log
" Usage: %s file_with_statements.sql" (Filename.basename
Sys.executable_name
);
70 Error.log
" Parse given file (treating content as SQL statements) and emit corresponding code to stdout"
73 match Array.to_list
Sys.argv
with
74 | _
::"-test"::_
-> Test.run
()
75 | _
::[file
] -> work file
78 let _ = Printexc.print
main ()