gen xml
[sqlgg.git] / gen_xml.ml
blobbda61ec46c01f36310f3843b2c426fd17f14b1e8
1 (* OCaml code generation *)
3 open ExtList
4 open ExtString
5 open Operators
6 open Printf
8 open Stmt
9 open Gen
10 open Sql
12 (* let escape = String.replace_chars (function '\n' -> "
" | '\r' -> "" | '"' -> "&" | c -> String.make 1 c) *)
13 let escape x = x
15 let comment x fmt = Printf.ksprintf (ignore) fmt
17 let value n t = Xml.Element ("value",["name",n; "type",t;],[])
19 let param_type_to_string t = Option.map_default Type.to_string "Any" t
20 let params_to_values = List.mapi (fun i (n,t) -> value (param_name_to_string n i) (param_type_to_string t))
21 let params_to_values = List.unique & params_to_values
23 let scheme_to_values = List.map (fun attr -> value "" (Type.to_string attr.RA.domain))
25 type t = Xml.xml list ref
27 let start () = ref []
29 let generate_code x index scheme params kind props =
30 let name = choose_name props kind index in
31 let input = Xml.Element ("in",[],params_to_values params) in
32 let output = Xml.Element ("out",[],scheme_to_values scheme) in
33 let sql = escape (get_sql props kind params) in
34 x:= Xml.Element ("stmt",["name",name; "sql",sql;],[input; output]) :: !x
36 let start_output x = ()
38 let finish_output x =
39 Xml.Element ("sqlgg",[],!x) >> Xml.to_string_fmt >> print_endline;
40 x := []