1
(* $Id: xmlcompile.ml 675 2004-06-13 16:03:16Z gerd $
2
* ----------------------------------------------------------------------
11
let error_happened = ref false;;
13
let rec prerr_error e =
14
prerr_endline (string_of_exn e)
21
prerr_endline ("WARNING: " ^ w)
26
let compile in_filename out_filename print super_root pis comments =
28
let e = new element_impl default_extension in
29
make_spec_from_mapping
30
~super_root_exemplar: (new super_root_impl default_extension)
31
~default_pinstr_exemplar: (new pinstr_impl default_extension)
32
~comment_exemplar: (new comment_impl default_extension)
33
~data_exemplar: (new data_impl default_extension)
34
~default_element_exemplar: e
35
~element_mapping: (Hashtbl.create 1)
42
enable_super_root_node = super_root;
43
enable_pinstr_nodes = pis;
44
enable_comment_nodes = comments;
51
(from_file in_filename)
55
let ch = open_out out_filename in
56
Pxp_codewriter.write_document ch tree;
57
output_string ch "(create_document { Pxp_yacc.default_config with Pxp_yacc.encoding = `Enc_utf8 } Pxp_yacc.default_spec) # write (`Out_channel stdout) `Enc_utf8;;\n";
61
tree # write (`Out_channel stdout) `Enc_utf8;
64
error_happened := true;
70
let in_file = ref "" in
71
let out_file = ref "" in
72
let print_file = ref false in
73
let super_root = ref false in
74
let pis = ref false in
75
let comments = ref false in
77
[ "-in", (Arg.String (fun s -> in_file := s)),
78
" <file> Set the XML file to read";
79
"-out", (Arg.String (fun s -> out_file := s)),
80
" <file> Set the Ocaml file to write";
81
"-print", (Arg.Set print_file),
82
" Print the XML file in standard form";
83
"-super-root", Arg.Set super_root,
84
" Generate a super root node";
86
" Generate wrapper nodes for processing instructions";
87
"-comments", Arg.Set comments,
88
" Generate nodes for comments";
90
(fun x -> raise (Arg.Bad "Unexpected argument"))
92
usage: compile [ options ]
95
if !in_file = "" then begin
96
prerr_endline "No input file specified.";
99
if !out_file = "" then begin
100
prerr_endline "No output file specified.";
103
compile !in_file !out_file !print_file !super_root !pis !comments
108
if !error_happened then exit(1);;