Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix #308 #314

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/frontend/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -642,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);
]

Expand Down
16 changes: 6 additions & 10 deletions src/frontend/range.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down