@@ -5265,24 +5265,25 @@ and parse_constr_decl_args p =
52655265 in
52665266 (constr_args, res)
52675267
5268+ (* Helper to check if current token is a bar or doc comment followed by a bar *)
5269+ and is_bar_or_doc_comment_then_bar p =
5270+ Parser. lookahead p (fun state ->
5271+ match state.Parser. token with
5272+ | DocComment _ -> (
5273+ Parser. next state;
5274+ match state.token with
5275+ | Bar -> true
5276+ | _ -> false )
5277+ | Bar -> true
5278+ | _ -> false )
5279+
52685280(* constr-decl ::=
52695281 * | constr-name
52705282 * | attrs constr-name
52715283 * | constr-name const-args
52725284 * | attrs constr-name const-args *)
52735285and parse_type_constructor_declaration_with_bar p =
5274- let is_constructor_with_bar p =
5275- Parser. lookahead p (fun state ->
5276- match state.Parser. token with
5277- | DocComment _ -> (
5278- Parser. next state;
5279- match state.token with
5280- | Bar -> true
5281- | _ -> false )
5282- | Bar -> true
5283- | _ -> false )
5284- in
5285- if is_constructor_with_bar p then (
5286+ if is_bar_or_doc_comment_then_bar p then (
52865287 let doc_comment_attrs =
52875288 match p.Parser. token with
52885289 | DocComment (loc , s ) ->
@@ -5905,29 +5906,84 @@ and parse_tag_spec_full p =
59055906
59065907and parse_tag_specs p =
59075908 match p.Parser. token with
5908- | Bar ->
5909- Parser. next p;
5910- let row_field = parse_tag_spec p in
5911- row_field :: parse_tag_specs p
5909+ | (Bar | DocComment _ ) when is_bar_or_doc_comment_then_bar p ->
5910+ let doc_comment_attrs =
5911+ match p.Parser. token with
5912+ | DocComment (loc , s ) ->
5913+ Parser. next p;
5914+ [doc_comment_to_attribute loc s]
5915+ | _ -> []
5916+ in
5917+ Parser. expect Bar p;
5918+ let tag = parse_tag_spec p in
5919+ let tag_with_doc =
5920+ match tag with
5921+ | Parsetree. Rtag (name , attrs , contains_constant , types ) ->
5922+ Parsetree. Rtag
5923+ (name, doc_comment_attrs @ attrs, contains_constant, types)
5924+ | Rinherit typ ->
5925+ Rinherit
5926+ {typ with ptyp_attributes = doc_comment_attrs @ typ.ptyp_attributes}
5927+ in
5928+ tag_with_doc :: parse_tag_specs p
59125929 | _ -> []
59135930
59145931and parse_tag_spec p =
5915- let attrs = parse_attributes p in
5932+ let doc_comment_attrs =
5933+ match p.Parser. token with
5934+ | DocComment (loc , s ) ->
5935+ Parser. next p;
5936+ [doc_comment_to_attribute loc s]
5937+ | _ -> []
5938+ in
5939+ let attrs = doc_comment_attrs @ parse_attributes p in
59165940 match p.Parser. token with
59175941 | Hash -> parse_polymorphic_variant_type_spec_hash ~attrs ~full: false p
59185942 | _ ->
59195943 let typ = parse_typ_expr ~attrs p in
59205944 Parsetree. Rinherit typ
59215945
59225946and parse_tag_spec_first p =
5923- let attrs = parse_attributes p in
59245947 match p.Parser. token with
5925- | Bar ->
5926- Parser. next p;
5927- [parse_tag_spec p]
5928- | Hash -> [parse_polymorphic_variant_type_spec_hash ~attrs ~full: false p]
5948+ | (Bar | DocComment _ ) when is_bar_or_doc_comment_then_bar p ->
5949+ let doc_comment_attrs =
5950+ match p.Parser. token with
5951+ | DocComment (loc , s ) ->
5952+ Parser. next p;
5953+ [doc_comment_to_attribute loc s]
5954+ | _ -> []
5955+ in
5956+ Parser. expect Bar p;
5957+ let tag = parse_tag_spec p in
5958+ (match tag with
5959+ | Parsetree. Rtag (name , attrs , contains_constant , types ) ->
5960+ Parsetree. Rtag (name, doc_comment_attrs @ attrs, contains_constant, types)
5961+ | Rinherit typ ->
5962+ Rinherit
5963+ {typ with ptyp_attributes = doc_comment_attrs @ typ.ptyp_attributes})
5964+ :: parse_tag_specs p
5965+ | DocComment _ | Hash | At -> (
5966+ let doc_comment_attrs =
5967+ match p.Parser. token with
5968+ | DocComment (loc , s ) ->
5969+ Parser. next p;
5970+ [doc_comment_to_attribute loc s]
5971+ | _ -> []
5972+ in
5973+ let attrs = doc_comment_attrs @ parse_attributes p in
5974+ match p.Parser. token with
5975+ | Hash -> [parse_polymorphic_variant_type_spec_hash ~attrs ~full: false p]
5976+ | _ -> (
5977+ let typ = parse_typ_expr ~attrs p in
5978+ match p.token with
5979+ | Rbracket ->
5980+ (* example: [ListStyleType.t] *)
5981+ [Parsetree. Rinherit typ]
5982+ | _ ->
5983+ Parser. expect Bar p;
5984+ [Parsetree. Rinherit typ; parse_tag_spec p]))
59295985 | _ -> (
5930- let typ = parse_typ_expr ~attrs p in
5986+ let typ = parse_typ_expr p in
59315987 match p.token with
59325988 | Rbracket ->
59335989 (* example: [ListStyleType.t] *)
0 commit comments