let rec doc_of_nmm_file (print_tokens:bool) (filename:string):Doc_types.tr_doc= let _ : unit = set_refs () in match Sys.file_exists filename && not (Sys.is_directory filename) with |false -> raise (Error ("cannot read from " ^ filename ^ ": No such file")) |true -> let ic=open_in filename in let sedlexbuf : Sedlexing.lexbuf = Sedlexing.Utf8.from_channel ic in let dummy_lexbuf : Lexing.lexbuf = Lexing.from_string "" in let lexer (lexbuf : Lexing.lexbuf) : Nmm_parser.token = match sedlexer print_tokens sedlexbuf with |token, start_pos, end_pos -> let _ : unit = dummy_lexbuf.Lexing.lex_start_p <- start_pos in let _ : unit = dummy_lexbuf.Lexing.lex_curr_p <- end_pos in token in try let doc = Nmm_parser.main lexer dummy_lexbuf in let _ : unit = close_in ic in doc with | _ -> match print_tokens with |false -> let _ : unit = IO.print_to_stderr ( String.concat "\n" [ "Read the the following tokens from " ^ filename ^ ":"; ] ) in doc_of_nmm_file true filename |true -> raise (Error "Parsing failed")