From d7857a3154bc7492c35a310616cdf072f85ae078 Mon Sep 17 00:00:00 2001 From: favonia Date: Mon, 21 Oct 2024 22:19:56 -0500 Subject: [PATCH] first cut --- src/Explication.ml | 2 +- src/Flattener.ml | 23 +++-- test/TestExplicator.ml | 6 +- test/TestFlattener.ml | 12 +-- test/TestTty.expected | 198 ++++++++++++++++++++--------------------- 5 files changed, 119 insertions(+), 122 deletions(-) diff --git a/src/Explication.ml b/src/Explication.ml index ff0a8e9..f3add5b 100644 --- a/src/Explication.ml +++ b/src/Explication.ml @@ -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 diff --git a/src/Flattener.ml b/src/Flattener.ml index 11ebdfb..6d5e0ba 100644 --- a/src/Flattener.ml +++ b/src/Flattener.ml @@ -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 @@ -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 diff --git a/test/TestExplicator.ml b/test/TestExplicator.ml index 7faf357..fb68d18 100644 --- a/test/TestExplicator.ml +++ b/test/TestExplicator.ml @@ -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 () = @@ -110,7 +110,7 @@ ggggghh {markers=[]; tokens= [String "bbbbbbb"]}; - {markers=[1;2]; + {markers=[2; 1]; tokens= [String "b"; Marker (RangeBegin 2); @@ -130,7 +130,7 @@ ggggghh {markers=[]; tokens= [String "4"]}; - {markers=[4; 8]; + {markers=[8; 4]; tokens= [String "ee"; Marker (RangeBegin 4); diff --git a/test/TestFlattener.ml b/test/TestFlattener.ml index 40b3f53..27820ab 100644 --- a/test/TestFlattener.ml +++ b/test/TestFlattener.ml @@ -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 @@ -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= diff --git a/test/TestTty.expected b/test/TestTty.expected index 84e14b8..2157851 100644 --- a/test/TestTty.expected +++ b/test/TestTty.expected @@ -8,109 +8,109 @@ → bug[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a bug → error[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an error → warning[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a warning → info[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an info → hint[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a hint → warning[hello] ꭍ ○ when peaking into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ○ when peaking into the abyss ╯ ○ when peaking into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → info[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ┆ ^ when stepping into the abyss ┆ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] -  1 | aaaaaaaaaa -  2 | bbbbbbbbbb +  1 | aaa‹aaaaaaa +  2 | b›bb‹bbbb›b‹b›b ^ message 6 ^ this is the main message ^ message 5 -  3 | cccccccccc +  3 | cccc‹c›ccccc ^ message 4 ■ /path/to/file.cool -  1 | aaaaaaaaaa -  2 | bbbbbbbbbb +  1 | aaa‹‹aaaaaaa +  2 | b›bbbbbbbbb ^ message 7 -  3 | cccccccccc +  3 | cccc›cccccc ^ message 2 - 10 | jjjjjjjjjj + 10 | ◂POS▸jjjjjjjjjj ^ message 8 ○ message 1 ○ message 3 → warning[hello] - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ this is the main message ■ /path/to/file.cool - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ ending of another file → warning[hello] @@ -123,109 +123,109 @@ → bug[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a bug → error[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an error → warning[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a warning → info[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an info → hint[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a hint → warning[hello] ꭍ ○ when peaking into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ○ when peaking into the abyss ╯ ○ when peaking into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → info[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ┆ ^ when stepping into the abyss ┆ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] -  1 | aaaaaaaaaa -  2 | bbbbbbbbbb +  1 | aaa‹aaaaaaa +  2 | b›bb‹bbbb›b‹b›b ^ message 6 ^ this is the main message ^ message 5 -  3 | cccccccccc +  3 | cccc‹c›ccccc ^ message 4 ■ /path/to/file.cool -  1 | aaaaaaaaaa -  2 | bbbbbbbbbb +  1 | aaa‹‹aaaaaaa +  2 | b›bbbbbbbbb ^ message 7 -  3 | cccccccccc +  3 | cccc›cccccc ^ message 2 - 10 | jjjjjjjjjj + 10 | ◂POS▸jjjjjjjjjj ^ message 8 ○ message 1 ○ message 3 → warning[hello] - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ this is the main message ■ /path/to/file.cool - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ ending of another file → warning[hello] @@ -238,108 +238,108 @@ → bug[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a bug → error[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an error → warning[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a warning → info[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is an info → hint[hello] ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ this is a hint → warning[hello] ꭍ ○ when peaking into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ○ when peaking into the abyss ╯ ○ when peaking into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → info[hello] ╭ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ┆ ^ when stepping into the abyss ┆ ■ /path/to/file.cool - ┆ 1 | aaaaaaaaaa + ┆ 1 | a‹aaaaaaaaa ┆ 2 | bbbbbbbbbb - ┆ 3 | cccccccccc + ┆ 3 | cccc›cccccc ╯ ^ when stepping into the deep abyss ■ /path/to/file.cool - 1 | aaaaaaaaaa + 1 | aaa‹aaaaaaa 2 | bbbbbbbbbb - 3 | cccccccccc + 3 | cccc›cccccc ^ hello from here → warning[hello] - 1 | aaaaaaaaaa - 2 | bbbbbbbbbb + 1 | aaa‹aaaaaaa + 2 | b›bb‹bbbb›b‹b›b ^ message 6 ^ this is the main message ^ message 5 - 3 | cccccccccc + 3 | cccc‹c›ccccc ^ message 4 ■ /path/to/file.cool - 1 | aaaaaaaaaa - 2 | bbbbbbbbbb + 1 | aaa‹‹aaaaaaa + 2 | b›bbbbbbbbb ^ message 7 - 3 | cccccccccc + 3 | cccc›cccccc ^ message 2 - 10 | jjjjjjjjjj + 10 | ◂POS▸jjjjjjjjjj ^ message 8 ○ message 1 ○ message 3 → warning[hello] - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ this is the main message ■ /path/to/file.cool - 23 | wwwwwwwwww‹EOF› + 23 | wwwwwwwwww◂POS▸ ^ ending of another file