let rec parse_file (print_tokens:bool) (s:string):Xml.xml =
match Sys.file_exists s && not (Sys.is_directory s) with
|false -> raise (Error ("cannot read from " ^ s ^ ": No such file"))
|true ->
try
let ic=open_in s in
let lexbuf=Lexing.from_channel ic in
let parse=Xml_right_parser.main (lexer print_tokens) in
let result=parse lexbuf in
let _=close_in ic in result
with
|_ ->
match print_tokens with
|false ->
let _ = IO.print_to_stderr ("Xml_right failed, read the following tokens from " ^ s ^ ":") in
parse_file true s
|true -> raise (Error "parsing failed")