texvc_test.ml 668 B

12345678910111213141516171819202122232425
  1. exception LexerException of string
  2. let lexer_token_safe lexbuf =
  3. try Lexer.token lexbuf
  4. with Failure s -> raise (LexerException s)
  5. let rec foo () =
  6. try
  7. let line = input_line stdin in
  8. (try
  9. let tree = Parser.tex_expr lexer_token_safe (Lexing.from_string line) in
  10. (match Html.render tree with
  11. Some _ -> print_string "$^\n"
  12. | None -> print_string "$_\n";
  13. )
  14. with
  15. Texutil.Illegal_tex_function s -> print_string ("$T" ^ s ^ " " ^ line ^ "\n")
  16. | LexerException s -> print_string ("$L" ^ line ^ "\n")
  17. | _ -> print_string ("$ " ^ line ^ "\n"));
  18. flush stdout;
  19. foo ();
  20. with
  21. End_of_file -> ()
  22. ;;
  23. foo ();;