Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ profile. This started with version 0.26.0.

### Added

- Support for OCaml 5.4 (#2717, @Julow)
- Support for OCaml 5.4 (#2717, #2720, @Julow, @Octachron)

- Added option `module-indent` option (#2711, @HPRIOR) to control the indentation
of items within modules. This affects modules and signatures. For example,
Expand Down
42 changes: 26 additions & 16 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ let longident_is_simple c x =
let rec length x =
match x with
| Longident.Lident x -> String.length x
| Ldot (x, y) -> length x + 1 + String.length y
| Lapply (x, y) -> length x + length y + 3
| Ldot (x, y) -> length x.txt + 1 + String.length y.txt
| Lapply (x, y) -> length x.txt + length y.txt + 3
in
longident_fit_margin c (length x)

Expand Down Expand Up @@ -977,14 +977,15 @@ end = struct
| Ptyp_alias (t1, _) | Ptyp_poly (_, t1) -> assert (typ == t1)
| Ptyp_arrow (t, t2) ->
assert (List.exists t ~f:(fun x -> typ == x.pap_type) || typ == t2)
| Ptyp_tuple t1N | Ptyp_constr (_, t1N) -> assert (List.exists t1N ~f)
| Ptyp_tuple t1N -> assert (List.exists t1N ~f:snd_f)
| Ptyp_constr (_, t1N) -> assert (List.exists t1N ~f)
| Ptyp_variant (r1N, _, _) ->
assert (
List.exists r1N ~f:(function
| {prf_desc= Rtag (_, _, t1N); _} -> List.exists t1N ~f
| {prf_desc= Rinherit t1; _} -> typ == t1 ) )
| Ptyp_open (_, t1) -> assert (t1 == typ)
| Ptyp_package (_, it1N, _) -> assert (List.exists it1N ~f:snd_f)
| Ptyp_package ptyp -> assert (List.exists ptyp.ppt_cstrs ~f:snd_f)
| Ptyp_object (fields, _) ->
assert (
List.exists fields ~f:(function
Expand Down Expand Up @@ -1017,15 +1018,15 @@ end = struct
match ctx.ppat_desc with
| Ppat_constraint (_, t1) -> assert (typ == t1)
| Ppat_extension (_, PTyp t) -> assert (typ == t)
| Ppat_unpack (_, Some (_, l, _)) ->
assert (List.exists l ~f:(fun (_, t) -> typ == t))
| Ppat_unpack (_, Some ptyp) ->
assert (List.exists ptyp.ppt_cstrs ~f:(fun (_, t) -> typ == t))
| Ppat_record (l, _) ->
assert (List.exists l ~f:(fun (_, t, _) -> Option.exists t ~f))
| _ -> assert false )
| Exp ctx -> (
match ctx.pexp_desc with
| Pexp_pack (_, Some (_, it1N, _), _) ->
assert (List.exists it1N ~f:snd_f)
| Pexp_pack (_, Some ptyp, _) ->
assert (List.exists ptyp.ppt_cstrs ~f:snd_f)
| Pexp_constraint (_, t1)
|Pexp_coerce (_, None, t1)
|Pexp_extension (_, PTyp t1) ->
Expand Down Expand Up @@ -1063,7 +1064,7 @@ end = struct
| Mod ctx -> (
match ctx.pmod_desc with
| Pmod_unpack (_, ty1, ty2) ->
let f (_, cstrs, _) = List.exists cstrs ~f:(fun (_, x) -> f x) in
let f ptyp = List.exists ptyp.ppt_cstrs ~f:snd_f in
assert (Option.exists ty1 ~f || Option.exists ty2 ~f)
| _ -> assert false )
| Sig ctx -> (
Expand Down Expand Up @@ -1255,7 +1256,9 @@ end = struct
| Pat ctx -> (
let f pI = pI == pat in
match ctx.ppat_desc with
| Ppat_array p1N | Ppat_list p1N | Ppat_tuple p1N | Ppat_cons p1N ->
| Ppat_tuple (p1N, _) ->
assert (List.exists p1N ~f:(fun (_, x) -> f x))
| Ppat_array p1N | Ppat_list p1N | Ppat_cons p1N ->
assert (List.exists p1N ~f)
| Ppat_record (p1N, _) ->
assert (List.exists p1N ~f:(fun (_, _, x) -> Option.exists x ~f))
Expand Down Expand Up @@ -1423,7 +1426,8 @@ end = struct
| Pexp_apply (e0, e1N) ->
(* FAIL *)
assert (e0 == exp || List.exists e1N ~f:snd_f)
| Pexp_tuple e1N | Pexp_array e1N | Pexp_list e1N | Pexp_cons e1N ->
| Pexp_tuple e1N -> assert (List.exists e1N ~f:snd_f)
| Pexp_array e1N | Pexp_list e1N | Pexp_cons e1N ->
assert (List.exists e1N ~f)
| Pexp_construct (_, e) | Pexp_variant (_, e) ->
assert (Option.exists e ~f)
Expand Down Expand Up @@ -1529,7 +1533,10 @@ end = struct
&& fit_margin c (width xexp)
| Pexp_construct (_, Some e0) | Pexp_variant (_, Some e0) ->
Exp.is_trivial e0
| Pexp_array e1N | Pexp_list e1N | Pexp_tuple e1N ->
| Pexp_tuple e1N ->
List.for_all e1N ~f:(snd >> Exp.is_trivial)
&& fit_margin c (width xexp)
| Pexp_array e1N | Pexp_list e1N ->
List.for_all e1N ~f:Exp.is_trivial && fit_margin c (width xexp)
| Pexp_record (e1N, e0) ->
Option.for_all e0 ~f:Exp.is_trivial
Expand Down Expand Up @@ -1631,7 +1638,7 @@ end = struct
| {ast= Typ _; _} -> None
| {ctx= Exp {pexp_desc; _}; ast= Exp exp} -> (
match pexp_desc with
| Pexp_tuple (e0 :: _) ->
| Pexp_tuple ((_, e0) :: _) ->
Some (Comma, if exp == e0 then Left else Right)
| Pexp_cons l ->
Some (ColonColon, if exp == List.last_exn l then Right else Left)
Expand Down Expand Up @@ -1848,6 +1855,9 @@ end = struct
( Str {pstr_desc= Pstr_exception _; _}
| Sig {psig_desc= Psig_exception _; _} ) } ->
true
| { ast= {ptyp_desc= Ptyp_tuple ((Some _, _) :: _); _}
; ctx= Typ {ptyp_desc= Ptyp_arrow _; _} } ->
true
| _ -> (
match ambig_prec (sub_ast ~ctx (Typ typ)) with
| `Ambiguous -> true
Expand Down Expand Up @@ -2087,7 +2097,7 @@ end = struct
|Pexp_try (_, cases, _) ->
continue (List.last_exn cases).pc_rhs
| Pexp_apply (_, args) -> continue (snd (List.last_exn args))
| Pexp_tuple es -> continue (List.last_exn es)
| Pexp_tuple es -> continue (snd @@ List.last_exn es)
| Pexp_array _ | Pexp_list _ | Pexp_coerce _ | Pexp_constant _
|Pexp_constraint _
|Pexp_construct (_, None)
Expand Down Expand Up @@ -2168,7 +2178,7 @@ end = struct
| Pexp_indexop_access {pia_rhs= rhs; _} -> (
match rhs with Some e -> continue e | None -> false )
| Pexp_apply (_, args) -> continue (snd (List.last_exn args))
| Pexp_tuple es -> continue (List.last_exn es)
| Pexp_tuple es -> continue (snd @@ List.last_exn es)
| Pexp_array _ | Pexp_list _ | Pexp_coerce _ | Pexp_constant _
|Pexp_constraint _
|Pexp_construct (_, None)
Expand Down Expand Up @@ -2220,7 +2230,7 @@ end = struct
&& Option.value_map ~default:false (prec_ast ctx) ~f:(fun p ->
Prec.compare p Apply < 0 ) ->
true
| Pexp_tuple e1N -> List.last_exn e1N == xexp.ast
| Pexp_tuple e1N -> snd (List.last_exn e1N) == xexp.ast
| _ -> false
in
match ambig_prec (sub_ast ~ctx (Exp exp)) with
Expand Down
5 changes: 4 additions & 1 deletion lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,10 @@ module Formatting = struct

let module_indent =
let docv = "COLS" in
let doc = "Indentation of items within struct ... end and sig ... end ($(docv) columns)." in
let doc =
"Indentation of items within struct ... end and sig ... end ($(docv) \
columns)."
in
let names = ["module-indent"] in
Decl.int ~names ~default ~doc ~docv ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with module_indent= elt}))
Expand Down
4 changes: 2 additions & 2 deletions lib/Exposed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Left = struct
let rec core_type typ =
match typ.ptyp_desc with
| Ptyp_arrow (t :: _, _) -> core_type t.pap_type
| Ptyp_tuple l -> core_type (List.hd_exn l)
| Ptyp_tuple l -> core_type (snd @@ List.hd_exn l)
| Ptyp_object _ -> true
| Ptyp_alias (typ, _) -> core_type typ
| _ -> false
Expand All @@ -29,7 +29,7 @@ module Right = struct
| {ptyp_desc; _} -> (
match ptyp_desc with
| Ptyp_arrow (_, t) -> core_type t
| Ptyp_tuple l -> core_type (List.last_exn l)
| Ptyp_tuple l -> core_type (snd @@ List.last_exn l)
| Ptyp_object _ -> true
| _ -> false )

Expand Down
20 changes: 0 additions & 20 deletions lib/Extended_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,26 +222,6 @@ module Parse = struct
&& not (Std_longident.is_monadic_binding longident) ->
let label_loc = {txt= op; loc= loc_op} in
{e with pexp_desc= Pexp_infix (label_loc, m.expr m l, m.expr m r)}
(* [(module M) : (module T)] -> [(module M : T)] *)
| { pexp_desc=
Pexp_constraint
( { pexp_desc=
Pexp_pack (name, None, {infix_ext= None; infix_attrs= []})
; pexp_attributes= []
; pexp_loc
; _ }
, {ptyp_desc= Ptyp_package pt; ptyp_attributes= []; ptyp_loc; _}
)
; _ } as p
when Migrate_ast.Location.compare_start ptyp_loc pexp_loc > 0 ->
(* Match locations to differentiate between the two position for
the constraint, we want to shorten the second: - [let _ :
(module S) = (module M)] - [let _ = ((module M) : (module
S))] *)
{ p with
pexp_desc=
Pexp_pack (name, Some pt, {infix_ext= None; infix_attrs= []})
}
| e -> Ast_mapper.default_mapper.expr m e
in
Ast_mapper.{default_mapper with expr; pat; binding_op}
Expand Down
Loading
Loading