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);
Printf.fprintf stderr "found %d %s:\n" num_errors
(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 ->
let num_errors = List.length es in
assert (num_errors <> 0);
Printf.fprintf stderr "found %d %s:\n" num_errors
(if num_errors = 1 then "ParserError" else "ParserErrors");
List.iter (fun e -> ParserError.show e |> Printf.fprintf stderr "%s\n") es
| RuntimeError e -> RuntimeError.show e |> Printf.fprintf stderr "%s\n"
List.iter (fun e -> ParserError.show e |> prerr_endline) es
| RuntimeError e -> RuntimeError.show e |> prerr_endline
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

View file

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