Skip to content

Commit

Permalink
fix extra grout issue in #84
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Dec 21, 2024
1 parent 9d116fb commit acce6e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ let rec remold = (~fill=Cell.dirty, ctx: Ctx.t): (Cell.t, Ctx.t) => {

let finalize = (~mode=Mode.Navigating, ~fill=Cell.dirty, ctx: Ctx.t): Zipper.t => {
Mode.set(mode);
// P.log("--- finalize");
// P.log("--- Modify.finalize");
let (remolded, ctx) = remold(~fill, ctx);
// P.show("remolded", Cell.show(remolded));
// P.show("ctx", Ctx.show(ctx));
Expand Down Expand Up @@ -245,6 +245,7 @@ let expand = (tok: Token.t) =>
};
let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
// P.log("--- Modify.try_expand");
let* () = Options.of_bool(String.starts_with(~prefix=" ", s));
// todo: check if in middle of token
let (face, rest) = Ctx.pull(~from=L, z.ctx);
Expand All @@ -253,6 +254,9 @@ let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
let* expanded = expand(tok);
let ((l, r), tl) = Ctx.unlink_stacks(rest);
let* (t, grouted, rest) = Result.to_option(Molder.mold(l, expanded));
// P.show("molded", Token.show(t));
// P.show("grouted", Grouted.show(grouted));
// P.show("stack", Stack.show(rest));
if (t.mtrl == Space(Unmolded) || t.mtrl == tok.mtrl) {
None;
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/core/material/Walk.re
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ module T = {

let is_eq = w => List.for_all(Swing.is_eq, Chain.loops(w));
// note: stricter than !is_eq
let is_neq = (w: t) => Swing.is_neq(hd(w)) && Swing.is_neq(ft(w));
// strict=true further requires ft swing to be neq, as a way to avoid
// generating matching ghosts from the start end of the walk (this is
// useful for preserving bidelimited containers)
let is_neq = (~strict=false, w: t) =>
Swing.is_neq(hd(w)) && (!strict || Swing.is_neq(ft(w)));
let is_valid = w => is_eq(w) || is_neq(w);

// let has_sort = w => List.exists(Swing.has_sort, strides(w));
Expand Down
4 changes: 2 additions & 2 deletions src/core/material/Walker.re
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ let walk = (~from: Dir.t, src: End.t, dst: End.t) =>
Index.find(dst, walk_all(~from, src));
let walk_eq = (~from: Dir.t, src: End.t, dst: End.t) =>
List.filter(Walk.is_eq, walk(~from, src, dst));
let walk_neq = (~from: Dir.t, src: End.t, dst: End.t) =>
List.filter(Walk.is_neq, walk(~from, src, dst));
let walk_neq = (~strict=true, ~from: Dir.t, src: End.t, dst: End.t) =>
List.filter(Walk.is_neq(~strict), walk(~from, src, dst));

let enter = (~from: Dir.t, sort: Mtrl.NT.t, dst: End.t) =>
Index.find(dst, enter_all(~from, sort));
Expand Down
7 changes: 5 additions & 2 deletions src/core/parser/Melder.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ let connect_eq =
};
let connect_neq =
(
~strict=false,
~repair=false,
~onto as d: Dir.t,
onto: Bound.t(Terr.t),
Expand All @@ -112,7 +113,7 @@ let connect_neq =
)
: option(Grouted.t) => {
let face = onto |> Bound.map(t => Terr.face(t).mtrl);
Walker.walk_neq(~from=d, face, Node(t.mtrl))
Walker.walk_neq(~strict, ~from=d, face, Node(t.mtrl))
|> Grouter.pick(~repair, ~from=d, [fill]);
};
let connect_lt = connect_neq(~onto=L);
Expand All @@ -132,7 +133,9 @@ let connect_ineq =
|> Options.bind(~f=onto => connect_eq(~repair, ~onto=d, onto, ~fill, t))
|> Option.map(((grouted, terr)) => (grouted, Bound.Node(terr)));
let neq = () =>
connect_neq(~repair, ~onto=d, onto, ~fill, t)
// require strict neq when we reach the stack bound to avoid breaking
// bidelimited containers
connect_neq(~strict=true, ~repair, ~onto=d, onto, ~fill, t)
|> Option.map(grouted => (grouted, onto));
if (repair) {
open Options.Syntax;
Expand Down
8 changes: 8 additions & 0 deletions src/core/parser/Molder.re
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,21 @@ and remold =
(c, up);
})
|> Option.value(~default=Slope.Up.unroll(hd.cell));
// P.log("--- Molder.remold/continue/molding");
// P.show("l", Stack.show(l));
// P.show("fill", Cell.show(fill));
// P.show("hd_w", Token.show(hd_w));
switch (mold(l, ~fill, Token.unmold(hd_w))) {
| Error(fill) =>
let (c, up) = unroll_tl_w_hd_cell();
let fill = fill |> Cell.pad(~r=c) |> Cell.mark_ends_dirty;
(l, r_tl) |> Stack.Frame.cat(([], up)) |> remold(~fill);
| Ok((t, grouted, rest)) when t.mtrl == hd_w.mtrl =>
// fast path for when hd_w retains original meld
// P.log("--- Molder.remold/continue/fast path");
// P.show("t", Token.show(t));
// P.show("grouted", Grouted.show(grouted));
// P.show("rest", Stack.show(rest));
let connected = Stack.connect(t, grouted, rest) |> Stack.extend(tl_w);
if (connected.bound == l.bound) {
remold(~fill=hd.cell, (connected, r_tl));
Expand Down

0 comments on commit acce6e2

Please sign in to comment.