Skip to content

Commit 44786dd

Browse files
committed
Remove loc adjustment hack
1 parent 6e01830 commit 44786dd

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,28 +4906,14 @@ and parse_type_constructor_declaration_with_bar p =
49064906
[doc_comment_to_attribute loc s]
49074907
| _ -> []
49084908
in
4909-
let has_doc_comment = not (doc_comment_attrs = []) in
49104909
let start_pos = p.Parser.start_pos in
49114910
Parser.next p;
49124911
let constr = parse_type_constructor_declaration ~start_pos p in
4913-
let pcd_loc =
4914-
if has_doc_comment then
4915-
{
4916-
constr.Parsetree.pcd_loc with
4917-
loc_end =
4918-
{
4919-
constr.pcd_loc.loc_end with
4920-
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4921-
};
4922-
}
4923-
else constr.pcd_loc
4924-
in
49254912
Some
49264913
{
49274914
constr with
49284915
Parsetree.pcd_attributes =
49294916
doc_comment_attrs @ constr.Parsetree.pcd_attributes;
4930-
pcd_loc;
49314917
}
49324918
| _ -> None
49334919

@@ -4965,27 +4951,10 @@ and parse_type_constructor_declarations ?first p =
49654951
[doc_comment_to_attribute loc s]
49664952
| _ -> []
49674953
in
4968-
let has_doc_comment = not (doc_comment_attrs = []) in
49694954
let start_pos = p.Parser.start_pos in
49704955
ignore (Parser.optional p Token.Bar);
49714956
let constr = parse_type_constructor_declaration ~start_pos p in
4972-
let pcd_loc =
4973-
if has_doc_comment then
4974-
{
4975-
constr.Parsetree.pcd_loc with
4976-
loc_end =
4977-
{
4978-
constr.pcd_loc.loc_end with
4979-
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4980-
};
4981-
}
4982-
else constr.pcd_loc
4983-
in
4984-
{
4985-
constr with
4986-
pcd_attributes = doc_comment_attrs @ constr.pcd_attributes;
4987-
pcd_loc;
4988-
}
4957+
{constr with pcd_attributes = doc_comment_attrs @ constr.pcd_attributes}
49894958
| Some first_constr_decl -> first_constr_decl
49904959
in
49914960
first_constr_decl

compiler/syntax/src/res_printer.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ let print_list ~get_loc ~nodes ~print ?(force_break = false) t =
340340
in
341341
Doc.breakable_group ~force_break docs
342342

343-
let print_listi ~get_loc ~nodes ~print ?(force_break = false) t =
343+
let print_listi ~get_loc ~nodes ~print ?(ignore_empty_lines = false)
344+
?(force_break = false) t =
344345
let rec loop i (prev_loc : Location.t) acc nodes =
345346
match nodes with
346347
| [] -> (prev_loc, Doc.concat (List.rev acc))
@@ -352,8 +353,10 @@ let print_listi ~get_loc ~nodes ~print ?(force_break = false) t =
352353
| Some comment -> (Comment.loc comment).loc_start
353354
in
354355
let sep =
355-
if start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1 then
356-
Doc.concat [Doc.hard_line; Doc.hard_line]
356+
if
357+
start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1
358+
&& not ignore_empty_lines
359+
then Doc.concat [Doc.hard_line; Doc.hard_line]
357360
else Doc.line
358361
in
359362
let doc = print_comments (print node t i) t loc in
@@ -1542,18 +1545,22 @@ and print_constructor_declarations ~state ~private_flag
15421545
~print:(fun cd cmt_tbl i ->
15431546
let doc = print_constructor_declaration2 ~state i cd cmt_tbl in
15441547
print_comments doc cmt_tbl cd.Parsetree.pcd_loc)
1545-
~force_break cmt_tbl
1548+
~force_break cmt_tbl ~ignore_empty_lines:true
15461549
in
15471550
Doc.breakable_group ~force_break
15481551
(Doc.indent (Doc.concat [Doc.line; private_flag; rows]))
15491552

15501553
and print_constructor_declaration2 ~state i
15511554
(cd : Parsetree.constructor_declaration) cmt_tbl =
1552-
let comment_attrs, attrs = ParsetreeViewer.partition_doc_comment_attributes cd.pcd_attributes in
1555+
let comment_attrs, attrs =
1556+
ParsetreeViewer.partition_doc_comment_attributes cd.pcd_attributes
1557+
in
15531558
let comment_doc =
15541559
match comment_attrs with
15551560
| [] -> Doc.nil
1556-
| comment_attrs -> print_doc_comments ~sep:Doc.hard_line ~state cmt_tbl comment_attrs in
1561+
| comment_attrs ->
1562+
print_doc_comments ~sep:Doc.hard_line ~state cmt_tbl comment_attrs
1563+
in
15571564
let attrs = print_attributes ~state attrs cmt_tbl in
15581565
let is_dot_dot_dot = cd.pcd_name.txt = "..." in
15591566
let bar =

0 commit comments

Comments
 (0)