let rec doc_of_nmm_stdin (print_tokens:bool) : Doc_types.tr_doc=
let _ : unit = set_refs () in
let input : string = In_channel.input_all stdin in
let sedlexbuf : Sedlexing.lexbuf = Sedlexing.Utf8.from_string input 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
doc
with
| _ ->
match print_tokens with
|false ->
let _ : unit = IO.print_to_stderr (
String.concat "\n" [
"Read the the following tokens from \'" ^ input ^ "\':";
]
)
in doc_of_nmm_string true input
|true -> raise (Error "Parsing failed")