Skip to content

Commit

Permalink
clean up curry printing
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn committed Jan 28, 2025
1 parent aecb41c commit fa57c78
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ let protect_longident ppf print_longident longprefix txt =
let is_curry_attr attr =
attr.attr_name.txt = Builtin_attributes.curry_attr_name

let filter_curry_attrs attrs =
List.filter (fun attr -> not (is_curry_attr attr)) attrs

let has_non_curry_attr attrs =
List.exists (fun attr -> not (is_curry_attr attr)) attrs
let split_out_curry_attr attrs =
let curry, non_curry = List.partition is_curry_attr attrs in
let is_curry =
match curry with
| [] -> false
| _ :: _ -> true
in
is_curry, non_curry

type space_formatter = (unit, Format.formatter, unit) format

Expand Down Expand Up @@ -497,10 +500,9 @@ and name_jkind f (name, jkind) =
(jkind_annotation reset_ctxt) jkind
and core_type ctxt f x =
let filtered_attrs = filter_curry_attrs x.ptyp_attributes in
if filtered_attrs <> [] then begin
if x.ptyp_attributes <> [] then begin
pp f "((%a)%a)" (core_type ctxt) {x with ptyp_attributes=[]}
(attributes ctxt) filtered_attrs
(attributes ctxt) x.ptyp_attributes
end
else match x.ptyp_desc with
| Ptyp_arrow (l, ct1, ct2, m1, m2) ->
Expand All @@ -524,8 +526,7 @@ and core_type ctxt f x =
| _ -> pp f "@[<2>%a@]" (core_type1 ctxt) x
and core_type1 ctxt f x =
(* CR zqian: the logic about curry should be pushed into Ptyp_arrow *)
if has_non_curry_attr x.ptyp_attributes then core_type ctxt f x
if x.ptyp_attributes <> [] then core_type ctxt f x
else
match x.ptyp_desc with
| Ptyp_any jkind -> tyvar_loc_option_jkind f (None, jkind)
Expand Down Expand Up @@ -627,7 +628,9 @@ and labeled_core_type1 ctxt f (label, ty) =
core_type1 ctxt f ty
and return_type ctxt f (x, m) =
if x.ptyp_attributes <> [] then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
let is_curry, ptyp_attributes = split_out_curry_attr x.ptyp_attributes in
let x = {x with ptyp_attributes} in
if is_curry then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
else core_type_with_optional_legacy_modes core_type ctxt f (x, m)
and core_type_with_optional_modes ctxt f (ty, modes) =
Expand Down

0 comments on commit fa57c78

Please sign in to comment.