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

Backport Pexp_function from OCaml 5.2 #2544

Merged
merged 164 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
8a2f202
Update vendored compilerlibs for OCaml 5.2
gpetiot Jan 12, 2024
b86e1a9
WIP: Backport 5.2 changes to parser-standard
Julow Jan 18, 2024
d790fe1
Merge branch 'MAIN' into backport-52-standard
Julow Feb 9, 2024
bf45693
Merge branch 'MAIN' into backport-52-standard
Julow Mar 5, 2024
d534e74
parser-extended: Backport Pexp_function
Julow Mar 6, 2024
c662e0c
WIP: Ast
Julow Mar 8, 2024
dae3c6c
WIP: Extended_ast
Julow Mar 8, 2024
9d92bb7
Remove Sugar.fun_
Julow Mar 8, 2024
d7c4392
WIP: Params
Julow Mar 8, 2024
bd08b27
WIP: Fmt_ast
Julow Mar 8, 2024
4931f06
WIP: Fmt_ast
Julow Mar 12, 2024
21a4375
WIP: More precise matching
Julow Mar 18, 2024
4653601
WIP: Preliminary fmt_function
Julow Mar 18, 2024
4af9c73
WIP: Matching
Julow Mar 18, 2024
19eb8ae
WIP: fmt_function call sites
Julow Mar 18, 2024
754da22
WIP
Julow Mar 29, 2024
c8fc8ba
WIP
Julow Apr 4, 2024
8f8eedf
Preliminary implementation of Pexp_function
Julow Apr 4, 2024
247c5c6
Fix space around value binding ':'
Julow Apr 9, 2024
8df232a
Fix AST rules
Julow Apr 9, 2024
6e9ac4b
Add missing space after 'fun'
Julow Apr 9, 2024
976fe38
Fix infix followed by fun
Julow Apr 9, 2024
f80a0ce
Restore let binding docking of 'function'
Julow Apr 10, 2024
8885c20
Fix parenthezed fun indent
Julow Apr 10, 2024
78dc6fd
Fix context passed to fmt_function
Julow Apr 10, 2024
9f436e8
Fix dropped attribute on 'function'
Julow Apr 10, 2024
a18680c
Restore 'fun' and 'function' spacing before attrs
Julow Apr 10, 2024
c0bd645
Missing AST rule for fun type constraints
Julow Apr 10, 2024
e9024cb
Fix special case of 'fun' in some extension points
Julow Apr 10, 2024
e359cd9
Fix misplaced attribute after fun after infix
Julow Apr 10, 2024
27f7ecd
Don't fit toplevel 'function's
Julow Apr 16, 2024
8c07855
Fix unstable vb
Julow Apr 16, 2024
7512388
Revert "Don't fit toplevel 'function's"
Julow Apr 16, 2024
cac739d
Promote tests
Julow Apr 16, 2024
f502604
Add missing wrap_intro space
Julow Apr 16, 2024
8535f4a
Restore let binding type constraints
Julow Apr 16, 2024
f8dd8ad
Fix spacing after fun%ext
Julow Apr 17, 2024
b25984b
Fix indentation of 'infix fun'
Julow Apr 19, 2024
5a3a6c5
dont align function paramater in `let _ = fun`
EmileTrotignon May 6, 2024
207df8b
tests Remove now unecessary --max-iter
Julow May 13, 2024
9958c84
Format comments after pro in expression
Julow May 13, 2024
2afbc1e
Don't ignore Pfunction_cases loc and attrs
Julow May 13, 2024
202bad4
Fix missing space in 'fun _ ->function'
Julow May 13, 2024
7bd9700
Remove space in 'function [@attr]'
Julow May 15, 2024
c814fc7
Restore formatting of '>>= function'
Julow May 15, 2024
822bcf4
Restore docked fun/ction indent and remove one ~box:false
Julow May 17, 2024
1faea29
Restore inconsistent space between 'function [@attr]'
Julow May 17, 2024
560a69e
Merge branch 'MAIN' into backport-52-extended
Julow May 17, 2024
d61e362
Restore de-indented 'let = fun'
Julow May 17, 2024
cc905ad
De-indented 'fun' in 'let in'
Julow May 17, 2024
e762b8e
wip 5.2
EmileTrotignon May 22, 2024
718bab2
break infix
EmileTrotignon May 23, 2024
f2eabc4
remove useless file
EmileTrotignon May 23, 2024
b2fc016
better implementation
EmileTrotignon May 23, 2024
4ca59f5
Restore indentation of 'fun' after a 'let in'
Julow May 24, 2024
d1f68dc
diff on js pattern
EmileTrotignon May 24, 2024
173329e
Remove special implementation of 'function' without 'fun'
Julow May 24, 2024
b8a26cb
Dock 'fun _ -> function' like 'function'
Julow May 24, 2024
d242455
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon May 24, 2024
e2887d5
Names for the new boxes
Julow May 24, 2024
0e10ae1
Fix indentation of '(* cmt *) fun _ ->'
Julow May 24, 2024
46b16b1
Revert change to test/passing/tests/args_grouped.ml
Julow May 27, 2024
b24f9d8
Box debug not showing break_unless_newline and fits_or_breaks
Julow May 27, 2024
542a8ac
Merge branch 'box_debug_missing_breaks' into backport-52-extended
Julow May 27, 2024
7c525f7
Fix break-colon=before regression
Julow May 28, 2024
371ec86
WIP : fix issue 289
EmileTrotignon May 28, 2024
402ef93
fix disambiguate-non-breaking-match
EmileTrotignon Jul 24, 2024
4ac8bf1
fix parens space in match2
EmileTrotignon Jul 24, 2024
a8b5ab7
Safer box_fun_expr
Julow Jul 22, 2024
b09e7ca
fix beginend
EmileTrotignon Jul 25, 2024
5598472
fix indent of funs that are not args
EmileTrotignon Jul 25, 2024
69ed0c1
to fixup with previous
EmileTrotignon Jul 25, 2024
019ac60
cleanup useless clause
EmileTrotignon Jul 25, 2024
8305757
finish cleanup
EmileTrotignon Jul 25, 2024
2a2cf32
Remove test.ml
Julow Jul 25, 2024
4600df0
fix janestreet indent
EmileTrotignon Jul 25, 2024
e0c2e1b
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon Jul 25, 2024
eb30a4e
fix closing paren on sperate line indentation
EmileTrotignon Jul 25, 2024
c3af449
Tweak 'function' indentation
Julow Jul 25, 2024
e7aa06b
Tweak 'fun -> function' indentation
Julow Jul 25, 2024
a78c9cd
Remove unused Params.Indent.docked_fun
Julow Jul 25, 2024
258e79b
Tweak labelled 'fun' indentation
Julow Jul 25, 2024
93e101d
Don't unbox functions passed as args
Julow Jul 25, 2024
e57f7f5
ocp-indent: Restore indentation of docked 'fun' args
Julow Jul 25, 2024
91978f8
fix hovbox in `else function ...` block
EmileTrotignon Jul 26, 2024
e3b0dc1
Merge branch 'MAIN' into backport-52-extended
Julow Jul 29, 2024
637bda9
add stacktraces to the html debug output
EmileTrotignon Jul 29, 2024
caee894
fix wrongful squash and answer review
EmileTrotignon Jul 29, 2024
07927f8
Fmt.str also produces stack information
EmileTrotignon Jul 29, 2024
49246e0
fix args in fun box
EmileTrotignon Jul 30, 2024
21b59ff
Fix regression with break_colon=before and ocp-indent-compat
Julow Jul 30, 2024
03484d4
fixes yesterday's regression
EmileTrotignon Jul 31, 2024
a1699f9
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon Jul 31, 2024
a5aae14
Fix indentation of 'f (fun -> )' after a comment
Julow Jul 31, 2024
8e94981
fix last regression before formatting the pr
EmileTrotignon Aug 1, 2024
040d9b2
add stack traces to break_unless_newline and others
EmileTrotignon Aug 1, 2024
5a6e4bd
format format !
EmileTrotignon Aug 1, 2024
f9ae5ae
fix comment in if-then-else
EmileTrotignon Aug 1, 2024
1b7355f
fix infix bind
EmileTrotignon Aug 1, 2024
4b16ccb
format format 2
EmileTrotignon Aug 1, 2024
6d3ce5f
issue289 fix
EmileTrotignon Aug 1, 2024
3464d63
Fix indentation of 'let _ = fun _ -> fun _ ->'
Julow Aug 2, 2024
1e582f8
fmt
Julow Aug 2, 2024
17d1796
fix issue with single case function
EmileTrotignon Sep 3, 2024
d4564e4
todo for this branch
EmileTrotignon Sep 3, 2024
6b01076
Fix (function) indent with janestreet profile
Julow Sep 3, 2024
6b294ad
janestreet: Tweak indent of docked (fun . -> .)
Julow Sep 3, 2024
0472038
fix let-binding-deindent-fun and aslo format according to previous co…
EmileTrotignon Sep 4, 2024
2eed680
fix extra indent given to fun in parens
EmileTrotignon Sep 4, 2024
7dc4789
Merge branch 'MAIN' into backport-52-extended
Julow Sep 4, 2024
ed0303a
Merge branch 'MAIN' into backport-52-extended
Julow Sep 4, 2024
dbc48ea
ocp: Tweak indent of labelled fun
Julow Sep 5, 2024
6930d76
ocp: Tweak indentation of labelled fun body
Julow Sep 5, 2024
980be25
chases regressions for js profile
EmileTrotignon Sep 5, 2024
9239373
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon Sep 5, 2024
22d258e
Restore indentation of 'let _ = fun _ -> function'
Julow Sep 5, 2024
e9dc8a7
update js todo
EmileTrotignon Sep 5, 2024
0db3cb9
Update TODO.md for the ocamlformat profile
Julow Sep 5, 2024
914bda1
Merge branch 'MAIN' into backport-52-extended
Julow Sep 5, 2024
ee55c7c
Update source-conventional.ml.ref
Julow Sep 5, 2024
9fe2727
fix break before arrow js
EmileTrotignon Sep 6, 2024
0ecb061
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon Sep 6, 2024
e9cf89a
fmt
EmileTrotignon Sep 6, 2024
fbcf842
ocp: Tweak breaking of 'let _ = function'
Julow Sep 10, 2024
29663ca
Safety rule for 'fun _ -> (function ...)'
Julow Sep 10, 2024
ef6cad5
The 'match -> (fun -> (match' diff is not a problem
Julow Sep 10, 2024
3fcfc06
ocp: Tweak break after 'fun ->' depending on context
Julow Sep 11, 2024
68a1a0c
Update TODO.md
Julow Sep 12, 2024
17aa326
fix js labelled arg fun formating
EmileTrotignon Sep 12, 2024
e02ca8d
Merge branch 'backport-52-extended' of github.com:julow/ocamlformat i…
EmileTrotignon Sep 12, 2024
9d324fa
fix js `fun a : t`
EmileTrotignon Sep 13, 2024
c5b522e
Merge branch 'MAIN' into backport-52-extended
Julow Sep 20, 2024
2cf5308
test: Remove --max-iter in issue289.ml
Julow Sep 20, 2024
d05ebe0
CI: Disable ocp-indent comparaison for janestreet
Julow Sep 23, 2024
fc1d8db
Update TODO.ml
Julow Sep 24, 2024
4833e14
test: Add labelled_args example
Julow Sep 24, 2024
a397f14
Fix indentation of labelled fun args
Julow Sep 24, 2024
3bde601
Remove unecessary arguments in Params
Julow Sep 30, 2024
c0d36ac
Update TODO.ml
Julow Sep 30, 2024
dc871a8
Fix break after label and comment
Julow Sep 30, 2024
b8b1419
js: Fix labelled fun args indent
Julow Sep 30, 2024
5b20205
Simplify Params.Indent.function_
Julow Sep 30, 2024
a1650d0
Fix indentation of labelled 'function'
Julow Sep 30, 2024
4b196f1
Remove a diff that is not a bug
Julow Sep 30, 2024
694514a
Fix breaking of function cases after infix
Julow Oct 3, 2024
7c93e9a
Clarify TODO.md
Julow Oct 3, 2024
d98957c
Re-implement inconsistent formatting of fun arguments
Julow Oct 8, 2024
59c2b01
Restore method indentation
Julow Oct 8, 2024
878ee1b
Merge branch 'MAIN' into backport-52-extended
Julow Oct 8, 2024
109cd14
Merge branch 'MAIN' into backport-52-extended
Julow Oct 8, 2024
6ece6c4
Update TODO.ml
Julow Oct 8, 2024
20efdce
TODO.ml: This is a fix.
Julow Oct 10, 2024
0f1d888
TODO.ml: Not a bug
Julow Oct 10, 2024
ef86c82
Fix indentation of `fun` on the left of an infix
Julow Oct 10, 2024
0710547
Fix indent of 'fun -> function' arguments
Julow Oct 10, 2024
9d53137
Fix indent of 'fun -> function' exprs
Julow Oct 10, 2024
0a3198b
js: Fix indent of 'function' after infix
Julow Oct 10, 2024
79330fe
Fix disambiguating parentheses and indentation of `function` after infix
Julow Oct 11, 2024
1a30c46
Adjust indentation of 'let in fun'
Julow Oct 14, 2024
d421d8d
Update TODO.ml
Julow Oct 14, 2024
b80f229
fmt
Julow Oct 14, 2024
620702d
Update CHANGES
Julow Oct 14, 2024
20cb0e6
Remove TODO.ml
Julow Oct 14, 2024
92c213b
Merge branch 'MAIN' into backport-52-extended
Julow Oct 14, 2024
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
9 changes: 5 additions & 4 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ jobs:
- conventional
- ocamlformat
- janestreet
include:
- ocp_indent: true
ocp_indent_config: JaneStreet
profile: janestreet
# To enable comparing with ocp-indent:
# include:
# - ocp_indent: true
# ocp_indent_config: JaneStreet
# profile: janestreet

