Skip to content

Commit 8af5eb5

Browse files
committed
WIP
1 parent a5b8f7a commit 8af5eb5

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4885,11 +4885,19 @@ and parse_constr_decl_args p =
48854885
* | constr-name const-args
48864886
* | attrs constr-name const-args *)
48874887
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
48884894
match p.Parser.token with
48894895
| Bar ->
48904896
let start_pos = p.Parser.start_pos in
48914897
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})
48934901
| _ -> None
48944902

48954903
and parse_type_constructor_declaration ~start_pos p =
@@ -4916,12 +4924,20 @@ and parse_type_constructor_declaration ~start_pos p =
49164924

49174925
(* [|] constr-decl { | constr-decl } *)
49184926
and parse_type_constructor_declarations ?first p =
4927+
let () = print_endline "2" in
49194928
let first_constr_decl =
49204929
match first with
49214930
| 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
49224937
let start_pos = p.Parser.start_pos in
49234938
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}
49254941
| Some first_constr_decl -> first_constr_decl
49264942
in
49274943
first_constr_decl
@@ -4947,7 +4963,8 @@ and parse_type_representation ?current_type_name_path ?inline_types_context p =
49474963
in
49484964
let kind =
49494965
match p.Parser.token with
4950-
| Bar | Uident _ ->
4966+
| Bar | Uident _ | DocComment _ ->
4967+
let () = print_endline "1" in
49514968
Parsetree.Ptype_variant (parse_type_constructor_declarations p)
49524969
| Lbrace ->
49534970
Parsetree.Ptype_record
@@ -5500,7 +5517,11 @@ and parse_type_equation_and_representation ?current_type_name_path
55005517
parse_record_or_object_decl ?current_type_name_path ?inline_types_context
55015518
p
55025519
| 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+
*)
55045525
let priv, kind = parse_type_representation p in
55055526
(None, priv, kind)
55065527
| _ -> (
@@ -5606,6 +5627,7 @@ and parse_type_definitions ~current_type_name_path ~inline_types_context ~attrs
56065627
* implemented for now. Needed to get a feel for the complexities of
56075628
* this territory of the grammar *)
56085629
and parse_type_definition_or_extension ~attrs p =
5630+
let () = print_endline "0" in
56095631
let start_pos = p.Parser.start_pos in
56105632
Parser.expect Token.Typ p;
56115633
let rec_flag =

0 commit comments

Comments
 (0)