@@ -4885,11 +4885,19 @@ and parse_constr_decl_args p =
4885
4885
* | constr-name const-args
4886
4886
* | attrs constr-name const-args *)
4887
4887
and parse_type_constructor_declaration_with_bar p =
4888
+ let doc_comment_attrs = match p.Parser. token with
4889
+ | DocComment (loc , s ) ->
4890
+ Parser. next p;
4891
+ [doc_comment_to_attribute loc s]
4892
+ | _ -> []
4893
+ in
4888
4894
match p.Parser. token with
4889
4895
| Bar ->
4890
4896
let start_pos = p.Parser. start_pos in
4891
4897
Parser. next p;
4892
- Some (parse_type_constructor_declaration ~start_pos p)
4898
+ let () = print_endline " 3" in
4899
+ let constr = parse_type_constructor_declaration ~start_pos p in
4900
+ Some ({constr with Parsetree. pcd_attributes = doc_comment_attrs @ constr.Parsetree. pcd_attributes})
4893
4901
| _ -> None
4894
4902
4895
4903
and parse_type_constructor_declaration ~start_pos p =
@@ -4916,12 +4924,20 @@ and parse_type_constructor_declaration ~start_pos p =
4916
4924
4917
4925
(* [|] constr-decl { | constr-decl } *)
4918
4926
and parse_type_constructor_declarations ?first p =
4927
+ let () = print_endline " 2" in
4919
4928
let first_constr_decl =
4920
4929
match first with
4921
4930
| None ->
4931
+ let doc_comment_attrs = match p.Parser. token with
4932
+ | DocComment (loc , s ) ->
4933
+ Parser. next p;
4934
+ [doc_comment_to_attribute loc s]
4935
+ | _ -> []
4936
+ in
4922
4937
let start_pos = p.Parser. start_pos in
4923
4938
ignore (Parser. optional p Token. Bar );
4924
- parse_type_constructor_declaration ~start_pos p
4939
+ let constr = parse_type_constructor_declaration ~start_pos p in
4940
+ {constr with pcd_attributes = doc_comment_attrs @ constr.pcd_attributes}
4925
4941
| Some first_constr_decl -> first_constr_decl
4926
4942
in
4927
4943
first_constr_decl
@@ -4947,7 +4963,8 @@ and parse_type_representation ?current_type_name_path ?inline_types_context p =
4947
4963
in
4948
4964
let kind =
4949
4965
match p.Parser. token with
4950
- | Bar | Uident _ ->
4966
+ | Bar | Uident _ | DocComment _ ->
4967
+ let () = print_endline " 1" in
4951
4968
Parsetree. Ptype_variant (parse_type_constructor_declarations p)
4952
4969
| Lbrace ->
4953
4970
Parsetree. Ptype_record
@@ -5500,7 +5517,11 @@ and parse_type_equation_and_representation ?current_type_name_path
5500
5517
parse_record_or_object_decl ?current_type_name_path ?inline_types_context
5501
5518
p
5502
5519
| Private -> parse_private_eq_or_repr p
5503
- | Bar | DotDot ->
5520
+ | Bar | DotDot | DocComment _ ->
5521
+ let () = print_endline " xxx" in
5522
+ (* DOCCOMMENT: Reached here if the first variant starts with |.
5523
+ It is possible that the first variant may not have | (with multiple variants)
5524
+ *)
5504
5525
let priv, kind = parse_type_representation p in
5505
5526
(None , priv, kind)
5506
5527
| _ -> (
@@ -5606,6 +5627,7 @@ and parse_type_definitions ~current_type_name_path ~inline_types_context ~attrs
5606
5627
* implemented for now. Needed to get a feel for the complexities of
5607
5628
* this territory of the grammar *)
5608
5629
and parse_type_definition_or_extension ~attrs p =
5630
+ let () = print_endline " 0" in
5609
5631
let start_pos = p.Parser. start_pos in
5610
5632
Parser. expect Token. Typ p;
5611
5633
let rec_flag =
0 commit comments