use prerr_* instead of fprintf where possible

This commit is contained in:
Moritz Gmeiner 2024-08-27 18:45:26 +02:00
commit d2077774f7
2 changed files with 11 additions and 11 deletions

View file

@ -50,14 +50,14 @@ let print_error (e : lox_error) =
assert (num_errors <> 0); assert (num_errors <> 0);
Printf.fprintf stderr "found %d %s:\n" num_errors Printf.fprintf stderr "found %d %s:\n" num_errors
(if num_errors = 1 then "LexerError" else "LexerErrors"); (if num_errors = 1 then "LexerError" else "LexerErrors");
List.iter (fun e -> LexerError.show e |> Printf.fprintf stderr "%s\n") es List.iter (fun e -> LexerError.show e |> prerr_endline) es
| ParserError es -> | ParserError es ->
let num_errors = List.length es in let num_errors = List.length es in
assert (num_errors <> 0); assert (num_errors <> 0);
Printf.fprintf stderr "found %d %s:\n" num_errors Printf.fprintf stderr "found %d %s:\n" num_errors
(if num_errors = 1 then "ParserError" else "ParserErrors"); (if num_errors = 1 then "ParserError" else "ParserErrors");
List.iter (fun e -> ParserError.show e |> Printf.fprintf stderr "%s\n") es List.iter (fun e -> ParserError.show e |> prerr_endline) es
| RuntimeError e -> RuntimeError.show e |> Printf.fprintf stderr "%s\n" | RuntimeError e -> RuntimeError.show e |> prerr_endline
let of_lexer_error e = Result.map_error (fun e -> LexerError e) e let of_lexer_error e = Result.map_error (fun e -> LexerError e) e
let of_parser_error e = Result.map_error (fun e -> ParserError e) e let of_parser_error e = Result.map_error (fun e -> ParserError e) e

View file

@ -16,13 +16,13 @@ let run ?(env : Environment.environment option) ?(debug = false) (source : strin
let () = let () =
if debug then if debug then
let print_tokens () = let print_tokens () =
Printf.fprintf stderr "--- Tokens ---\n"; prerr_endline "--- Tokens ---";
let f token = Printf.fprintf stderr "%s " (Lexer.show_token token) in let f token = Printf.fprintf stderr "%s " (Lexer.show_token token) in
Printf.fprintf stderr "Got %d tokens\n" (List.length tokens); Printf.fprintf stderr "Got %d tokens\n" (List.length tokens);
List.iter f tokens; List.iter f tokens;
Printf.fprintf stderr "\n"; prerr_newline ();
Printf.fprintf stderr "--------------\n"; prerr_endline "--------------";
Printf.fprintf stderr "\n" prerr_newline ()
in in
print_tokens () print_tokens ()
else () else ()
@ -31,11 +31,11 @@ let run ?(env : Environment.environment option) ?(debug = false) (source : strin
let () = let () =
if debug then if debug then
let print_statements () = let print_statements () =
Printf.fprintf stderr "--- Statements ---\n"; prerr_endline "--- Statements ---";
let f (stmt : Stmt.stmt_node) = Printf.fprintf stderr "%s\n" (Stmt.show_stmt stmt.stmt) in let f (stmt : Stmt.stmt_node) = prerr_endline (Stmt.show_stmt stmt.stmt) in
List.iter f stmts; List.iter f stmts;
Printf.fprintf stderr "------------------\n"; prerr_endline "------------------";
Printf.fprintf stderr "\n" prerr_newline ()
in in
print_statements () print_statements ()
else () else ()