let arg2 = Sys.argv.(2) in
if arg2 = "-f"
then let fq = open_in Sys.argv.(3) in
- let rec list_qu fq list =
- try
- (match XPath.parse_file fq with
- | q -> list_qu fq (q::list)
- | _ -> list)
+ let rec list_qu fq list =
+ try let q = XPath.parse_file fq in
+ list_qu fq (q::list)
with _ -> list in
let list = list_qu fq [] in
close_in fq;
- fprintf err_formatter "Parse query OK ! ";
+ fprintf err_formatter "Parse query OK !\n %!";
list
else failwith "Use -f"
-let build_asta query =
- let asta = Compil.trans query in
- fprintf err_formatter "Compil OK ! ";
- asta
-
let compute_run doc query =
let run = Run.compute doc query in
- fprintf err_formatter "Run OK ! \n";
run
let () =
+ let flag = Array.length Sys.argv = 5 in
Format.pp_set_margin err_formatter 80;
let doc = doc () in
output_string stderr "##### Doc with positions #####\n";
Tree.print_xml_preorder stderr doc (Tree.root doc);
+ output_string stderr "\n";
let queries = query () in
+ let rec print_selec fmt l = match l with
+ | [x] -> fprintf fmt "%s" (string_of_int x)
+ | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl
+ | [] -> fprintf fmt "%s" "ø" in
let rec solve_queries = function
| [] -> ()
| query :: tl ->
- let asta = build_asta query in
+ let asta = Compil.trans query in
let selected_nodes = Run.selected_nodes doc asta in
- fprintf err_formatter "Query: %a\n"
- XPath.Ast.print query;
- let rec print_selec fmt l = match l with
- | [x] -> fprintf fmt "%s" (string_of_int x)
- | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl
- | [] -> fprintf fmt "%s" "ø" in
- fprintf err_formatter "@.@. # Selected nodes: {%a}@."
- print_selec selected_nodes in
+ let run = compute_run doc asta in
+ fprintf err_formatter "\n ### Query: %a"
+ XPath.Ast.print query;
+ fprintf err_formatter "@. ### Selected nodes: {%a}@."
+ print_selec selected_nodes;
+ if flag
+ then begin
+ Asta.print err_formatter asta;
+ Run.print err_formatter run;
+ end
+ else ();
+ let asta = Asta.empty in
+ solve_queries tl in
solve_queries queries;
exit 0