Skip to content

Commit a4470a6

Browse files
committed
Trim empty lines upfront
1 parent 4307cf2 commit a4470a6

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

bin/test/main.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ let run_toplevel_tests ?root c ppf tests t =
182182
) tests;
183183
Block.pp_footer ppf ()
184184

185-
let trim l =
186-
let rec trim_front = function
187-
| ""::t -> trim_front t
188-
| l -> l
189-
in
190-
let rev_trim l = trim_front (List.rev (trim_front l)) in
191-
rev_trim (List.rev_map String.trim l)
192-
193185
type file = { first: Mdx_top.Part.file; current: Mdx_top.Part.file }
194186

195187
let files: (string, file) Hashtbl.t = Hashtbl.create 8
@@ -227,8 +219,8 @@ let update_block_with_file ppf t file part =
227219
(match part with None -> "" | Some p -> p)
228220
file
229221
| Some lines ->
230-
let lines = trim lines in
231222
let contents = String.concat "\n" lines in
223+
let contents = String.trim contents in
232224
Output.pp ppf (`Output contents);
233225
Block.pp_footer ppf ()
234226

lib/top/part.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ let rec remove_empty_heads = function
3535
| "" :: tl -> remove_empty_heads tl
3636
| l -> l
3737

38+
let trim_empty_rev l =
39+
remove_empty_heads (List.rev (remove_empty_heads l))
40+
3841
module Parse_parts =
3942
struct
4043

@@ -47,8 +50,8 @@ struct
4750
ws; str "]"; ws; opt (str ";;"); ws;
4851
]
4952

50-
let next_part ~name ~sep_indent = fun lines ->
51-
let body = String.concat "\n" (List.rev (remove_empty_heads lines)) in
53+
let next_part ~name ~sep_indent = fun lines_rev ->
54+
let body = String.concat "\n" (trim_empty_rev lines_rev) in
5255
Part.v ~name ~sep_indent ~body
5356

5457
let next_part_of_groups groups =

test/sync_to_ml.ml.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let f = "hello world!"
1919

2020
[@@@part "42"] ;;
2121

22-
2322
let () =
2423
f x print_int
2524

0 commit comments

Comments
 (0)