]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/pxp/rtests/codewriter/compile.ml
Initial revision
[helm.git] / helm / DEVEL / pxp / pxp / rtests / codewriter / compile.ml
1 (* $Id$
2  * ----------------------------------------------------------------------
3  *
4  *)
5
6
7 open Pxp_document;;
8 open Pxp_yacc;;
9 open Pxp_types;;
10
11 let error_happened = ref false;;
12
13 let rec prerr_error e =
14   prerr_endline (string_of_exn e)
15 ;;
16
17
18 class warner =
19   object 
20     method warn w =
21       prerr_endline ("WARNING: " ^ w)
22   end
23 ;;
24
25
26 let compile in_filename out_filename print super_root pis comments =
27   let spec =
28     let e = new element_impl default_extension in
29     make_spec_from_mapping
30       ~super_root_exemplar:      e
31       ~default_pinstr_exemplar:  e
32       ~comment_exemplar:         e
33       ~data_exemplar:            (new data_impl default_extension)
34       ~default_element_exemplar: e
35       ~element_mapping:          (Hashtbl.create 1)
36       ()
37   in
38   let config =
39       { default_config with 
40           encoding = `Enc_utf8;
41           warner = new warner;
42           enable_super_root_node = super_root;
43           enable_pinstr_nodes = pis;
44           enable_comment_nodes = comments;
45       }
46   in
47   try 
48     let tree =
49       parse_document_entity
50         config
51         (from_file in_filename)
52         spec 
53     in
54     
55     let ch = open_out out_filename in
56     Pxp_codewriter.write_document ch tree;
57     output_string ch "(create_document (new Pxp_types.drop_warnings) Pxp_yacc.default_spec) # write (Pxp_types.Out_channel stdout) `Enc_utf8;;\n";
58     close_out ch;
59
60     if print then
61       tree # write (Out_channel stdout) `Enc_utf8;
62   with
63       e ->
64         error_happened := true;
65         prerr_error e
66 ;;
67
68
69 let main() =
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
76   Arg.parse
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";
85         "-pis", Arg.Set pis,
86              "            Generate wrapper nodes for processing instructions";
87         "-comments", Arg.Set comments,
88                   "       Generate nodes for comments";
89       ]
90       (fun x -> raise (Arg.Bad "Unexpected argument"))
91       "
92 usage: compile [ options ]
93
94 List of options:";
95   if !in_file = "" then begin
96     prerr_endline "No input file specified.";
97     exit 1
98   end;
99   if !out_file = "" then begin
100     prerr_endline "No output file specified.";
101     exit 1
102   end;
103   compile !in_file !out_file !print_file !super_root !pis !comments
104 ;;
105
106
107 main();
108 if !error_happened then exit(1);;
109
110 (* ======================================================================
111  * History:
112  * 
113  * $Log$
114  * Revision 1.1  2000/11/17 09:57:35  lpadovan
115  * Initial revision
116  *
117  * Revision 1.4  2000/08/17 01:20:15  gerd
118  *      Update: Also tested whether super root nodes, pinstr nodes
119  * and comment nodes work.
120  *      Note: comment nodes are not fully tested yet.
121  *
122  * Revision 1.3  2000/08/16 23:44:19  gerd
123  *      Updates because of changes of the PXP API.
124  *
125  * Revision 1.2  2000/07/16 17:54:15  gerd
126  *      Updated because of PXP interface changes.
127  *
128  * Revision 1.1  2000/07/09 00:33:32  gerd
129  *      Initial revision.
130  *
131  *)