-let document =
- if Filename.check_suffix !Options.input_file ".srx"
- then
- time
- ~msg:"Loading file"
- (Tree.load
- ~sample:!Options.sample_factor
- ~load_text:true)
- !Options.input_file
- else
- let v =
- time
- ~msg:"Parsing document"
- (Tree.parse_xml_uri)
- !Options.input_file
- in
- let () =
- if !Options.save_file <> ""
+ let document =
+ if Filename.check_suffix !Options.input_file ".g.bin" ||
+ Filename.check_suffix !Options.input_file ".g"
+ then
+ let is_index = Filename.check_suffix !Options.input_file ".g.bin" in
+ let g =
+ if is_index then
+ time ~msg:"Loading grammar" (Grammar2.load) !Options.input_file
+ else
+ let g = time ~msg:"Parsing grammar file" Grammar2.parse !Options.input_file in
+ if !Options.save_file <> "" then
+ time ~msg:"Saving index" (Grammar2.save g) !Options.save_file;
+ g
+ in
+ begin
+ (* Todo Factorise with main *)
+ Tag.init (Grammar2.tag_operations g);
+ let query =
+ time ~msg:"Parsing query" XPath.parse !Options.query
+ in
+ if !Options.verbose then begin
+ Printf.eprintf "Parsed query:\n%!";
+ XPath.Ast.print Format.err_formatter query;
+ Format.fprintf Format.err_formatter "\n%!"
+ end;
+ let auto, bu_info =
+ time ~msg:"Compiling query" (Compile.compile) query
+ in
+ if !Options.verbose then Ata.print Format.err_formatter auto;
+ Gc.full_major();
+ Gc.compact();
+ Gc.set (tuned_gc);
+ let runtime =
+ if !Options.count_only then
+ let module R = ResJIT.Make(NodeSet.Partial(NodeSet.Count)) in
+ let module M = Runtime.Make(R) in
+ (* mk_runtime run auto doc arg count print outfile *)
+ mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
+ else
+ let module R = ResJIT.Mat in
+ let module M = Runtime.Make(R) in
+ (* mk_runtime run auto doc arg count print outfile *)
+ mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
+ in
+ runtime ();
+ exit 0
+ end
+ else if Filename.check_suffix !Options.input_file ".srx"