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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ profile. This started with version 0.26.0.
end
```

- \* Allow `begin end` on one line in most cases. (#2745, @EmileTrotignon).
`f begin fun x -> y end` is not supported for now and is still always
multiline.

## 0.28.1

### Highlight
Expand Down
7 changes: 3 additions & 4 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3051,10 +3051,9 @@ and fmt_lazy c ~ctx ?(pro = noop) ~fmt_atrs ~infix_ext_attrs ~parens e =
and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs
~infix_ext_attrs ~indent_wrap ?eol e =
let cmts_before = Cmts.fmt_before c ?eol loc in
let begin_ = fmt_infix_ext_attrs c ~pro:(str "begin") infix_ext_attrs
and end_ =
(if not box then break 1000 (-2) else break 1000 0)
$ str "end" $ fmt_atrs
let begin_ = fmt_infix_ext_attrs c ~pro:(str "begin") infix_ext_attrs in
let end_ =
(if not box then break 1000 (-2) else break 1 0) $ str "end" $ fmt_atrs
in
let box_beginend_sb = Params.Exp.box_beginend_subexpr c.conf ~ctx ~ctx0 in
let beginend_box =
Expand Down
6 changes: 1 addition & 5 deletions test/passing/refs.ahrefs/attributes.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,7 @@ let _ =

let _ = ((module[@a] X) [@b])

let _ =
begin[@a]
x
end
[@b]
let _ = begin[@a] x end [@b]

let fold input ~init ~f =
foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail]
Expand Down
21 changes: 4 additions & 17 deletions test/passing/refs.ahrefs/exp_grouping-parens.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,10 @@ let _ = begin%ext end
let _ = begin%ext end (* foo *)
let _ = x y
let _ = (* foo *) x y
let _ =
begin%ext
x y
end
let _ =
begin%ext
(* foo *) x y
end
let _ = begin%ext x y end
let _ = begin%ext (* foo *) x y end

let _ =
begin[@landmark "parse_constant_dividends"]
market_data_items := ()
end
let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end

let () = if a then b (* asd *)

Expand Down Expand Up @@ -531,11 +522,7 @@ let main =
| A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| B -> bbbbbbbbbbbbbbbbbbbbbb

let _ =
begin
a
end
[@a]
let _ = begin a end [@a]

let () =
fooooo
Expand Down
31 changes: 6 additions & 25 deletions test/passing/refs.ahrefs/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -316,27 +316,12 @@ let _ = begin end
let _ = begin end (* foo *)
let _ = begin%ext end
let _ = begin%ext end (* foo *)
let _ =
begin
x y
end
let _ =
begin
(* foo *) x y
end
let _ =
begin%ext
x y
end
let _ =
begin%ext
(* foo *) x y
end
let _ = begin x y end
let _ = begin (* foo *) x y end
let _ = begin%ext x y end
let _ = begin%ext (* foo *) x y end

let _ =
begin[@landmark "parse_constant_dividends"]
market_data_items := ()
end
let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end

let () =
if a then begin
Expand Down Expand Up @@ -611,11 +596,7 @@ let main =
| A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| B -> bbbbbbbbbbbbbbbbbbbbbb

let _ =
begin
a
end
[@a]
let _ = begin a end [@a]

let () =
fooooo
Expand Down
37 changes: 6 additions & 31 deletions test/passing/refs.ahrefs/extensions_exp_grouping.ml.ref
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
let _ =
begin%ext
y >>= z
end
let _ =
[%ext
begin
y >>= z
end]
let _ =
x
>>= begin%ext
y >>= z
end
let _ =
x
>>= [%ext
begin
y >>= z
end]
let _ =
f
begin%ext
y >>= z
end
let _ =
f
[%ext
begin
y >>= z
end]
let _ = begin%ext y >>= z end
let _ = [%ext begin y >>= z end]
let _ = x >>= begin%ext y >>= z end
let _ = x >>= [%ext begin y >>= z end]
let _ = f begin%ext y >>= z end
let _ = f [%ext begin y >>= z end]

let _ = (module%ext S)
let _ = [%ext (module S)]
Expand Down
12 changes: 3 additions & 9 deletions test/passing/refs.ahrefs/reformat_string.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ let _ = (* test *) "asd"

let _ = "asd"

let _ =
begin
(* te""st *) "asd"
end

let _ =
begin
"asd"
end
let _ = begin (* te""st *) "asd" end

let _ = begin "asd" end

let _ = 'a'

Expand Down
8 changes: 4 additions & 4 deletions test/passing/refs.ahrefs/source.ml.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Warning: source.ml:3417 exceeds the margin
Warning: source.ml:6551 exceeds the margin
Warning: source.ml:6985 exceeds the margin
Warning: source.ml:7817 exceeds the margin
Warning: source.ml:3415 exceeds the margin
Warning: source.ml:6549 exceeds the margin
Warning: source.ml:6983 exceeds the margin
Warning: source.ml:7815 exceeds the margin
4 changes: 1 addition & 3 deletions test/passing/refs.ahrefs/source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ let () =
assert%foo[@foo] true;
lazy%foo[@foo] x;
object%foo[@foo] end;
begin%foo[@foo]
3
end;
begin%foo[@foo] 3 end;
new%foo[@foo] x;

match%foo[@foo] () with
Expand Down
7 changes: 1 addition & 6 deletions test/passing/refs.default/attributes.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,7 @@ let _ =
[@b]

let _ = ((module[@a] X) [@b])

let _ =
begin[@a]
x
end
[@b]
let _ = begin[@a] x end [@b]

let fold input ~init ~f =
foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail]
Expand Down
8 changes: 2 additions & 6 deletions test/passing/refs.default/cases_exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ let a =
| B -> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
end

let a =
begin match f x i with A -> a | B -> b
end
let a = begin match f x i with A -> a | B -> b end

let a =
begin[@a] match[@b]
Expand Down Expand Up @@ -177,9 +175,7 @@ let a =
| B -> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
end

let a =
begin try f x i with A -> a | B -> b
end
let a = begin try f x i with A -> a | B -> b end

let a =
begin[@a] try[@b]
Expand Down
25 changes: 4 additions & 21 deletions test/passing/refs.default/exp_grouping-parens.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,9 @@ let _ = begin%ext end
let _ = begin%ext end (* foo *)
let _ = x y
let _ = (* foo *) x y

let _ =
begin%ext
x y
end

let _ =
begin%ext
(* foo *) x y
end

let _ =
begin[@landmark "parse_constant_dividends"]
market_data_items := ()
end

let _ = begin%ext x y end
let _ = begin%ext (* foo *) x y end
let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end
let () = if a then b (* asd *)

let x =
Expand Down Expand Up @@ -548,11 +535,7 @@ let main =
| A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| B -> bbbbbbbbbbbbbbbbbbbbbb

let _ =
begin
a
end
[@a]
let _ = begin a end [@a]

let () =
fooooo
Expand Down
36 changes: 6 additions & 30 deletions test/passing/refs.default/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -332,31 +332,11 @@ let _ = begin end
let _ = begin end (* foo *)
let _ = begin%ext end
let _ = begin%ext end (* foo *)

let _ =
begin
x y
end

let _ =
begin
(* foo *) x y
end

let _ =
begin%ext
x y
end

let _ =
begin%ext
(* foo *) x y
end

let _ =
begin[@landmark "parse_constant_dividends"]
market_data_items := ()
end
let _ = begin x y end
let _ = begin (* foo *) x y end
let _ = begin%ext x y end
let _ = begin%ext (* foo *) x y end
let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end

let () =
if a then begin
Expand Down Expand Up @@ -629,11 +609,7 @@ let main =
| A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| B -> bbbbbbbbbbbbbbbbbbbbbb

let _ =
begin
a
end
[@a]
let _ = begin a end [@a]

let () =
fooooo
Expand Down
43 changes: 6 additions & 37 deletions test/passing/refs.default/extensions_exp_grouping.ml.ref
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
let _ =
begin%ext
y >>= z
end

let _ =
[%ext
begin
y >>= z
end]

let _ =
x
>>= begin%ext
y >>= z
end

let _ =
x
>>= [%ext
begin
y >>= z
end]

let _ =
f
begin%ext
y >>= z
end

let _ =
f
[%ext
begin
y >>= z
end]

let _ = begin%ext y >>= z end
let _ = [%ext begin y >>= z end]
let _ = x >>= begin%ext y >>= z end
let _ = x >>= [%ext begin y >>= z end]
let _ = f begin%ext y >>= z end
let _ = f [%ext begin y >>= z end]
let _ = (module%ext S)
let _ = [%ext (module S)]
let _ = f (module%ext S)
Expand Down
4 changes: 1 addition & 3 deletions test/passing/refs.default/js_begin.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ let g = function
foo;
bar

let () =
begin match foo with Bar -> snoo
end
let () = begin match foo with Bar -> snoo end
5 changes: 1 addition & 4 deletions test/passing/refs.default/js_pattern.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ let f = function _ -> 0
let f x = match x with _ -> 0
let f = function _ -> 0
let f x = match x with _ -> 0

let f x =
begin match x with _ -> 0
end
let f x = begin match x with _ -> 0 end

let check_price t = function
| { Exec.trade_at_settlement = None | Some false } -> ()
Expand Down
Loading
Loading