@@ -110,8 +110,14 @@ let bake_stances = stances => stances |> List.map(bake_stance) |> Option.some;
110110
111111let rec degrout = (c: Cell . t ): Cells . t =>
112112 switch (Cell . get(c)) {
113+ // open the cell
113114 | Some (M (l , w , r )) when Option . is_some(Wald . is_grout(w)) =>
115+ P . log("degrout hit some case" );
116+ // pull the inner cells out ("base")
114117 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));
115121 List . iter(Effects . remove, toks);
116122 // we wish to maximally stabilize grout positioning, ie grout that is removed
117123 // in this pass, if reinserted, should be reinserted in the same position.
@@ -123,9 +129,12 @@ let rec degrout = (c: Cell.t): Cells.t =>
123129 let cells_l =
124130 switch (cells) {
125131 | [ hd , ... tl ] when Cell . Space . is_space(l) =>
132+ // mark_degrouted says "a grout once was here"
126133 let l = Cell . mark_degrouted(l, ~side= R );
134+ P . show("degrout cells_l & pad without squash" , Cell . show(l));
127135 [ Cell . pad(~squash= false , ~l, hd), ... tl] ;
128136 | [] when Cell . Space . is_space(l) =>
137+ P . show("degrout cells_l" , Cell . show(l));
129138 let l = Cell . mark_degrouted(l, ~side= R );
130139 [ l] ;
131140 | _ => [ l, ... cells]
@@ -134,9 +143,11 @@ let rec degrout = (c: Cell.t): Cells.t =>
134143 switch (Lists . Framed . ft(cells_l)) {
135144 | Some ((pre , ft )) when Cell . Space . is_space(r) =>
136145 let r = Cell . mark_degrouted(~side= L , r);
146+ P . show("degrout cells_r & pad without squash" , Cell . show(l));
137147 Lists . Framed . put_ft(pre, Cell . pad(~squash= false , ft, ~r));
138148 | None when Cell . Space . is_space(r) =>
139149 let r = Cell . mark_degrouted(~side= L , r);
150+ P . show("degrout cells_r" , Cell . show(l));
140151 [ r] ;
141152 | _ => cells_l @ [ r]
142153 };
@@ -158,23 +169,40 @@ let fill_default =
158169 ),
159170 );
160171
172+ /*
173+ slot = swing = "tower" of nonterminals (modeled via chain) - tower is a partial (left spine) "derivation" through non-terminal symbols to other non terminals
174+ bot is the most important nt as it is the fill target; everything above is context
175+ swing example:
176+ _ + n * _
177+ walk (+ -> *) L->R
178+ swing b/w: R(+), L(*)
179+ filling in the swing would be filling the left arg of times L(*)
180+
181+ top and bot essentially provide L/R bounds on the fill of interest
182+
183+
184+ takes in a particular bin of fills (if 4 fills, 3 slots, 4 fills will be partitioned into 3 bins)
185+ */
186+
161187// assumes cs already squashed sans padding
162188let fill_swing = (cs: Cells . t , sw: Walk . Swing . t , ~from: Dir . t ) => {
163189 let cs = Dir . pick(from, (List . rev, Fun . id), cs);
164- if (dbg^ ) {
165- P . log("--- Grouter.fill_swing" );
166- P . show("from" , Dir . show(from));
167- P . show("sw" , Walk . Swing . show(sw));
168- P . show("cs" , Cells . show(cs));
169- };
190+ // 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));
195+ // };
170196 let (bot , top ) = Walk . Swing . (bot(sw), top(sw));
171197 switch (bot) {
172198 | Space (nt ) =>
173- if (dbg^ ) {
174- P . log("--- Grouter.fill_swing/Space" );
175- P . show("nt" , Space . NT . show(nt));
176- P . show("cs" , Cells . show(cs));
177- };
199+ // if (dbg^) {
200+ // P.log("--- Grouter.fill_swing/Space");
201+ // P.show("from", Dir.show(from));
202+ // P.show("sw", Walk.Swing.show(sw));
203+ // P.show("nt", Space.NT.show(nt));
204+ // P.show("cs", Cells.show(cs));
205+ // };
178206 let squashed = Cells . squash(cs);
179207 if (dbg^ ) {
180208 P . show("squashed" , Cells . show(squashed));
@@ -209,8 +237,11 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
209237 open Options . Syntax ;
210238 let (nt_l , nt_r ) =
211239 Walk . Swing . is_eq(sw) ? (bot, bot) : Dir . order(from, (top, bot));
240+ // check that fills are properly precedence bounded by swing nts
212241 let + has_pre = Cells.are_bounded(cs, nt_l, ~from=L)
213242 and + has_pos = Cells.are_bounded(cs, nt_r, ~from=R);
243+ // handles breadcrumbs from degrouting to retain grout positioning
244+ // NOTE: split padding is a possible candidate for newline bug fix
214245 switch (Cells . split_padding (cs )) {
215246 | (l, cs, r) when List.for_all(Cell.Space.is_space, cs) =>
216247 if (dbg^) {
@@ -235,6 +266,8 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
235266 P . show("cs" , Cells . show(cs));
236267 P . show("r" , Cell . show(r));
237268 };
269+ // cells is list of children cells for target grout form
270+ // cons/scnoc here effectively add l/r as children of prefix/postfix grout
238271 let cells =
239272 cs
240273 |> (has_pre ? List . cons(l) : Lists . map_hd(Cell . pad(~l)))
@@ -249,6 +282,8 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
249282 has_pos ? [ Effects . insert(pos(s))] : [] ,
250283 ]
251284 |> List . concat;
285+ // chain is the content of the cell that we will be returning
286+ // essentially a meld represented with Chain.t
252287 let chain = Chain . mk(cells, toks);
253288 switch (Chain . unlink(chain)) {
254289 | Error (c ) =>
@@ -267,6 +302,20 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
267302 };
268303};
269304
305+ /* degrout explain:
306+ if fill: 1 > < 2
307+ then degrout would separate this into two separate fills
308+ [1, 2] with no infix grout
309+
310+ if fill: \n <> (newline is left child of hole - whitespace has max prec)
311+ then degrout produces \n (single newline cell)
312+
313+
314+ degrout functionally strips away top level grout to re-create from a clean(ish) slate to verify minimality
315+
316+ if same grout is reinserted to fill, it must be in the same pos
317+ */
318+
270319let fill_swings =
271320 (~repair, ~from, cells: list (Cell . t ), swings: list (Walk . Swing . t )) => {
272321 if (dbg^ ) {
@@ -278,7 +327,7 @@ let fill_swings =
278327 cells
279328 |> Dir . pick(from, (List . rev, Fun . id))
280329 |> (repair ? List . concat_map(degrout) : Fun . id)
281- // |> (dbg^ ? P.oshow("degrouted", Cells.show) : Fun.id)
330+ |> (true ? P . oshow("degrouted" , Cells . show) : Fun . id)
282331 |> Dir . pick(from, (List . rev, Fun . id))
283332 |> Lists . split_bins(List . length(swings))
284333 |> Oblig . Delta . minimize(~to_zero=! repair, c_bins =>
@@ -303,13 +352,14 @@ let fill = (~repair, ~from, cs, (swings, stances): Walk.t) => {
303352// pick a walk from ws that best accommodates the cells in cs, ie minimizes
304353// obligation delta. the given cells are expected to be oriented the same way as the
305354// given walks according to from.
355+ // cs should be a singleton cell
306356let pick = (~repair= false , ~from: Dir . t , cs: list (Cell . t ), ws: list (Walk . t )) => {
307357 // if (dbg^) {
308- // P.log("--- Grouter.pick");
309- // P.show("from", Dir.show(from));
310- // P.show("cs", Cells.show(cs));
311- // P.log("ws");
312- // ws |> List.iter(w => P.show("w", Walk.show(w)));
358+ // P.log("--- Grouter.pick");
359+ // P.show("from", Dir.show(from));
360+ // P.show("cs", Cells.show(cs));
361+ // P.log("ws");
362+ // ws |> List.iter(w => P.show("w", Walk.show(w)));
313363 // };
314364 Oblig . Delta . minimize(
315365 ~to_zero=! repair,
0 commit comments