From 3bb4562b0961dc895c837e3b0ad47f25e3021e8e Mon Sep 17 00:00:00 2001 From: OOHASHI Daichi Date: Thu, 25 Nov 2021 23:14:13 +0900 Subject: [PATCH 1/3] print the program name and a position in `report_error` --- src/frontend/main.ml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/frontend/main.ml b/src/frontend/main.ml index 8bb43ee44..981a72d62 100644 --- a/src/frontend/main.ml +++ b/src/frontend/main.ml @@ -40,32 +40,36 @@ let show_error_category = function | System -> "Error" -let report_error (cat : error_category) (lines : line list) = +let program_name = ref (Some "satysfi") + +let report_error ?rng (cat : error_category) (lines : line list) = let aux lst = - lst |> List.fold_left (fun is_first line -> - begin + lst |> List.iteri (fun i line -> match line with | NormalLine(s) | NormalLineOption(Some(s)) -> - if is_first then - print_endline s + if i = 0 then + Printf.printf "%s\n" s else - print_endline (" " ^ s) + Printf.printf "%*s%s\n" 4 " " s | DisplayLine(s) | DisplayLineOption(Some(s)) -> - if is_first then - print_endline ("\n " ^ s) + if i = 0 then + Printf.printf "\n%*s%s\n" 6 " " s else - print_endline (" " ^ s) + Printf.printf "%*s%s\n" 6 " " s | _ -> () - end; - false - ) true + ) in - print_string ("! [" ^ (show_error_category cat) ^ "] "); + !program_name |> Option.iter (Printf.printf "%s:"); + rng |> Option.iter (fun rng -> Printf.printf "%s:" @@ Range.to_string rng); + if Option.is_some !program_name || Option.is_some rng then begin + Printf.printf " " + end; + Printf.printf "%s: " (show_error_category cat); aux lines |> ignore; exit 1 From 35b632ec9405a7d9ff50d30785a20e2e5c66c713 Mon Sep 17 00:00:00 2001 From: OOHASHI Daichi Date: Sat, 25 Dec 2021 07:50:12 +0900 Subject: [PATCH 2/3] Range.to_string: format ranges in the GNU format --- src/frontend/range.ml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/frontend/range.ml b/src/frontend/range.ml index 7f4f333c0..c8c8d6c4a 100644 --- a/src/frontend/range.ml +++ b/src/frontend/range.ml @@ -33,16 +33,12 @@ let message rng = let to_string rng = - let s = string_of_int in - match rng with - | Dummy(msg) -> - "dummy range '" ^ msg ^ "'" - - | Normal(fname, ln1, pos1, ln2, pos2) -> - if ln1 = ln2 then - "\"" ^ fname ^ "\", line " ^ (s ln1) ^ ", characters " ^ (s pos1) ^ "-" ^ (s pos2) - else - "\"" ^ fname ^ "\", line " ^ (s ln1) ^ ", character " ^ (s pos1) ^ " to line " ^ (s ln2) ^ ", character " ^ (s pos2) + match rng with + | Dummy(msg) -> + Printf.sprintf "//dummy/%s" msg + + | Normal(fname, ln1, pos1, ln2, pos2) -> + Format.asprintf "%a" format_range (fname, ln1, pos1, ln2, pos2) let get_last = function From b73e1f2cf3143c5206eadeac53a249f9101c0bbd Mon Sep 17 00:00:00 2001 From: OOHASHI Daichi Date: Sat, 25 Dec 2021 07:40:03 +0900 Subject: [PATCH 3/3] wip --- src/frontend/main.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frontend/main.ml b/src/frontend/main.ml index 981a72d62..2351f5559 100644 --- a/src/frontend/main.ml +++ b/src/frontend/main.ml @@ -646,8 +646,7 @@ let error_log_environment suspended = ] | Lexer.LexError(rng, s) -> - report_error Lexer [ - NormalLine("at " ^ (Range.to_string rng) ^ ":"); + report_error ~rng Lexer [ NormalLine(s); ]