Merge branch 'handle-stdout'
[SXSI/xpathcomp.git] / src / lextest.ml
1 (* Abstract type for the index, generated from C++ code *)
2
3 type index
4
5 external build_lex_index : Tree.tree_pointer -> Tag.t -> index = "caml_build_lex_index"
6
7 external print_lex_index : index -> unit = "caml_print_lex_index"
8
9
10 let main () =
11   if Array.length Sys.argv != 3 then
12   let () = Printf.eprintf "Error: invalid argument" in exit 1
13   else
14   let file = Sys.argv.(1) in
15   (* Load the index or the xml file *)
16   Printf.printf "Loading document\n%!";
17   let document =
18     if Filename.check_suffix file ".srx"
19     then Tree.load file
20     else if Filename.check_suffix file ".xml" then Tree.parse_xml_uri file
21     else
22     let () = Printf.eprintf "Error: unrecognized extension" in exit 2
23   in
24   Tag.init (Tree.tag_operations document);
25   Printf.printf "Building lex index for tag %s\n%!" (Tag.to_string (Tag.tag Sys.argv.(2)));
26   let index = build_lex_index (Tree.get_tree_pointer document) (Tag.tag Sys.argv.(2)) in
27   Printf.printf "Printing lex index\n%!";
28   print_lex_index index;
29   exit 0
30
31
32 let () =
33   try
34     main ()
35   with
36     e -> Printf.eprintf "Fatal error: %s" (Printexc.to_string e); exit 3
37