steps:
- name: Install ocp-indent
Expand Down
7 changes: 4 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ profile. This started with version 0.26.0.

### Added

- Support OCaml 5.2 syntax (#2519, @Julow)
This includes:
+ Local open in types.
- \* Support OCaml 5.2 syntax (#2519, #2544, @Julow, @EmileTrotignon)
This includes local open in types and changed syntax for functions.
This might change the formatting of some functions due to the formatting code
being completely rewritten.
- Allow a custom command to be used to run ocamlformat in the emacs plugin (#2577, @gridbugs)

### Changed
Expand Down
6 changes: 3 additions & 3 deletions lib-rpc/protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module Make (IO : IO.S) = struct
let to_sexp =
let open Csexp in
function
| `Version v -> List [Atom "Version"; Atom v] | _ -> assert false
| `Version v -> List [Atom "Version"; Atom v]
| _ -> assert false

let output oc t = IO.write oc [to_sexp t]
end
Expand Down Expand Up @@ -109,8 +110,7 @@ module Make (IO : IO.S) = struct
let csexp_to_config csexpl =
List.filter_map
(function
| List [Atom name; Atom value] -> Some (name, value) | _ -> None
)
| List [Atom name; Atom value] -> Some (name, value) | _ -> None )
csexpl
in
read ic
Expand Down
95 changes: 59 additions & 36 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ module Exp = struct

let has_trailing_attributes {pexp_desc; pexp_attributes; _} =
match pexp_desc with
| Pexp_fun _ | Pexp_function _ | Pexp_ifthenelse _ | Pexp_match _
|Pexp_try _ ->
| Pexp_function _ | Pexp_ifthenelse _ | Pexp_match _ | Pexp_try _ ->
false
| _ -> List.exists pexp_attributes ~f:(Fn.non Attr.is_doc)

Expand Down Expand Up @@ -180,12 +179,14 @@ module Exp = struct
|( {pexp_desc= Pexp_sequence _; _}
, (Non_apply | Sequence | Then | ThenElse) )
|( { pexp_desc=
( Pexp_function _ | Pexp_match _ | Pexp_try _
| Pexp_fun (_, {pexp_desc= Pexp_constraint _; _}) )
( Pexp_function (_, Some _, _)
| Pexp_function (_, _, Pfunction_cases _)
| Pexp_match _ | Pexp_try _ )
; _ }
, (Match | Let_match | Non_apply) )
|( { pexp_desc=
( Pexp_fun _ | Pexp_let _ | Pexp_letop _ | Pexp_letexception _
( Pexp_function (_, _, Pfunction_body _)
| Pexp_let _ | Pexp_letop _ | Pexp_letexception _
| Pexp_letmodule _ | Pexp_open _ | Pexp_letopen _ )
; _ }
, (Let_match | Non_apply) ) ->
Expand Down Expand Up @@ -1016,6 +1017,7 @@ end = struct
List.exists en1 ~f:(fun (_, c, _) ->
Option.exists c ~f:check_type_constraint ) )
| Pexp_let (lbs, _, _) -> assert (check_let_bindings lbs)
| Pexp_function (_, Some t1, _) -> assert (check_type_constraint t1)
| _ -> assert false )
| Fpe _ | Fpc _ -> assert false
| Vc c -> assert (check_value_constraint c)
Expand Down Expand Up @@ -1206,15 +1208,16 @@ end = struct
let check_param_val (_, _, p) = p == pat in
let check_expr_function_param param =
match param.pparam_desc with
| Param_val x -> check_param_val x
| Param_newtype _ -> false
| Pparam_val x -> check_param_val x
| Pparam_newtype _ -> false
in
let check_class_function_param param =
check_param_val param.pparam_desc
in
let check_class_function_params =
List.exists ~f:check_class_function_param
in
let check_cases = List.exists ~f:(fun c -> c.pc_lhs == pat) in
match ctx with
| Pld (PPat (p1, _)) -> assert (p1 == pat)
| Pld _ -> assert false
Expand Down Expand Up @@ -1266,13 +1269,17 @@ end = struct
| Pexp_letop {let_; ands; _} ->
let f {pbop_pat; _} = check_subpat pbop_pat in
assert (f let_ || List.exists ~f ands)
| Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases) ->
assert (
List.exists cases ~f:(function
| {pc_lhs; _} when pc_lhs == pat -> true
| _ -> false ) )
| Pexp_match (_, cases) | Pexp_try (_, cases) ->
assert (check_cases cases)
| Pexp_for (p, _, _, _, _) -> assert (p == pat)
| Pexp_fun (p, _) -> assert (check_expr_function_param p) )
| Pexp_function (params, _, body) ->
let check_body =
match body with
| Pfunction_body _ -> false
| Pfunction_cases (cases, _, _) -> check_cases cases
in
assert (
List.exists ~f:check_expr_function_param params || check_body ) )
| Fpe ctx -> assert (check_expr_function_param ctx)
| Fpc ctx -> assert (check_class_function_param ctx)
| Vc _ -> assert false
Expand Down Expand Up @@ -1329,15 +1336,21 @@ end = struct
let check_param_val (_, e, _) = Option.exists e ~f:(fun x -> x == exp) in
let check_expr_function_param param =
match param.pparam_desc with
| Param_val x -> check_param_val x
| Param_newtype _ -> false
| Pparam_val x -> check_param_val x
| Pparam_newtype _ -> false
in
let check_class_function_param param =
check_param_val param.pparam_desc
in
let check_class_function_params =
List.exists ~f:check_class_function_param
in
let check_cases =
List.exists ~f:(function
| {pc_guard= Some g; _} when g == exp -> true
| {pc_rhs; _} when pc_rhs == exp -> true
| _ -> false )
in
match ctx with
| Pld (PPat (_, Some e1)) -> assert (e1 == exp)
| Pld _ -> assert false
Expand All @@ -1359,15 +1372,16 @@ end = struct
let f {pbop_exp; _} = pbop_exp == exp in
assert (f let_ || List.exists ~f ands || body == exp)
| (Pexp_match (e, _) | Pexp_try (e, _)) when e == exp -> ()
| Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
->
| Pexp_match (_, cases) | Pexp_try (_, cases) ->
assert (check_cases cases)
| Pexp_function (params, _, body) ->
let check_body =
match body with
| Pfunction_body body -> body == exp
| Pfunction_cases (cases, _, _) -> check_cases cases
in
assert (
List.exists cases ~f:(function
| {pc_guard= Some g; _} when g == exp -> true
| {pc_rhs; _} when pc_rhs == exp -> true
| _ -> false ) )
| Pexp_fun (param, body) ->
assert (check_expr_function_param param || body == exp)
List.exists ~f:check_expr_function_param params || check_body )
| Pexp_indexop_access {pia_lhs; pia_kind= Builtin idx; pia_rhs; _} ->
assert (
pia_lhs == exp || idx == exp
Expand Down Expand Up @@ -1867,7 +1881,7 @@ end = struct
| Ppat_cons _ -> true
| Ppat_construct _ | Ppat_record _ | Ppat_variant _ -> false
| _ -> true )
| Fpe {pparam_desc= Param_val (_, _, _); _}, Ppat_cons _ -> true
| Fpe {pparam_desc= Pparam_val (_, _, _); _}, Ppat_cons _ -> true
| Fpc {pparam_desc= _; _}, Ppat_cons _ -> true
| Pat {ppat_desc= Ppat_construct _; _}, Ppat_cons _ -> true
| _, Ppat_constraint (_, {ptyp_desc= Ptyp_poly _; _}) -> false
Expand Down Expand Up @@ -1901,7 +1915,7 @@ end = struct
( Ppat_construct _ | Ppat_exception _ | Ppat_or _
| Ppat_lazy _ | Ppat_tuple _ | Ppat_variant _ | Ppat_list _ )
; _ }
| Exp {pexp_desc= Pexp_fun _; _} )
| Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _} )
, Ppat_alias _ )
|( Pat {ppat_desc= Ppat_lazy _; _}
, ( Ppat_construct _ | Ppat_cons _
Expand All @@ -1917,14 +1931,14 @@ end = struct
|Pat {ppat_desc= Ppat_tuple _; _}, Ppat_tuple _
|Pat _, Ppat_lazy _
|Pat _, Ppat_exception _
|Exp {pexp_desc= Pexp_fun _; _}, Ppat_or _
|Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _}, Ppat_or _
|Cl {pcl_desc= Pcl_fun _; _}, Ppat_variant (_, Some _)
|Cl {pcl_desc= Pcl_fun _; _}, Ppat_tuple _
|Cl {pcl_desc= Pcl_fun _; _}, Ppat_construct _
|Cl {pcl_desc= Pcl_fun _; _}, Ppat_alias _
|Cl {pcl_desc= Pcl_fun _; _}, Ppat_lazy _
|(Exp {pexp_desc= Pexp_letop _; _} | Bo _), Ppat_exception _
|( Exp {pexp_desc= Pexp_fun _; _}
|( Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _); _}
, ( Ppat_construct _ | Ppat_cons _ | Ppat_lazy _ | Ppat_tuple _
| Ppat_variant _ ) ) ->
true
Expand Down Expand Up @@ -1976,7 +1990,7 @@ end = struct
match exp.pexp_desc with
| Pexp_assert e
|Pexp_construct (_, Some e)
|Pexp_fun (_, e)
|Pexp_function (_, _, Pfunction_body e)
|Pexp_ifthenelse (_, Some e)
|Pexp_prefix (_, e)
|Pexp_infix (_, _, e)
Expand Down Expand Up @@ -2004,8 +2018,9 @@ end = struct
match cls with Match | Then | ThenElse -> continue e | _ -> false )
| Pexp_match _ when match cls with Then -> true | _ -> false ->
false
| Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
->
| Pexp_function (_, _, Pfunction_cases (cases, _, _))
|Pexp_match (_, cases)
|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)
Expand Down Expand Up @@ -2057,7 +2072,7 @@ end = struct
|Pexp_lazy e
|Pexp_open (_, e)
|Pexp_letopen (_, e)
|Pexp_fun (_, e)
|Pexp_function (_, _, Pfunction_body e)
|Pexp_sequence (_, e)
|Pexp_setfield (_, _, e)
|Pexp_setinstvar (_, e)
Expand All @@ -2073,13 +2088,16 @@ end = struct
| Pexp_extension (ext, PStr [{pstr_desc= Pstr_eval (e, _); _}])
when Source.extension_using_sugar ~name:ext ~payload:e.pexp_loc -> (
match e.pexp_desc with
| Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
->
| Pexp_function (_, _, Pfunction_cases (cases, _, _))
|Pexp_match (_, cases)
|Pexp_try (_, cases) ->
List.iter cases ~f:(fun case ->
mark_parenzed_inner_nested_match case.pc_rhs ) ;
true
| _ -> continue e )
| Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases) ->
| Pexp_function (_, _, Pfunction_cases (cases, _, _))
|Pexp_match (_, cases)
|Pexp_try (_, cases) ->
List.iter cases ~f:(fun case ->
mark_parenzed_inner_nested_match case.pc_rhs ) ;
true
Expand Down Expand Up @@ -2241,6 +2259,10 @@ end = struct
, {pexp_desc= Pexp_construct _ | Pexp_cons _; _} )
when e == exp ->
true
| ( Exp {pexp_desc= Pexp_function (_, _, Pfunction_body e); _}
, {pexp_desc= Pexp_function (_, _, Pfunction_cases _); _} )
when e == exp ->
true
| Exp {pexp_desc; _}, _ -> (
match pexp_desc with
| Pexp_extension
Expand All @@ -2249,13 +2271,14 @@ end = struct
[ { pstr_desc=
Pstr_eval
( { pexp_desc=
( Pexp_function cases
( Pexp_function
(_, _, Pfunction_cases (cases, _, _))
| Pexp_match (_, cases)
| Pexp_try (_, cases) )
; _ }
, _ )
; _ } ] )
|Pexp_function cases
|Pexp_function (_, _, Pfunction_cases (cases, _, _))
|Pexp_match (_, cases)
|Pexp_try (_, cases) ->
if !leading_nested_match_parens then
Expand Down
2 changes: 1 addition & 1 deletion lib/Cmts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ let break_comment_group source a b =
Location.line_difference a b = 0
&& List.is_empty
(Source.tokens_between source a.loc_end b.loc_start
~filter:(function _ -> true) )
~filter:(function _ -> true ))
in
not (vertical_align || horizontal_align)

