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

Commit 8b85058

Browse files
committed
Separate out parseIfExpression parts
1 parent 690630d commit 8b85058

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/napkin_core.ml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,20 +2993,34 @@ and parseTryExpression p =
29932993
let loc = mkLoc startPos p.prevEndPos in
29942994
Ast_helper.Exp.try_ ~loc expr cases
29952995

2996-
and parseIfExpression p =
2997-
Parser.beginRegion p;
2998-
Parser.leaveBreadcrumb p Grammar.ExprIf;
2999-
let startPos = p.Parser.startPos in
3000-
Parser.expect If p;
2996+
and parseIfCondition p =
30012997
Parser.leaveBreadcrumb p Grammar.IfCondition;
30022998
(* doesn't make sense to try es6 arrow here? *)
30032999
let conditionExpr = parseExpr ~context:WhenExpr p in
30043000
Parser.eatBreadcrumb p;
3001+
conditionExpr
3002+
3003+
and parseIfBranch p =
30053004
Parser.leaveBreadcrumb p IfBranch;
30063005
Parser.expect Lbrace p;
30073006
let thenExpr = parseExprBlock p in
30083007
Parser.expect Rbrace p;
30093008
Parser.eatBreadcrumb p;
3009+
thenExpr
3010+
3011+
and parseElseBranch p =
3012+
Parser.expect Lbrace p;
3013+
let blockExpr = parseExprBlock p in
3014+
Parser.expect Rbrace p;
3015+
blockExpr;
3016+
3017+
and parseIfExpression p =
3018+
Parser.beginRegion p;
3019+
Parser.leaveBreadcrumb p Grammar.ExprIf;
3020+
let startPos = p.Parser.startPos in
3021+
Parser.expect If p;
3022+
let conditionExpr = parseIfCondition p in
3023+
let thenExpr = parseIfBranch p in
30103024
let elseExpr = match p.Parser.token with
30113025
| Else ->
30123026
Parser.endRegion p;
@@ -3017,10 +3031,7 @@ and parseIfExpression p =
30173031
| If ->
30183032
parseIfExpression p
30193033
| _ ->
3020-
Parser.expect Lbrace p;
3021-
let blockExpr = parseExprBlock p in
3022-
Parser.expect Rbrace p;
3023-
blockExpr
3034+
parseElseBranch p
30243035
in
30253036
Parser.eatBreadcrumb p;
30263037
Parser.endRegion p;

0 commit comments

Comments
 (0)