Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Represent 'let f _ = function' in the CST #2596

Merged
merged 22 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor
  • Loading branch information
Julow committed Oct 22, 2024
commit bf75249c57ab0f03b5f3f8523b3875e6bd0c84f5
34 changes: 15 additions & 19 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1875,25 +1875,21 @@ end = struct
| _ -> false

let parenze_pat_in_bindings bindings pat =
(* [pat] appears on the left side of a binding. *)
List.exists bindings ~f:(fun {pvb_pat; _} ->
pvb_pat == pat
) &&
(* Some patterns must be parenthesed when followed by a colon. *)
if exposed_right_colon pat &&
List.exists bindings ~f:(fun pvb ->
pvb.pvb_pat == pat &&
Option.is_some pvb.pvb_constraint
)
then true
else
match pat.ppat_desc with
Ppat_construct (_, Some _)
| Ppat_variant (_, Some _)
| Ppat_cons _ | Ppat_alias _ | Ppat_or _ ->
(* Add disambiguation parentheses that are not necessary. *)
true
| _ -> false
let parenze_pat_in_binding ~pvb_constraint =
(* Some patterns must be parenthesed when followed by a colon. *)
(exposed_right_colon pat && Option.is_some pvb_constraint)
||
match pat.ppat_desc with
| Ppat_construct (_, Some _)
|Ppat_variant (_, Some _)
|Ppat_cons _ | Ppat_alias _ | Ppat_or _ ->
(* Add disambiguation parentheses that are not necessary. *)
true
| _ -> false
in
List.exists bindings ~f:(fun {pvb_pat; pvb_constraint; _} ->
(* [pat] appears on the left side of a binding. *)
pvb_pat == pat && parenze_pat_in_binding ~pvb_constraint )

(** [parenze_pat {ctx; ast}] holds when pattern [ast] should be
parenthesized in context [ctx]. *)
Expand Down