Expand Down
16 changes: 7 additions & 9 deletions lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ module Formatting = struct
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt ->
update conf ~f:(fun f -> {f with break_collection_expressions= elt})
)
update conf ~f:(fun f -> {f with break_collection_expressions= elt}) )
(fun conf -> conf.fmt_opts.break_collection_expressions)

let break_colon =
Expand Down Expand Up @@ -597,8 +596,7 @@ module Formatting = struct
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt ->
update conf ~f:(fun f ->
{f with break_struct= Elt.make Poly.(elt.v = `Force) elt.from} )
)
{f with break_struct= Elt.make Poly.(elt.v = `Force) elt.from} ) )
(fun conf ->
let elt = conf.fmt_opts.break_struct in
if elt.v then Elt.make `Force elt.from
Expand Down Expand Up @@ -895,8 +893,7 @@ module Formatting = struct
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt ->
update conf ~f:(fun f -> {f with indicate_nested_or_patterns= elt})
)
update conf ~f:(fun f -> {f with indicate_nested_or_patterns= elt}) )
(fun conf -> conf.fmt_opts.indicate_nested_or_patterns)

let infix_precedence =
Expand All @@ -923,8 +920,7 @@ module Formatting = struct
let names = ["leading-nested-match-parens"] in
Decl.flag ~names ~default ~doc ~kind ~allow_inline:false
(fun conf elt ->
update conf ~f:(fun f -> {f with leading_nested_match_parens= elt})
)
update conf ~f:(fun f -> {f with leading_nested_match_parens= elt}) )
(fun conf -> conf.fmt_opts.leading_nested_match_parens)

let let_and =
Expand Down Expand Up @@ -1400,7 +1396,9 @@ module Operational = struct
let debug =
let doc = "Generate debugging output." in
Decl.flag ~default ~names:["g"; "debug"] ~doc ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with debug= elt}))
(fun conf elt ->
if elt.v then Box_debug.enable_stacktraces := true ;
update conf ~f:(fun f -> {f with debug= elt}) )
(fun conf -> conf.opr_opts.debug)

let disable =
Expand Down
21 changes: 1 addition & 20 deletions lib/Extended_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module Parse = struct
{p with ppat_desc= Ppat_unpack (name, Some pt)}
| p -> Ast_mapper.default_mapper.pat m p
in
let rec expr (m : Ast_mapper.mapper) = function
let expr (m : Ast_mapper.mapper) = function
| {pexp_desc= Pexp_cons (_ :: _ :: _ :: _ as l); _} as e
when match List.last_exn l with
(* Empty lists are always represented as Lident [] *)
Expand Down Expand Up @@ -233,25 +233,6 @@ module Parse = struct
(module S) = (module M)] - [let _ = ((module M) : (module
S))] *)
{p with pexp_desc= Pexp_pack (name, Some pt)}
| { pexp_desc=
Pexp_fun
({pparam_desc= Param_newtype types1; pparam_loc= loc1}, e1)
; pexp_attributes= []
; _ } as e ->
let e =
match (expr m e1).pexp_desc with
| Pexp_fun
({pparam_desc= Param_newtype types2; pparam_loc= loc2}, e2)
->
{ e with
pexp_desc=
Pexp_fun
( { pparam_desc= Param_newtype (types1 @ types2)
; pparam_loc= {loc1 with loc_end= loc2.loc_end} }
, e2 ) }
| _ -> e
in
Ast_mapper.default_mapper.expr m e
| e -> Ast_mapper.default_mapper.expr m e
in
Ast_mapper.{default_mapper with expr; pat; binding_op}
Expand Down
Loading
Loading