Skip to content

Commit

Permalink
being extra careful about fill propagation but not sure if strictly n…
Browse files Browse the repository at this point in the history
…ecessary
  • Loading branch information
dm0n3y committed Nov 8, 2024
1 parent bc0161a commit 8d66284
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ let relabel =
// None means token was removed. Some(ctx) means token was molded (or deferred and
// tagged as an unmolded space), ctx includes the molded token.
let mold =
(ctx: Ctx.t, ~fill=Cell.dirty, tok: Token.Unmolded.t): option(Ctx.t) => {
open Options.Syntax;
(ctx: Ctx.t, ~fill=Cell.dirty, tok: Token.Unmolded.t)
: Result.t(Ctx.t, Cell.t) => {
open Result.Syntax;
let ((l, r), rest) = Ctx.unlink_stacks(ctx);
// Grouter.dbg := true;
let+ (tok, grouted, l) = Molder.mold(l, ~fill, tok);
Expand Down Expand Up @@ -240,7 +241,7 @@ let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
// if expandable, consider all expandable const labels
let* expanded = expand(tok);
let ((l, r), tl) = Ctx.unlink_stacks(rest);
let* (t, grouted, rest) = Molder.mold(l, expanded);
let* (t, grouted, rest) = Result.to_option(Molder.mold(l, expanded));
if (t.mtrl == Space(Unmolded) || t.mtrl == tok.mtrl) {
None;
} else {
Expand Down Expand Up @@ -336,7 +337,7 @@ let insert_toks =
// P.show("fill", Cell.show(fill));
// P.show("tok", Token.Unmolded.show(tok));
switch (mold(ctx, ~fill, tok)) {
| Some(ctx) =>
| Ok(ctx) =>
// P.show("molded tok", Ctx.show(ctx));
let (face, rest) = Ctx.pull(~from=L, ctx);
switch (face, next_fill.marks.cursor) {
Expand All @@ -355,11 +356,10 @@ let insert_toks =
(ctx, next_fill);
| _ => (ctx, next_fill)
};
| None =>
| Error(fill) =>
// removed empty token
let next_fill =
Option.is_some(fill.marks.cursor)
? Cell.mark_ends_dirty(fill) : next_fill;
Cell.mark_ends_dirty(Cell.Space.merge(fill, next_fill));
(ctx, next_fill);
}
},
Expand Down
14 changes: 7 additions & 7 deletions src/core/parser/Molder.re
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let complete_pending_ghosts = (~bounds, l: Stack.t, ~fill) => {
// returns None if input token is empty
let rec mold =
(stack: Stack.t, ~fill=Cell.empty, t: Token.Unmolded.t)
: option((Token.t, Grouted.t, Stack.t)) =>
: Result.t((Token.t, Grouted.t, Stack.t), Cell.t) =>
switch (
candidates(t)
|> Oblig.Delta.minimize(tok =>
Expand All @@ -88,12 +88,12 @@ let rec mold =
// P.show("grouted", Grouted.show(grouted));
// P.show("stack", Stack.show(stack));
Mtrl.is_tile(tok.mtrl) && tok.text == "" && Grouted.is_neq(grouted)
? None : Some(molded)
? Error(Cell.mark_degrouted(fill, ~side=R)) : Ok(molded)
| None =>
let deferred = Token.Unmolded.defer(t);
Token.is_empty(deferred)
? None
: Some(
? Error(Cell.mark_degrouted(fill, ~side=R))
: Ok(
{
let (fill, slope) = Slope.Dn.unroll(fill);
let stack = Stack.cat(slope, stack);
Expand Down Expand Up @@ -137,19 +137,19 @@ and remold =
})
|> Option.value(~default=Slope.Up.unroll(hd.cell));
switch (mold(l, ~fill, Token.unmold(hd_w))) {
| None =>
| 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);
| Some((t, grouted, rest)) when t.mtrl == hd_w.mtrl =>
| Ok((t, grouted, rest)) when t.mtrl == hd_w.mtrl =>
// fast path for when hd_w retains original meld
let connected = Stack.connect(t, grouted, rest) |> Stack.extend(tl_w);
if (connected.bound == l.bound) {
remold(~fill=hd.cell, (connected, r_tl));
} else {
Error((hd.cell, (connected, r_tl)));
};
| Some((t, grouted, rest)) =>
| Ok((t, grouted, rest)) =>
let connected = Stack.connect(t, grouted, rest);
// check if connection changed the stack bound
if (connected.bound == l.bound) {
Expand Down

0 comments on commit 8d66284

Please sign in to comment.