mirror of
https://github.com/comby-tools/comby.git
synced 2024-10-26 13:19:23 +03:00
Print line numbers for -match-only option (#152)
This commit is contained in:
parent
e6810b9ebb
commit
3fee93b352
@ -30,14 +30,18 @@ let pp_source_path ppf source_path =
|
||||
| Some path -> Format.fprintf ppf "%s:" path
|
||||
| None -> Format.fprintf ppf ""
|
||||
|
||||
let pp_line_number ppf start_line =
|
||||
Format.fprintf ppf "%d:" start_line
|
||||
|
||||
let pp ppf (source_path, matches) =
|
||||
if matches = [] then
|
||||
()
|
||||
else
|
||||
let matched =
|
||||
List.map matches ~f:(fun { matched; _ } ->
|
||||
List.map matches ~f:(fun { matched; range; _ } ->
|
||||
let matched = String.substr_replace_all matched ~pattern:"\n" ~with_:"\\n" in
|
||||
Format.asprintf "%a%s" pp_source_path source_path matched)
|
||||
let line = range.match_start.line in
|
||||
Format.asprintf "%a%a%s" pp_source_path source_path pp_line_number line matched)
|
||||
|> String.concat ~sep:"\n"
|
||||
in
|
||||
Format.fprintf ppf "%s@." matched
|
||||
|
@ -804,8 +804,8 @@ let%expect_test "print_single_line_matches" =
|
||||
let command = Format.sprintf "%s %s" binary_path command_args in
|
||||
read_expect_stdin_and_stdout command source
|
||||
|> print_string;
|
||||
[%expect_exact {|let ()
|
||||
let ()
|
||||
[%expect_exact {|2:let ()
|
||||
3:let ()
|
||||
|
||||
|}]
|
||||
|
||||
@ -828,9 +828,9 @@ in
|
||||
let command = Format.sprintf "%s %s" binary_path command_args in
|
||||
read_expect_stdin_and_stdout command source
|
||||
|> print_string;
|
||||
[%expect_exact {|let ()
|
||||
let\n\n ()
|
||||
let ()
|
||||
[%expect_exact {|2:let ()
|
||||
3:let\n\n ()
|
||||
7:let ()
|
||||
|
||||
|}];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user