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

Commit 769d719

Browse files
intead by fold_left to suppress reanalyze termination check
1 parent 3f77897 commit 769d719

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

src/res_core.ml

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,24 +3718,28 @@ and parseSpreadExprRegionWithLoc p =
37183718

37193719
and parseListExpr ~startPos p =
37203720
let split_by_spread exprs =
3721-
let rec loop exprs acc =
3722-
match exprs, acc with
3723-
| [], acc -> acc
3724-
| (true, expr, startPos, endPos) :: exprs, _ ->
3725-
(* find a spread expression, prepend a new sublist *)
3726-
loop exprs (([], Some expr, startPos, endPos) :: acc)
3727-
| (false, expr, startPos, _endPos) :: exprs, ((no_spreads, spread, _accStartPos, accEndPos) :: acc) ->
3728-
(* find a non-spread expression, and the accumulated is not empty,
3729-
* prepend to the first sublist, and update the loc first sublist *)
3730-
loop exprs ((expr :: no_spreads, spread, startPos, accEndPos) :: acc)
3731-
| (false, expr, startPos, endPos) :: exprs, [] ->
3732-
(* find a non-spread expression, and the accumulated is empty *)
3733-
loop exprs [[expr] , None, startPos, endPos] in
3734-
loop exprs [] in
3721+
List.fold_left
3722+
(fun acc curr ->
3723+
match (curr, acc) with
3724+
| (true, expr, startPos, endPos), _ ->
3725+
(* find a spread expression, prepend a new sublist *)
3726+
([], Some expr, startPos, endPos) :: acc
3727+
| ( (false, expr, startPos, _endPos),
3728+
(no_spreads, spread, _accStartPos, accEndPos) :: acc ) ->
3729+
(* find a non-spread expression, and the accumulated is not empty,
3730+
* prepend to the first sublist, and update the loc first sublist *)
3731+
(expr :: no_spreads, spread, startPos, accEndPos) :: acc
3732+
| (false, expr, startPos, endPos), [] ->
3733+
(* find a non-spread expression, and the accumulated is empty *)
3734+
[([expr], None, startPos, endPos)])
3735+
[] exprs
3736+
in
37353737
let make_sub_expr = function
37363738
| exprs, Some spread, startPos, endPos ->
3737-
makeListExpression (mkLoc startPos endPos) exprs (Some spread)
3738-
| exprs, None, startPos, endPos -> makeListExpression (mkLoc startPos endPos) exprs None in
3739+
makeListExpression (mkLoc startPos endPos) exprs (Some spread)
3740+
| exprs, None, startPos, endPos ->
3741+
makeListExpression (mkLoc startPos endPos) exprs None
3742+
in
37393743
let listExprsRev =
37403744
parseCommaDelimitedReversedList p ~grammar:Grammar.ListExpr ~closing:Rbrace
37413745
~f:parseSpreadExprRegionWithLoc
@@ -3744,22 +3748,23 @@ and parseListExpr ~startPos p =
37443748
let loc = mkLoc startPos p.prevEndPos in
37453749
match split_by_spread listExprsRev with
37463750
| [] -> makeListExpression loc [] None
3747-
| [exprs, Some spread, _, _] -> makeListExpression loc exprs (Some spread)
3748-
| [exprs, None, _, _] -> makeListExpression loc exprs None
3751+
| [(exprs, Some spread, _, _)] -> makeListExpression loc exprs (Some spread)
3752+
| [(exprs, None, _, _)] -> makeListExpression loc exprs None
37493753
| exprs ->
3750-
let listExprs = List.map
3751-
make_sub_expr
3752-
exprs in
3753-
Ast_helper.Exp.(apply ~loc
3754-
(Ast_helper.Exp.ident ~loc
3755-
(Location.mkloc (Longident.(Ldot (Ldot (Lident "Belt", "List"), "concatMany"))) loc))
3756-
[Asttypes.Nolabel, Ast_helper.Exp.array ~loc listExprs])
3757-
(* | (true (\* spread expression *\), expr, _) :: exprs ->
3758-
* let exprs = check_all_non_spread_exp exprs in
3759-
* makeListExpression loc exprs (Some expr)
3760-
* | exprs ->
3761-
* let exprs = check_all_non_spread_exp exprs in
3762-
* makeListExpression loc exprs None *)
3754+
let listExprs = List.map make_sub_expr exprs in
3755+
Ast_helper.Exp.apply ~loc
3756+
(Ast_helper.Exp.ident ~loc
3757+
(Location.mkloc
3758+
(Longident.Ldot
3759+
(Longident.Ldot (Longident.Lident "Belt", "List"), "concatMany"))
3760+
loc))
3761+
[(Asttypes.Nolabel, Ast_helper.Exp.array ~loc listExprs)]
3762+
(* | (true (\* spread expression *\), expr, _) :: exprs ->
3763+
* let exprs = check_all_non_spread_exp exprs in
3764+
* makeListExpression loc exprs (Some expr)
3765+
* | exprs ->
3766+
* let exprs = check_all_non_spread_exp exprs in
3767+
* makeListExpression loc exprs None *)
37633768

37643769
(* Overparse ... and give a nice error message *)
37653770
and parseNonSpreadExp ~msg p =

0 commit comments

Comments
 (0)