Simon Génier pushed to branch gambit-compile-pervasives at Stefan / Typer
Commits: c6e03ab0 by Simon Génier at 2022-11-04T16:43:26-04:00 Print multiline locations.
- - - - -
1 changed file:
- src/source.ml
Changes:
===================================== src/source.ml ===================================== @@ -175,31 +175,60 @@ module Location = struct let display_context (location : t) (f : formatter) : unit =
+ let print_within line_number = + let line = Container.nth_line location.container line_number in + let before = String.sub line 0 location.start_offset in + let focus = + String.sub + line + location.start_offset + (location.end_offset - location.start_offset) + in + let after = + String.sub + line + location.end_offset + (String.length line - location.end_offset) + in + fprintf f "%d | %s@{<cyan>%s@}%s@." line_number before focus after; + in + + let print_start_line line_number start_offset = + let line = Container.nth_line location.container line_number in + let before = String.sub line 0 start_offset in + let focus = + String.sub line start_offset (String.length line - start_offset) + in + fprintf f "%d | %s@{<cyan>%s@}@." line_number before focus; + in + + let print_middle_line line_number = + let line = Container.nth_line location.container line_number in + fprintf f "%d | @{<cyan>%s@}@." line_number line; + in + + let print_end_line line_number end_offset = + let line = Container.nth_line location.container line_number in + let focus = String.sub line 0 end_offset in + let after = String.sub line end_offset (String.length line - end_offset) in + fprintf f "%d | @{<cyan>%s@}%s@." line_number focus after; + in + if location != dummy then begin fprintf f " → In: @{<green>%s@}@." (Container.name location.container); if location.start_line = location.end_line - then - let line = Container.nth_line location.container location.start_line in - let before = String.sub line 0 location.start_offset in - let focus = - String.sub - line - location.start_offset - (location.end_offset - location.start_offset) - in - let after = - String.sub - line - location.end_offset - (String.length line - location.end_offset) - in - fprintf f "%d | %s@{<cyan>%s@}%s@." location.start_line before focus after; - else - failwith "TODO" + then print_within location.start_line + else begin + print_start_line location.start_line location.start_offset; + for line_number = location.start_line + 1 to location.end_line - 1 do + print_middle_line line_number; + done; + print_end_line location.end_line location.end_offset; end + end end
(** A source object is text paired with a cursor. *)
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/c6e03ab0f974d75cc87a3a15184172fda1...
Afficher les réponses par date