Skip to content

Commit

Permalink
first cut
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Oct 22, 2024
1 parent 43789e0 commit d7857a3
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/Explication.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let dump_token dump_tag fmt =
| Marker m -> Format.fprintf fmt {|@[<2>Marker@ @[<1>(%a)@]@]|} (dump_marker dump_tag) m
let dump_line dump_tag fmt {markers; tokens} =
Format.fprintf fmt {|@[<1>{@[<2>tags=@,@[%a@]@];@ @[<2>tokens=@ @[%a@]@]}@]|}
Format.fprintf fmt {|@[<1>{@[<2>markers=@,@[%a@]@];@ @[<2>tokens=@ @[%a@]@]}@]|}
(Utils.dump_list dump_tag) markers
(Utils.dump_list (dump_token dump_tag)) tokens
Expand Down
23 changes: 10 additions & 13 deletions src/Flattener.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct
if Range.end_line_num range - block.end_line_num > block_splitting_threshold then
go (blocks <: block) (singleton r) rs
else
let end_line_num = Int.min block.end_line_num (Range.end_line_num range) in
let end_line_num = Int.max block.end_line_num (Range.end_line_num range) in
go blocks {block with end_line_num; ranges = block.ranges <: r} rs
in
match l with
Expand Down Expand Up @@ -144,19 +144,16 @@ struct
end
=
struct
let compare_line_marker (i1, t1) (i2, t2) =
Utils.compare_pair Int.compare Int.compare
(i1, Tag.priority t1) (i2, Tag.priority t2)

let flatten_block ({begin_line_num; end_line_num; ranges} : unflattened_block) =
let ranges = Bwd.to_list ranges in
{ begin_line_num
; end_line_num
; markers = BlockFlattener.flatten ranges
; line_markers =
List.stable_sort compare_line_marker @@
List.map (fun (range, tag) -> Range.end_line_num range, tag) ranges
}
let markers = BlockFlattener.flatten @@ Bwd.to_list ranges in
let line_markers =
List.filter_map
(function
| (_, RangeBegin _) -> None
| (p, RangeEnd tag) | (p, Point tag) -> Some (p.Range.line_num, tag))
markers
in
{ begin_line_num; end_line_num; markers; line_markers }

let flatten ~block_splitting_threshold rs =
List.map flatten_block @@ Bwd.to_list @@ Splitter.partition ~block_splitting_threshold rs
Expand Down
6 changes: 3 additions & 3 deletions test/TestExplicator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let single_line mode eol () =
]}]}
]}
] in
let actual = E.explicate ~line_breaks:mode [range1, 1; range2, 2] in
let actual = E.explicate ~line_breaks:mode [(range1, 1); (range2, 2)] in
Alcotest.(check test_explication) "Explication is correct" expected actual

let multi_lines_with_ls () =
Expand Down Expand Up @@ -110,7 +110,7 @@ ggggghh
{markers=[];
tokens=
[String "bbbbbbb"]};
{markers=[1;2];
{markers=[2; 1];
tokens=
[String "b";
Marker (RangeBegin 2);
Expand All @@ -130,7 +130,7 @@ ggggghh
{markers=[];
tokens=
[String "4"]};
{markers=[4; 8];
{markers=[8; 4];
tokens=
[String "ee";
Marker (RangeBegin 4);
Expand Down
12 changes: 6 additions & 6 deletions test/TestFlattener.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ let single_line_flatten () =
[(source,
[{begin_line_num=1;
end_line_num=1;
markers=[(pt1, RangeBegin 1);(pt2, RangeBegin 2);(pt3, RangeEnd 3);(pt4, RangeEnd 4)];
line_markers=[(1,1);(2,1)]}])]
markers=[(pt1, RangeBegin 1); (pt2, RangeBegin 2); (pt3, RangeEnd 1); (pt4, RangeEnd 2)];
line_markers=[(1,1);(1,2)]}])]
in
let actual = F.flatten ~block_splitting_threshold:5 [range1, 1; range2, 2] in
Alcotest.(check test_flattened) "Flattener is correct" expected actual
Expand Down Expand Up @@ -81,10 +81,10 @@ ggggghh
(pt40, RangeEnd 4);
];
line_markers=
[(4, 1);
(4, 2);
(9, 4);
(9, 8)]};
[(4, 2);
(4, 1);
(9, 8);
(9, 4)]};
{begin_line_num=15;
end_line_num=15;
markers=
Expand Down
Loading

0 comments on commit d7857a3

Please sign in to comment.