Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 64195ca

Browse files
committed
Rough test with let Some.
1 parent e01c050 commit 64195ca

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/res_core.ml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,7 @@ and parseExprBlockItem p =
30663066
Ast_helper.Exp.open_ ~loc od.popen_override od.popen_lid blockExpr
30673067
| Let ->
30683068
let recFlag, letBindings = parseLetBindings ~attrs p in
3069+
30693070
parseNewlineOrSemicolonExprBlock p;
30703071
let next =
30713072
if Grammar.isBlockExprStart p.Parser.token then parseExprBlock p
@@ -3076,7 +3077,35 @@ and parseExprBlockItem p =
30763077
None
30773078
in
30783079
let loc = mkLoc startPos p.prevEndPos in
3079-
Ast_helper.Exp.let_ ~loc recFlag letBindings next
3080+
3081+
let res =
3082+
match letBindings with
3083+
| [
3084+
{
3085+
pvb_pat =
3086+
{
3087+
ppat_desc =
3088+
Ppat_construct
3089+
({txt = Lident "Some"}, Some ({ppat_desc = Ppat_var _} as pat));
3090+
};
3091+
pvb_expr;
3092+
};
3093+
]
3094+
when recFlag = Nonrecursive ->
3095+
let lid_none = Location.mknoloc (Longident.Lident "None") in
3096+
let pat_none = Ast_helper.Pat.construct lid_none None in
3097+
let exp_none = Ast_helper.Exp.construct lid_none None in
3098+
let case_none = Ast_helper.Exp.case pat_none exp_none in
3099+
let lid_some = Location.mknoloc (Longident.Lident "Some") in
3100+
let pat_some = Ast_helper.Pat.construct lid_some (Some pat) in
3101+
let case_some = Ast_helper.Exp.case pat_some next in
3102+
let match_exp =
3103+
Ast_helper.Exp.match_ ~loc pvb_expr [case_none; case_some]
3104+
in
3105+
match_exp
3106+
| _ -> Ast_helper.Exp.let_ ~loc recFlag letBindings next
3107+
in
3108+
res
30803109
| _ ->
30813110
let e1 =
30823111
let expr = parseExpr p in
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let foo = (x, y) => {
2+
let Some(vx) = x
3+
let Some(vy) = y
4+
Some(vx + vy)
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let foo x y =
2+
((match x with
3+
| None -> None
4+
| Some vx -> (match y with | None -> None | Some vy -> Some (vx + vy)))
5+
[@ns.braces ])

0 commit comments

Comments
 (0)