Skip to content

Commit 12bd0f8

Browse files
committed
Parse doc comments in type parameters.
1 parent 379b4ae commit 12bd0f8

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;
@@ -6394,15 +6402,17 @@ and parseAttribute p =
63946402
Some (attrId, payload)
63956403
| DocComment (loc, s) ->
63966404
Parser.next p;
6397-
Some
6398-
( {txt = "res.doc"; loc},
6399-
PStr
6400-
[
6401-
Ast_helper.Str.eval ~loc
6402-
(Ast_helper.Exp.constant ~loc (Pconst_string (s, None)));
6403-
] )
6405+
Some (docCommentToAttribute loc s)
64046406
| _ -> None
64056407

6408+
and docCommentToAttribute loc s : Parsetree.attribute =
6409+
( {txt = "res.doc"; loc},
6410+
PStr
6411+
[
6412+
Ast_helper.Str.eval ~loc
6413+
(Ast_helper.Exp.constant ~loc (Pconst_string (s, None)));
6414+
] )
6415+
64066416
and parseAttributes p =
64076417
parseRegion p ~grammar:Grammar.Attribute ~f:parseAttribute
64086418

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)