@@ -8,7 +8,21 @@ let rec split_cell_padding = (~side: Dir.t, c: Cell.t) =>
88 switch (Cell . get(c)) {
99 | None => Cell . (empty, c)
1010 | Some (m ) when Option . is_some(Meld . Space . get(m)) =>
11- Cell . Space . split(~side, c) |> Option . value(~default= (c, Cell . empty))
11+ switch (Cell . Space . split(~side, c)) {
12+ | Some (s ) => s
13+ | None =>
14+ // P.show("Cell.space.split results in none with c:", Cell.show(c));
15+ switch (side) {
16+ | L =>
17+ // P.show("split_cell_padding edge left c", Cell.show(c));
18+ (c, Cell . empty) /* |> Option.value(~default=) */
19+ | R =>
20+ let (c , rest ) = Cell . split_edge(~side= L , c);
21+ // P.show("split_cell_padding split_edge right c", Cell.show(c));
22+ // P.show("rest", Cell.show(rest));
23+ (rest, c);
24+ }
25+ }
1226 | Some (M (l , w , r )) =>
1327 switch (side) {
1428 | L =>
@@ -61,21 +75,48 @@ module Cells = {
6175 // where c holds the meld {} " " {|} " " {}, the caret | will be pulled
6276 // left side of any grout inserted between the spaces, which is afaict always
6377 // what we want after any modification (except maybe forward delete)
64- let (l , cs ) =
65- switch (cs) {
66- | [ c , ... cs ] =>
67- let (l , c ) = split_cell_padding(~side= L , c);
68- (l, cons(c, cs));
69- | [] => (Cell . empty, cs)
70- };
71- let (cs , r ) =
72- switch (Lists . Framed . ft(cs)) {
73- | Some ((cs , c )) =>
74- let (r , c ) = split_cell_padding(~side= R , c);
75- (List . rev(cons(c, cs)), r);
76- | None => (cs, Cell . empty)
77- };
78- (l, squash(cs), r);
78+ switch (cs) {
79+ | [ c ] when Cell . Space . is_space(c) =>
80+ // P.log("Special split_padding case");
81+ // P.show("r: ", Cell.show(r));
82+ // P.show("c: ", Cell.show(c));
83+
84+ let (cs , r ) =
85+ switch (Lists . Framed . ft(cs)) {
86+ | Some ((cs , c )) =>
87+ let (r , c ) = split_cell_padding(~side= R , c);
88+ (List . rev(cons(c, cs)), r);
89+ | None => (cs, Cell . empty)
90+ };
91+ // P.show("cs: ", show(cs));
92+ // P.show("r: ", Cell.show(r));
93+ let (l , cs ) =
94+ switch (cs) {
95+ | [ c , ... cs ] =>
96+ let (l , c ) = split_cell_padding(~side= L , c);
97+ (l, cons(c, cs));
98+ | [] => (Cell . empty, cs)
99+ };
100+ // P.show("l: ", Cell.show(l));
101+ // P.show("final cs: ", show(cs));
102+ (l, squash(cs), r);
103+ | _ =>
104+ let (l , cs ) =
105+ switch (cs) {
106+ | [ c , ... cs ] =>
107+ let (l , c ) = split_cell_padding(~side= L , c);
108+ (l, cons(c, cs));
109+ | [] => (Cell . empty, cs)
110+ };
111+ let (cs , r ) =
112+ switch (Lists . Framed . ft(cs)) {
113+ | Some ((cs , c )) =>
114+ let (r , c ) = split_cell_padding(~side= R , c);
115+ (List . rev(cons(c, cs)), r);
116+ | None => (cs, Cell . empty)
117+ };
118+ (l, squash(cs), r);
119+ };
79120 };
80121
81122 // output Some(b) if bounded, where b indicates whether pre/post grout needed
@@ -112,12 +153,12 @@ let rec degrout = (c: Cell.t): Cells.t =>
112153 switch (Cell . get(c)) {
113154 // open the cell
114155 | Some (M (l , w , r )) when Option . is_some(Wald . is_grout(w)) =>
115- P . log("degrout hit some case" );
156+ // P.log("degrout hit some case");
116157 // pull the inner cells out ("base")
117158 let W ((toks , cells )) = w;
118- P . show("l: " , Cell . show(l));
119- P . show ("w: " , Wald . show (w));
120- P . show("r: " , Cell . show(r));
159+ // P.show("l: ", Cell.show(l));
160+ // P.sexp ("w: ", Wald.sexp_of_t (w));
161+ // P.show("r: ", Cell.show(r));
121162 List . iter(Effects . remove, toks);
122163 // we wish to maximally stabilize grout positioning, ie grout that is removed
123164 // in this pass, if reinserted, should be reinserted in the same position.
@@ -137,7 +178,9 @@ let rec degrout = (c: Cell.t): Cells.t =>
137178 P . show("degrout cells_l" , Cell . show(l));
138179 let l = Cell . mark_degrouted(l, ~side= R );
139180 [ l] ;
140- | _ => [ l, ... cells]
181+ | _ =>
182+ let l = Cell . mark_degrouted(l, ~side= R );
183+ [ l, ... cells] ;
141184 };
142185 let cells_lr =
143186 switch (Lists . Framed . ft(cells_l)) {
@@ -149,7 +192,9 @@ let rec degrout = (c: Cell.t): Cells.t =>
149192 let r = Cell . mark_degrouted(~side= L , r);
150193 P . show("degrout cells_r" , Cell . show(l));
151194 [ r] ;
152- | _ => cells_l @ [ r]
195+ | _ =>
196+ let r = Cell . mark_degrouted(r, ~side= L );
197+ cells_l @ [ r] ;
153198 };
154199 List . concat_map(degrout, cells_lr);
155200 | _ => [ c]
@@ -188,10 +233,10 @@ let fill_default =
188233let fill_swing = (cs: Cells . t , sw: Walk . Swing . t , ~from: Dir . t ) => {
189234 let cs = Dir . pick(from, (List . rev, Fun . id), cs);
190235 // if (dbg^) {
191- // P.log("--- Grouter.fill_swing");
192- // P.show("from", Dir.show(from));
193- // P.show("sw", Walk.Swing.show(sw));
194- // P.show("cs", Cells.show(cs));
236+ P . log("--- Grouter.fill_swing" );
237+ P . show("from" , Dir . show(from));
238+ P . show("sw" , Walk . Swing . show(sw));
239+ P . show("cs" , Cells . show(cs));
195240 // };
196241 let (bot , top ) = Walk . Swing . (bot(sw), top(sw));
197242 switch (bot) {
@@ -244,28 +289,29 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
244289 // NOTE: split padding is a possible candidate for newline bug fix
245290 switch (Cells . split_padding (cs )) {
246291 | (l, cs, r) when List.for_all(Cell.Space.is_space, cs) =>
247- if (dbg^) {
248- P.log("--- Grouter.fill_swing/Tile/all space");
249- P.show("l", Cell . show(l));
250- P.show("cs", Cells . show(cs));
251- P.show("r", Cell . show(r));
252- };
292+ // if (dbg^) {
293+ P.log("--- Grouter.fill_swing/Tile/all space");
294+ P.show("l", Cell . show(l));
295+ P.show("cs", Cells . show(cs));
296+ P.show("r", Cell . show(r));
297+ // };
253298 // prioritize getting any carets in cs over to the left for now.
254299 // todo: parametrize this based on parsing mode
255300 let l = List.hd(Cells.squash([l, ...cs]));
301+ P.show("squashed l", Cell . show(l));
256302 // let r = List.hd(Cells.squash(cs @ [r]));
257- let r = Cell . pad(~l, fill_default(bot), ~r);
258- if (dbg^ ) {
259- P . show("padded" , Cell . show(r ));
260- };
261- r ;
303+ let ret = Cell.pad(~l, fill_default(bot), ~r);
304+ // if (dbg^) {
305+ P.show("padded", Cell . show(ret ));
306+ // };
307+ ret ;
262308 | (l, cs, r) =>
263- if (dbg^ ) {
264- P . log("--- Grouter.fill_swing/Tile/not all space" );
265- P . show("l" , Cell . show(l));
266- P . show("cs" , Cells . show(cs));
267- P . show("r" , Cell . show(r));
268- };
309+ // if (dbg^) {
310+ P.log("--- Grouter.fill_swing/Tile/not all space");
311+ P.show("l", Cell . show(l));
312+ P.show("cs", Cells . show(cs));
313+ P.show("r", Cell . show(r));
314+ // };
269315 // cells is list of children cells for target grout form
270316 // cons/scnoc here effectively add l/r as children of prefix/postfix grout
271317 let cells =
@@ -318,12 +364,12 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
318364
319365let fill_swings =
320366 (~repair, ~from, cells: list (Cell . t ), swings: list (Walk . Swing . t )) => {
321- if (dbg^ ) {
322- P . log("--- Grouter.fill_swings" );
323- P . show("from" , Dir . show(from));
324- P . show("cells" , Cells . show(Dir . pick(from, (List . rev, Fun . id), cells)));
325- // P.show("swings", Fmt.to_to_string(Fmt.list(Walk.Swing.pp), swings));
326- };
367+ // if (dbg^) {
368+ P . log("--- Grouter.fill_swings" );
369+ // P.show("from", Dir.show(from));
370+ // P.show("cells", Cells.show(Dir.pick(from, (List.rev, Fun.id), cells)));
371+ // P.show("swings", Fmt.to_to_string(Fmt.list(Walk.Swing.pp), swings));
372+ // };
327373 cells
328374 |> Dir . pick(from, (List . rev, Fun . id))
329375 |> (repair ? List . concat_map(degrout) : Fun . id)
@@ -355,15 +401,14 @@ let fill = (~repair, ~from, cs, (swings, stances): Walk.t) => {
355401// cs should be a singleton cell
356402let pick = (~repair= false , ~from: Dir . t , cs: list (Cell . t ), ws: list (Walk . t )) => {
357403 // if (dbg^) {
358- // P.log("--- Grouter.pick");
404+ P . log("--- Grouter.pick" );
359405 // P.show("from", Dir.show(from));
360406 // P.show("cs", Cells.show(cs));
361407 // P.log("ws");
362408 // ws |> List.iter(w => P.show("w", Walk.show(w)));
363409 // };
364- Oblig . Delta . minimize(
365- ~to_zero=! repair,
366- fill(~repair, ~from, cs),
367- ws,
368- );
410+ let r =
411+ Oblig . Delta . minimize(~to_zero=! repair, fill(~repair, ~from, cs), ws);
412+ P . log("Grouter.pick done" );
413+ r;
369414};
0 commit comments