diff --git a/lib/error.ml b/lib/error.ml index adab803..ce67da5 100644 --- a/lib/error.ml +++ b/lib/error.ml @@ -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 diff --git a/lib/lox.ml b/lib/lox.ml index 5a43f1e..e462358 100644 --- a/lib/lox.ml +++ b/lib/lox.ml @@ -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 ()