@@ -1208,13 +1208,13 @@ end = struct
12081208 in
12091209 let check_cases = List. exists ~f: (fun c -> c.pc_lhs == pat) in
12101210 let check_binding {pvb_pat; pvb_body; _} =
1211- check_subpat pvb_pat || match pvb_body with
1212- | Pfunction_body _ -> false
1213- | Pfunction_cases (cases , _ , _ ) ->
1214- check_cases cases in
1215- let check_bindings l =
1216- List. exists l ~f: check_binding
1211+ check_subpat pvb_pat
1212+ ||
1213+ match pvb_body with
1214+ | Pfunction_body _ -> false
1215+ | Pfunction_cases (cases , _ , _ ) -> check_cases cases
12171216 in
1217+ let check_bindings l = List. exists l ~f: check_binding in
12181218 let check_param_val (_ , _ , p ) = p == pat in
12191219 let check_expr_function_param param =
12201220 match param.pparam_desc with
@@ -1389,7 +1389,8 @@ end = struct
13891389 assert (check_cases cases)
13901390 | Pexp_function (params , _ , body ) ->
13911391 assert (
1392- List. exists ~f: check_expr_function_param params || check_fun_body body )
1392+ List. exists ~f: check_expr_function_param params
1393+ || check_fun_body body )
13931394 | Pexp_indexop_access {pia_lhs; pia_kind = Builtin idx ; pia_rhs; _} ->
13941395 assert (
13951396 pia_lhs == exp || idx == exp
@@ -1927,10 +1928,11 @@ end = struct
19271928 | Ppat_or _ | Ppat_alias _ ) ) ->
19281929 true
19291930 | Bo {pbop_typ = Some _ ; _} , (Ppat_any | Ppat_tuple _ ) -> true
1930- | Exp {pexp_desc= ( Pexp_function (_, _, Pfunction_body _) ); _}, Ppat_or _
1931+ | Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _}, Ppat_or _
19311932 | ( Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _}
19321933 , ( Ppat_construct _ | Ppat_cons _ | Ppat_lazy _ | Ppat_tuple _
1933- | Ppat_variant _ ) ) -> true
1934+ | Ppat_variant _ ) ) ->
1935+ true
19341936 | _, Ppat_constraint _
19351937 | _, Ppat_unpack _
19361938 | ( Pat
@@ -1944,8 +1946,7 @@ end = struct
19441946 ( Ppat_construct _ | Ppat_exception _ | Ppat_or _
19451947 | Ppat_lazy _ | Ppat_tuple _ | Ppat_variant _ | Ppat_list _ )
19461948 ; _ }
1947- | Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _}
1948- )
1949+ | Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _} )
19491950 , Ppat_alias _ )
19501951 | ( Pat {ppat_desc= Ppat_lazy _; _}
19511952 , ( Ppat_construct _ | Ppat_cons _
@@ -1966,8 +1967,7 @@ end = struct
19661967 | Cl {pcl_desc= Pcl_fun _; _}, Ppat_construct _
19671968 | Cl {pcl_desc= Pcl_fun _; _}, Ppat_alias _
19681969 | Cl {pcl_desc= Pcl_fun _; _}, Ppat_lazy _
1969- | (Exp {pexp_desc= Pexp_letop _; _} | Bo _), Ppat_exception _
1970- ->
1970+ | (Exp {pexp_desc= Pexp_letop _; _} | Bo _ ), Ppat_exception _ ->
19711971 true
19721972 | (Str _ | Exp _ | Lb _ ), Ppat_lazy _ -> true
19731973 | ( (Fpe _ | Fpc _)
@@ -1995,14 +1995,14 @@ end = struct
19951995 true
19961996 | _ -> false
19971997
1998- (* Whether an expression in a let binding shouldn't be parenthesed, bypassing
1999- the other Ast rules. *)
1998+ (* Whether an expression in a let binding shouldn't be parenthesed,
1999+ bypassing the other Ast rules. *)
20002000 let dont_parenze_exp_in_bindings bindings exp =
20012001 match exp.pexp_desc with
20022002 | Pexp_function ([] , None, (Pfunction_cases _ as fun_body )) ->
20032003 (* [fun_body] is the body of the let binding and shouldn't be
2004- parenthesed. [exp] is a synthetic expression constructed in
2005- the formatting code. *)
2004+ parenthesed. [exp] is a synthetic expression constructed in the
2005+ formatting code. *)
20062006 List. exists bindings ~f: (fun {pvb_body; _} -> pvb_body == fun_body)
20072007 | _ -> false
20082008
@@ -2170,16 +2170,19 @@ end = struct
21702170 (* Whether to parenze an expr on the RHS of a let binding.
21712171 [dont_parenze_exp_in_bindings] must have been checked before. *)
21722172 and parenze_exp_in_bindings bindings exp =
2173- List. exists bindings ~f: (fun {pvb_body; pvb_args; _} ->
2174- match pvb_body with
2175- | Pfunction_body ({pexp_desc = Pexp_function ([] ,None,Pfunction_cases _ );_} as let_body ) when let_body == exp ->
2176- (* Function with cases and no 'fun' keyword is in the body of
2177- a binding, parentheses are needed if the binding also
2178- defines arguments. *)
2179- not (List. is_empty pvb_args)
2180- | Pfunction_cases (cases ,_ ,_ ) -> parenze_exp_in_match_case cases exp
2181- | _ -> false
2182- )
2173+ List. exists bindings ~f: (fun {pvb_body; pvb_args; _} ->
2174+ match pvb_body with
2175+ | Pfunction_body
2176+ ( {pexp_desc= Pexp_function ([] , None , Pfunction_cases _); _} as
2177+ let_body )
2178+ when let_body == exp ->
2179+ (* Function with cases and no 'fun' keyword is in the body of a
2180+ binding, parentheses are needed if the binding also defines
2181+ arguments. *)
2182+ not (List. is_empty pvb_args)
2183+ | Pfunction_cases (cases , _ , _ ) ->
2184+ parenze_exp_in_match_case cases exp
2185+ | _ -> false )
21832186
21842187 (* * [parenze_exp {ctx; ast}] holds when expression [ast] should be
21852188 parenthesized in context [ctx]. *)
@@ -2235,18 +2238,19 @@ end = struct
22352238 ||
22362239 match (ctx, exp) with
22372240 | Str {pstr_desc = Pstr_eval _ ; _} , _ -> false
2238- | ( Lb pvb , _ ) when dont_parenze_exp_in_bindings [pvb] exp -> false
2239- | ( Exp {pexp_desc= Pexp_let ({ pvbs_bindings; _ }, _, _);_}, _)
2240- | ( Cl {pcl_desc= Pcl_let ({ pvbs_bindings; _ }, _,_);_}, _)
2241+ | Lb pvb , _ when dont_parenze_exp_in_bindings [pvb] exp -> false
2242+ | Exp {pexp_desc= Pexp_let ({pvbs_bindings; _}, _, _); _}, _
2243+ | Cl {pcl_desc= Pcl_let ({pvbs_bindings; _}, _, _); _}, _
22412244 when dont_parenze_exp_in_bindings pvbs_bindings exp ->
22422245 false
2243- | ( Lb pvb , _ ) when parenze_exp_in_bindings [pvb] exp ->
2244- true
2245- | ( Exp {pexp_desc= Pexp_let ({ pvbs_bindings; _ }, _, _);_}, _)
2246- | ( Cl {pcl_desc= Pcl_let ({ pvbs_bindings; _ }, _,_);_}, _)
2246+ | Lb pvb , _ when parenze_exp_in_bindings [pvb] exp -> true
2247+ | Exp {pexp_desc= Pexp_let ({pvbs_bindings; _}, _, _); _}, _
2248+ | Cl {pcl_desc= Pcl_let ({pvbs_bindings; _}, _, _); _}, _
22472249 when parenze_exp_in_bindings pvbs_bindings exp ->
22482250 true
2249- | _ , {pexp_desc = Pexp_infix _ ; pexp_attributes = _ :: _ ; _} when ctx_sensitive_to_trailing_attributes ctx -> true
2251+ | _, {pexp_desc= Pexp_infix _; pexp_attributes= _ :: _ ; _}
2252+ when ctx_sensitive_to_trailing_attributes ctx ->
2253+ true
22502254 | ( Str
22512255 { pstr_desc=
22522256 Pstr_value
@@ -2336,24 +2340,27 @@ end = struct
23362340 , {pexp_desc= Pexp_function ([] , None , Pfunction_cases _); _} )
23372341 when e == exp ->
23382342 true
2339- | Exp {pexp_desc=
2340- Pexp_extension
2341- ( _
2342- , PStr
2343- [ { pstr_desc=
2344- Pstr_eval
2345- ( { pexp_desc=
2346- ( Pexp_function
2347- (_, _, Pfunction_cases (cases, _, _))
2348- | Pexp_match (_, cases)
2349- | Pexp_try (_, cases) )
2350- ; _ }
2351- , _ )
2352- ; _ } ] )
2353- | Pexp_function (_, _, Pfunction_cases (cases, _, _))
2354- | Pexp_match (_, cases)
2355- | Pexp_try (_, cases)
2356- ; _}, _ -> parenze_exp_in_match_case cases exp
2343+ | ( Exp
2344+ { pexp_desc=
2345+ ( Pexp_extension
2346+ ( _
2347+ , PStr
2348+ [ { pstr_desc=
2349+ Pstr_eval
2350+ ( { pexp_desc=
2351+ ( Pexp_function
2352+ (_, _, Pfunction_cases (cases, _, _))
2353+ | Pexp_match (_, cases)
2354+ | Pexp_try (_, cases) )
2355+ ; _ }
2356+ , _ )
2357+ ; _ } ] )
2358+ | Pexp_function (_, _, Pfunction_cases (cases, _, _))
2359+ | Pexp_match (_, cases)
2360+ | Pexp_try (_, cases) )
2361+ ; _ }
2362+ , _ ) ->
2363+ parenze_exp_in_match_case cases exp
23572364 | Exp {pexp_desc; _} , _ -> (
23582365 match pexp_desc with
23592366 | Pexp_ifthenelse (eN, _)
@@ -2417,7 +2424,10 @@ end = struct
24172424 | _ -> Exp. has_trailing_attributes exp || parenze () ) )
24182425 | _ , {pexp_desc = Pexp_list _ ; _} -> false
24192426 | _ , {pexp_desc = Pexp_array _ ; _} -> false
2420- | _ , exp when ctx_sensitive_to_trailing_attributes ctx && Exp. has_trailing_attributes exp -> true
2427+ | _, exp
2428+ when ctx_sensitive_to_trailing_attributes ctx
2429+ && Exp. has_trailing_attributes exp ->
2430+ true
24212431 | _ -> false
24222432
24232433 (* * [parenze_cl {ctx; ast}] holds when class expr [ast] should be
0 commit comments