Skip to content

Commit c5a78cc

Browse files
committed
Parse doc comments in type parameters.
1 parent cc00e83 commit c5a78cc

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

res_syntax/src/res_core.ml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,14 +4125,21 @@ and parseTypeAlias p typ =
41254125
* | . type_parameter
41264126
*)
41274127
and parseTypeParameter p =
4128+
let docAttr : Parsetree.attributes =
4129+
match p.Parser.token with
4130+
| DocComment (loc, s) ->
4131+
Parser.next p;
4132+
[docCommentToAttribute loc s]
4133+
| _ -> []
4134+
in
41284135
if
41294136
p.Parser.token = Token.Tilde
41304137
|| p.token = Dot
41314138
|| Grammar.isTypExprStart p.token
41324139
then
41334140
let startPos = p.Parser.startPos in
41344141
let dotted = Parser.optional p Dot in
4135-
let attrs = parseAttributes p in
4142+
let attrs = docAttr @ parseAttributes p in
41364143
match p.Parser.token with
41374144
| Tilde -> (
41384145
Parser.next p;
@@ -4236,6 +4243,7 @@ and parseEs6ArrowType ~attrs p =
42364243
let returnType = parseTypExpr ~alias:false p in
42374244
let loc = mkLoc startPos p.prevEndPos in
42384245
Ast_helper.Typ.arrow ~loc ~attrs arg typ returnType
4246+
| DocComment _ -> assert false
42394247
| _ ->
42404248
let parameters = parseTypeParameters p in
42414249
Parser.expect EqualGreater p;
@@ -6399,15 +6407,17 @@ and parseAttribute p =
63996407
Some (attrId, payload)
64006408
| DocComment (loc, s) ->
64016409
Parser.next p;
6402-
Some
6403-
( {txt = "res.doc"; loc},
6404-
PStr
6405-
[
6406-
Ast_helper.Str.eval ~loc
6407-
(Ast_helper.Exp.constant ~loc (Pconst_string (s, None)));
6408-
] )
6410+
Some (docCommentToAttribute loc s)
64096411
| _ -> None
64106412

6413+
and docCommentToAttribute loc s : Parsetree.attribute =
6414+
( {txt = "res.doc"; loc},
6415+
PStr
6416+
[
6417+
Ast_helper.Str.eval ~loc
6418+
(Ast_helper.Exp.constant ~loc (Pconst_string (s, None)));
6419+
] )
6420+
64116421
and parseAttributes p =
64126422
parseRegion p ~grammar:Grammar.Attribute ~f:parseAttribute
64136423

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let doc1: (/** ddd */ ~x: int) => int = (~x) => x + 1
2+
let doc2: @res.doc(" ddd ") int => int = x => x + 1
3+
let doc3: /** ddd */ int => int = x => x + 1
4+
let doc4: (/** ddd */ ~x: int, /** eee */ n) => int = (~x) => x + 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let doc1: (/** ddd */ ~x: int) => int = (~x) => x + 1
2+
let doc2: /** ddd */ int => int = x => x + 1
3+
let doc3: /** ddd */ int => int = x => x + 1
4+
let doc4: (/** ddd */ ~x: int, /** eee */ n) => int = (~x) => x + 1

0 commit comments

Comments
 (0)