Skip to content

Commit

Permalink
v0.18~preview.130.00+55
Browse files Browse the repository at this point in the history
  • Loading branch information
public-release committed Oct 8, 2024
1 parent 991e1e6 commit 61329d3
Show file tree
Hide file tree
Showing 15 changed files with 1,599 additions and 1,149 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- Rename `Bonsai.Cont.yoink` to `Bonsai.Cont.peek` to mirror the peek operation in
other abstract data types



- Made the `close_when_clicked_outside` argument to `Bonsai_web_ui_popover` dynamic.

- Changed Bonsai path generation so that paths are only extended at branch points where
Expand Down
1 change: 1 addition & 0 deletions bonsai.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ depends: [
"ppx_jane"
"ppx_let"
"ppx_pattern_bind"
"ppxlib_jane"
"uopt"
"virtual_dom"
"dune" {>= "3.11.0"}
Expand Down
7 changes: 6 additions & 1 deletion ppx_bonsai/src/expander/balance_list_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let balance ~n nodes =
in
match chunks with
| [ [ single ] ] -> single
| [ single_nodes ] -> Node single_nodes
| [ single_chunk ] -> Node single_chunk
| _ when Nonempty_list.length chunks > n -> Nonempty_list.map chunks ~f:loop |> loop
| _ -> Node (Nonempty_list.map chunks ~f:loop)
in
match loop nodes with
Expand All @@ -30,6 +31,10 @@ let balance ~n list =
match Nonempty_list.of_list list with
| None -> Or_error.error_string "expand_letn: list of bindings must be non-empty"
| Some _ when n <= 0 -> Or_error.error_string "expand_letn: n must be positive"
| Some [ singleton ] when n = 1 -> Ok (Nonempty_list.singleton (Leaf singleton))
| Some _ when n = 1 ->
Or_error.error_string
"expand_letn: n may only be 1 if the length of the input list is exactly 1"
| Some list ->
let nodes = Nonempty_list.map list ~f:(fun x -> Leaf x) in
Ok (balance ~n nodes)
Expand Down
5 changes: 4 additions & 1 deletion ppx_bonsai/src/expander/balance_list_tree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ type 'a t = private
(** Balances the given list. Each sublist's length within the tree has the property of
being <= n.
The function returns an error if the length of the list is < 1 or if n <= 0. *)
The function returns an error if:
- the length of the list is < 1, or
- n <= 0, or
- n = 1, and the length of the list is not exactly 1 *)
val balance : n:int -> 'a list -> 'a t Nonempty_list.t Or_error.t
4 changes: 2 additions & 2 deletions ppx_bonsai/src/expander/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name ppx_bonsai_expander)
(public_name bonsai.ppx_bonsai_expander)
(libraries core core_kernel.nonempty_list ppxlib ppx_let.expander
ppx_pattern_bind ppx_here.expander)
(libraries core core_kernel.nonempty_list ppxlib ppxlib_jane
ppx_let.expander ppx_pattern_bind ppx_here.expander)
(preprocess
(pps ppxlib.metaquot ppx_jane)))
36 changes: 14 additions & 22 deletions ppx_bonsai/src/expander/ppx_bonsai_expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,20 @@ let arr (location_behavior : Location_behavior.t) : (module Ext) =
match acc with
| true -> true
| false ->
(match Ppxlib_jane.Shim.Pattern_desc.of_parsetree pattern.ppat_desc with
(* let (_ as a) = x in ... *)
| Ppat_alias (_, _) -> false
| Ppat_any
(* let { a ; b ; _ } = x in ... *)
| Ppat_record (_, Open)
(* let { a = (module _) ; b } = x in ... *)
| Ppat_unpack { txt = None; _ } -> true
| Ppat_record (_, Closed)
| Ppat_unpack { txt = Some _; _ }
| Ppat_constant _
| Ppat_interval (_, _)
| Ppat_var _ | Ppat_tuple _
| Ppat_unboxed_tuple (_, _)
| Ppat_construct (_, _)
| Ppat_array _
| Ppat_or (_, _)
| Ppat_constraint (_, _, _)
| Ppat_type _ | Ppat_lazy _ | Ppat_extension _
| Ppat_open (_, _)
| Ppat_exception _
| Ppat_variant (_, _) -> super#pattern pattern acc)
(match Ppxlib_jane.Jane_syntax.Pattern.of_ast pattern with
| Some (Jpat_tuple (_tuple, Open), _attrs) -> true
| _ ->
(match Ppxlib_jane.Shim.Pattern_desc.of_parsetree pattern.ppat_desc with
(* let (_ as a) = x in ... *)
| Ppat_alias (_, _) -> false
| Ppat_any
(* let { a ; b ; _ } = x in ... *)
| Ppat_record (_, Open)
(* let { a = (module _) ; b } = x in ... *)
| Ppat_unpack { txt = None; _ } -> true
| Ppat_record (_, Closed) | Ppat_unpack { txt = Some _; _ } ->
super#pattern pattern acc
| _ -> super#pattern pattern acc))
end
in
ignore_finder#pattern pattern false
Expand Down
Loading

0 comments on commit 61329d3

Please sign in to comment.