Skip to content

Commit bc4e072

Browse files
committed
added hazel
1 parent c47dcde commit bc4e072

File tree

10 files changed

+363
-27
lines changed

10 files changed

+363
-27
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ init:
1919
@echo "" > src/core/material/precompiled/walk_r_no_filter_map.txt
2020
dune build @src/fmt --auto-promote || true
2121
dune build src --profile dev
22-
./_build/default/src/minijs/precompile.exe
22+
./_build/default/src/hazel/precompile.exe
2323
mv enter_l_map.txt src/core/material/precompiled
2424
mv enter_r_map.txt src/core/material/precompiled
2525
mv nts.txt src/core/material/precompiled

src/core/editor/Modify.re

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,18 +600,18 @@ let apply_remold = (changes, ctx) => {
600600
let+ changed = apply_changes(changes, ctx);
601601
() => {
602602
open Options.Syntax;
603-
let* ((ctx, fill), expanded, restrict_obligs) = changed();
604-
P.log("--- Modify.apply_remold/changed");
605-
P.sexp("ctx", Ctx.sexp_of_t(ctx));
606-
P.show("fill", Cell.show(fill));
607-
P.show("expanded", string_of_bool(expanded));
608-
P.show("restrict_obligs", string_of_bool(restrict_obligs));
603+
let* ((ctx, fill), _expanded, _restrict_obligs) = changed();
604+
// P.log("--- Modify.apply_remold/changed");
605+
// P.sexp("ctx", Ctx.sexp_of_t(ctx));
606+
// P.show("fill", Cell.show(fill));
607+
// P.show("expanded", string_of_bool(expanded));
608+
// P.show("restrict_obligs", string_of_bool(restrict_obligs));
609609
let (remolded, ctx) = remold(~fill, ctx);
610610
// P.log("--- Modify.apply_remold/remolded");
611611
// P.show("remolded", Grouted.show(remolded));
612612
// P.show("ctx", Ctx.show(ctx));
613-
P.show("effects", Fmt.(to_to_string(list(Effects.pp), Effects.log^)));
614-
P.show("delta", Oblig.Delta.show(Oblig.Delta.of_effects(Effects.log^)));
613+
// P.show("effects", Fmt.(to_to_string(list(Effects.pp), Effects.log^)));
614+
// P.show("delta", Oblig.Delta.show(Oblig.Delta.of_effects(Effects.log^)));
615615
// !expanded
616616
// && restrict_obligs
617617
// && Oblig.Delta.(not_hole(of_effects(Effects.log^)))

src/core/parser/Grouter.re

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,14 @@ let bake_stances = stances => stances |> List.map(bake_stance) |> Option.some;
110110

111111
let 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
162188
let 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+
270319
let 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
306356
let 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,

src/core/parser/Melder.re

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ let combine_cells =
108108
};
109109
};
110110

111+
//let x = 2 + _ >in< 1
112+
//insert an "in" after 1
113+
/*
114+
onto: let x = 2 + _ >in<
115+
fill: 1
116+
t: in
117+
118+
119+
onto: let x =
120+
fill: combine_cells(2 + _, 1) -> 2 + 1
121+
t: in
122+
123+
ret: (Grouted(Chain((2 + 1, grammar swing over let definition))), onto: let x = )
124+
*/
125+
111126
let connect_eq =
112127
(~repair=?, ~onto as d: Dir.t, onto: Terr.t, ~fill=Cell.empty, t: Token.t)
113128
: option((Grouted.t, Terr.t)) => {

src/core/structure/Cell.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,22 @@ module Space = {
280280
};
281281

282282
// returns split-off cell first (regardless of side), rest of cell second
283+
// if i find a degrout mark within the space cell, split the cell into two at that point
283284
let split = (~side as d: Dir.t, c: t) => {
284285
open Options.Syntax;
285286
assert(is_space(c));
287+
//g = general get
288+
//calling get on a space cell (spaces separated by empty cells with potential metadata ie degrout)
286289
let* m = g(c);
287290
let (cs, ts) = m |> Dir.pick(d, (Fun.id, Meld.rev)) |> Meld.to_chain;
291+
//traverses cells and searches for 1st cell with degrout mark
288292
let (cs_d, cs_b) =
289293
cs
290294
|> Lists.split_while(~f=(c: t) => Path.Map.is_empty(c.marks.degrouted));
291295
switch (cs_d, cs_b) {
292296
| (_, []) => None
293297
| ([], [b_hd, ...b_tl]) =>
298+
//ensuring no cursor duplication in cells with degrouted mark
294299
let b_hd_dup = {
295300
...b_hd,
296301
marks: {

0 commit comments

Comments
 (0)