diff --git a/src/core/material/Walk.re b/src/core/material/Walk.re index a62b7ab2..677f0220 100644 --- a/src/core/material/Walk.re +++ b/src/core/material/Walk.re @@ -80,7 +80,7 @@ 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)); + let is_neq = (w: t) => Swing.is_neq(hd(w)) && 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)); diff --git a/src/core/parser/Melder.re b/src/core/parser/Melder.re index 74723518..97469fdf 100644 --- a/src/core/parser/Melder.re +++ b/src/core/parser/Melder.re @@ -135,7 +135,17 @@ let connect_ineq = let neq = () => connect_neq(~repair, ~onto=d, onto, ~fill, t) |> Option.map(grouted => (grouted, onto)); - Oblig.Delta.minimize(~to_zero=!repair, f => f(), [eq, neq]); + if (repair) { + open Options.Syntax; + // if repairing, then this means we're molding/remolding and our push of the + // current candidate token has reached the top of the local stack ie the nearest + // bidelimited container. prioritize maintaining the current bidelimited + // container if possible. + let/ () = neq(); + eq(); + } else { + Oblig.Delta.minimize(~to_zero=true, f => f(), [eq, neq]); + }; }; let connect = diff --git a/src/core/parser/Molder.re b/src/core/parser/Molder.re index f1fbb0b0..14d54c00 100644 --- a/src/core/parser/Molder.re +++ b/src/core/parser/Molder.re @@ -58,8 +58,12 @@ let mold = Token.is_empty(deferred) ? None : Some( - Melder.push(deferred, ~fill, stack, ~onto=L) - |> Option.map(((grouted, stack)) => (deferred, grouted, stack)) - |> Options.get_fail("bug: failed to push space"), + { + let (fill, slope) = Slope.Dn.unroll(fill); + let stack = Stack.cat(slope, stack); + Melder.push(deferred, ~fill, stack, ~onto=L) + |> Option.map(((grouted, stack)) => (deferred, grouted, stack)) + |> Options.get_fail("bug: failed to push space"); + }, ); }; diff --git a/src/core/parser/Stack.re b/src/core/parser/Stack.re index dc4a7ba2..752a3b4b 100644 --- a/src/core/parser/Stack.re +++ b/src/core/parser/Stack.re @@ -7,6 +7,11 @@ type t = { let empty = {slope: Slope.empty, bound: Bound.Root}; +let cat = (slope: Slope.t, stack: t) => { + ...stack, + slope: Slope.cat(slope, stack.slope), +}; + let merge_hd = (~onto: Dir.t, t: Token.t, stack: t) => switch (stack) { | {slope: [], bound: Root} => None