Skip to content

Commit

Permalink
fix dropped comments in Ppat_construct
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed May 29, 2019
1 parent e91acd0 commit 6d4d0d1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -851,23 +851,26 @@ and fmt_pattern c ?pro ?parens ({ctx= ctx0; ast= pat} as xpat) =
| Ppat_construct (lid, None) -> fmt_longident_loc c lid
| Ppat_construct
( {txt= Lident "::"; loc}
, Some {ppat_desc= Ppat_tuple [x; y]; ppat_attributes= []} ) -> (
, Some {ppat_desc= Ppat_tuple [x; y]; ppat_attributes= []; ppat_loc}
) -> (
match Sugar.list_pat c.cmts pat with
| Some (loc_xpats, nil_loc) ->
let fmt_pat (locs, xpat) =
Cmts.fmt_list c ~eol:(fmt "@;<1 2>") locs @@ fmt_pattern c xpat
in
hvbox 0
(wrap_list c
( list loc_xpats "@,; " fmt_pat
$ Cmts.fmt_before c ~pro:(fmt "@;<1 2>") ~epi:noop nil_loc
$ Cmts.fmt_after c ~pro:(fmt "@ ") ~epi:noop nil_loc ))
(Cmts.fmt c ppat_loc
(wrap_list c
( list loc_xpats "@,; " fmt_pat
$ Cmts.fmt_before c ~pro:(fmt "@;<1 2>") ~epi:noop nil_loc
$ Cmts.fmt_after c ~pro:(fmt "@ ") ~epi:noop nil_loc )))
| None ->
hvbox 0
(wrap_if parens "(" ")"
( fmt_pattern c (sub_pat ~ctx x)
$ Cmts.fmt c ~pro:(str " ") ~epi:noop loc (fmt "@ :: ")
$ fmt_pattern c (sub_pat ~ctx y) )) )
(Cmts.fmt c ppat_loc
( fmt_pattern c (sub_pat ~ctx x)
$ Cmts.fmt c ~pro:(str " ") ~epi:noop loc (fmt "@ :: ")
$ fmt_pattern c (sub_pat ~ctx y) ))) )
| Ppat_construct (lid, Some pat) ->
cbox 2
(wrap_if parens "(" ")"
Expand Down
5 changes: 5 additions & 0 deletions test/passing/comments.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,8 @@ let () =
xxxxxxxxxx
land (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

let rec fooooooooooo = function
| ((*XX*) (x :: t) (*YY*)) -> k
| (* AA*) ((*BB*) [(* CC *)x(* DD *) ; (* EE *)y(* FF *)] (* GG *)) (* HH *) -> k
| (* AA*) ((*BB*) ((* CC *)x(* DD *) :: (* EE *)t(* FF *)) (* GG *)) (* HH *) -> k
2 changes: 1 addition & 1 deletion test/passing/comments.ml.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--max-iter=3
--max-iter=4
19 changes: 19 additions & 0 deletions test/passing/comments.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,22 @@ let () =
xxxxxxxxxx
land (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

let rec fooooooooooo = function
(*XX*)
| x :: t (*YY*) -> k
(* AA*)
(*BB*)
(* CC *)
| [x (* DD *); (* EE *) y (* FF *)]
(* GG *)
(* HH *) ->
k
(* AA*)
(*BB*)
(* CC *)
| x (* DD *) :: (* EE *) t
(* FF *)
(* GG *)
(* HH *) ->
k

0 comments on commit 6d4d0d1

Please sign in to comment.