Skip to content

Commit

Permalink
projectors large-scale cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
disconcision committed May 17, 2024
1 parent af38b9c commit a473d33
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 262 deletions.
2 changes: 0 additions & 2 deletions src/haz3lcore/tiles/Grout.re
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,3 @@ let merge = (gs: list(t)): option(t) =>
| Some((_, ft)) => hd.shape == ft.shape ? Some(hd) : None
}
};

let update_id = (g: t, id: Id.t): t => {...g, id};
7 changes: 0 additions & 7 deletions src/haz3lcore/tiles/Piece.re
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,3 @@ let mold_of = (~shape=Nib.Shape.Convex, p: t) =>
| Grout(g) => Mold.of_grout(g, Any)
| Secondary(_) => Mold.of_secondary({sort: Any, shape})
};

let update_id = (p: t, id: Id.t): t =>
switch (p) {
| Tile(t) => Tile(Tile.update_id(id, t))
| Grout(g) => Grout(Grout.update_id(g, id))
| Secondary(w) => Secondary(Secondary.update_id(w, id))
};
2 changes: 0 additions & 2 deletions src/haz3lcore/tiles/Secondary.re
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,3 @@ let get_string: secondary_content => string =
};

let id = w => w.id;

let update_id = (w: t, id) => {...w, id};
2 changes: 0 additions & 2 deletions src/haz3lcore/tiles/Tile.re
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,3 @@ let pop_r = (tile: t): (segment, piece) =>
// };
// };
// };

let update_id = (id, t: t) => {...t, id};
24 changes: 7 additions & 17 deletions src/haz3lcore/zipper/Editor.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Meta = {
segment_projected: Segment.t,
measured_projected: Measured.t,
term_projected: Term.UExp.t,
term_ranges_projected: TermRanges.t,
term_ranges: TermRanges.t,
terms: TermMap.t,
tiles: TileMap.t,
holes: list(Grout.t),
Expand All @@ -34,7 +34,7 @@ module Meta = {
measured_real,
measured_projected: Measured.of_segment(segment_projected),
segment_projected,
term_ranges_projected: TermRanges.mk(segment_projected),
term_ranges: TermRanges.mk(segment_projected),
tiles: TileMap.mk(segment_projected),
term_projected,
terms,
Expand All @@ -43,19 +43,18 @@ module Meta = {
};
};

//TODO(andrew): what is this module used for?
module type S = {
let touched: Touched.t;
let measured_projected: Measured.t;
let term_ranges_projected: TermRanges.t;
let term_ranges: TermRanges.t;
let col_target: int;
};
let module_of_t = (m: t): (module S) =>
(module
{
let touched = m.touched;
let measured_projected = m.measured_projected;
let term_ranges_projected = m.term_ranges_projected;
let term_ranges = m.term_ranges;
let col_target = m.col_target;
});

Expand Down Expand Up @@ -88,8 +87,8 @@ module Meta = {
segment_projected,
)
: measured_real;
let term_ranges_projected =
is_edit ? TermRanges.mk(segment_projected) : meta.term_ranges_projected;
let term_ranges =
is_edit ? TermRanges.mk(segment_projected) : meta.term_ranges;
let col_target =
switch (a) {
| Move(Local(Up | Down))
Expand All @@ -113,7 +112,7 @@ module Meta = {
measured_projected,
segment_real,
segment_projected,
term_ranges_projected,
term_ranges,
tiles: is_edit ? TileMap.mk(segment_projected) : meta.tiles,
term_projected,
terms,
Expand Down Expand Up @@ -235,15 +234,6 @@ let trailing_hole_ctx = (ed: t, info_map: Statics.Map.t) => {

let get_projectors = (ed: t) => ed.state.zipper.projectors;

let get_projector = (id: Id.t, ed: t) =>
Projector.Map.find(id, ed.state.zipper.projectors);

let add_projector = (id: Id.t, p: Projector.t, ed: t) =>
update_z(
z => {...z, projectors: Projector.Map.add(id, p, z.projectors)},
ed,
);

let map_projectors = (f: (Id.t, Projector.t) => Projector.t, ed: t) =>
update_z(
z => {...z, projectors: Projector.Map.mapi(f, z.projectors)},
Expand Down
32 changes: 32 additions & 0 deletions src/haz3lcore/zipper/Printer.re
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ let to_string_selection = (editor: Editor.t): string =>
)
|> String.concat("\n");

let to_log = (~measured: Measured.t, z: Zipper.t): t => {
code:
to_rows(
~holes=None,
~measured,
~caret=Some(Zipper.caret_point(measured, z)),
~indent=" ",
~segment=seg_of_zip(z),
),
selection: z.selection.content |> of_segment(~holes=None) |> lines_to_list,
backpack:
List.map(
(s: Selection.t) =>
s.content |> of_segment(~holes=None) |> lines_to_list,
z.backpack,
),
};

let to_log_flat = (~measured, z: Zipper.t): string => {
let {code, selection, backpack} = to_log(~measured, z);
Printf.sprintf(
"CODE:\n%s\nSELECTION:\n%s\n%s\n",
String.concat("\n", code),
String.concat("\n", selection),
backpack
|> List.mapi((i, b) =>
Printf.sprintf("BP(%d):\n %s\n", i, String.concat("\n", b))
)
|> String.concat(""),
);
};

let zipper_of_string =
(~zipper_init=Zipper.init(), str: string): option(Zipper.t) => {
let insert = (z: option(Zipper.t), c: string): option(Zipper.t) => {
Expand Down
154 changes: 1 addition & 153 deletions src/haz3lcore/zipper/Projector.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ module Map = {
let placehold = (ps: Map.t, p: Piece.t) =>
switch (Map.find(Piece.id(p), ps)) {
| None => p
| Some(pr) =>
//TODO(andrew): Maybe shouldn't just duplicate this id in the general case?
placeholder(pr, Piece.id(p))
| Some(pr) => placeholder(pr, Piece.id(p))
};

let rec of_segment = (projectors, seg: Segment.t): Segment.t => {
Expand Down Expand Up @@ -87,153 +85,3 @@ let selection_sides_is =
piece_is(projectors, ListUtil.hd_opt(s.content)),
piece_is(projectors, ListUtil.last_opt(s.content)),
);

/*
projector map has ids of projectors
can use infomap to get ancestors of projectors
projector map has projector type
but for each projector we also need:
- it's extent (to use for measured)
- clarification: 'range of projector': extent in base syntax
- vs 'domain of projector': extent in view (eg collapsed entirely for fold)
- it's view function (to use for view)
- it's action function (to use for action dispatch
we might want to pre-derive:
- parent segment
- the range of the projector in the segment
measured side:
recurse into segment, accumulating ancestor list
i guess this alternatingly comes from enclosing tiles and segment skels
i guess inside a segment, we recurse into the skel, tracking going through ancestors
from the ancestor list until we hit a tile
whose id is the target id
then we subsistute in a token consisting only of spaces/linebreaks which
takes up the space of the projector (which i guess should be a starting
and ending offset in the frame of the parent editor)
view side:
recurse into segment, accumulating ancestor list
i guess this alternatingly comes from enclosing tiles and segment skels
i guess inside a segment, we recurse into the skel, tracking going through ancestors
from the ancestor list until we hit a tile
whose id is the target id
maybe to make things easier:
if for each projector we know its parent segment
and know what range of the segment 0 <= start < end < length(seg) corresponds to the projector
ok, new plan:
in view_of_segment, we recurse the skel looking for projectors. the first (topmost) one we find,
we find it's range in the segment, and create new segment to render, consisting of the segment
vefore the projector subrange, a placeholder for the projector subrange, and the segment after
the projector subrange. we don't handle any drawing for the projector; that goes through Deco
for first pass we dont need full recursion, so can just have a deco type that is subeditors
for first pass subeditor will just be stub views, so they can be treated as inline/tokens
(for higher phases will want to be able to insert full editors, so will likely need editors
to have programable starting col, so that we can draw them as if they were just a subsegment
of the parent editor)
action side:
for opaque projectors, we will prohibit movement into them,
and make forming them eject the cursor. as long as we
ensure the cursor cant move into one, we can dont
need to worry about whether we're inside one for action permissions
so for basic movement actions, we make moving left into an
opaque leaf projector jump to its right, and vice versa
(phase 1.5 we allow a single cursor state on the projector itself)
actions: movement
- phase 1.0: move past subview
- phase 1.5: move onto subview
- phase 2: move into subview
for phase 1.5, we probably need to extend caret position to
model the cursor being on the projector itself. being in this
state will dispatch keyboard input to the projector's handler
old:
type t =
| Outer
| Inner(int, int);
v2:
type inner =
| Token(int, int)
| SubCell(Id.t);
type t =
| Outer
| Inner(inner);
v3:
type base =
| Outer
| Inner(int, int);
type t =
| Base(base)
| SubCell(Id.t, t); // supports nested subcells
primary movement needs to check if the piece we're trying to move into starts/ends
a subcell. if so, we (phase i) skip over it or (phase ii) move into it, ie set caret
position to Subcell(Id.t,og_caret_pos)
2024-02-26
want to add some entries to Measured
right now the placeholder approach is that a monotoken is introduced
with the same id as the projector root term. this seems to work well
in the case where the projector root tile is convex, as this means that
the delims on the left and right of the projected segment are shards of
the same tile. but actually even this creates some issues actually,
see the FuCkNASTY hackzz in Measured.
in general we are concerned with caret positions to the left and right
of the projected segment. caret_point/base_point is excepting there
because they are looking for ids not found in measured, in the case
of infix operators on both sides so they can't currently be folded.
not sure if its a good idea, but one approach is to make sure that
the ids in Measured include the left and right delims of the projected
segment instead of the root id.
but we probably dont want to add multiple tiles to the projection zipper.
but maybe we could add ids after the fact, copying some measurements
by querying the measurements of the placeholder tile.
collapsed segments:
[1]: root is 1, L is 1, R is 1
[(1)]: root is [(,)], L is [(], R is [)]
[1+2] : root is +, L is 1, R is 2
[let x = 1 in 4] root is [let,=,in], L is [let], R is 4
(mythical postfix operator:)
[5!] root is [,], L is 5, L is [!]
ideally the placeholder tile should correspond to the left and right
delims of the projected segment so as to make measured accesses
seamless. so what if:
placeholder tiles uses two shards, one for the left delim and
one for the right delim
then after we run Measured we get the placeholder measurement,
and create (up to) two new entries in the Measured map, one for
the left delim and one for the right delim,
NOTE: currently the FuCkNASTY occurs on the right delim
of a collapsed "(1+2)" segment, but not a "1" segment
Current status:
singletons and convex seem to work fine
can fold [fun, ->] and [let, =, in], can unfold (from one side at least),
some movement problems
can fold infix ops if surrounded by parens; movement bugged, cant unfold
*/
6 changes: 2 additions & 4 deletions src/haz3lcore/zipper/action/Move.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ module Make = (M: Editor.Meta.S) => {
};

let is_at_side_of_row = (d: Direction.t, z: Zipper.t) => {
print_endline("Move.is_at_side_of_row");
let Measured.Point.{row, col} = caret_point(z);
switch (Zipper.move(d, z)) {
| None => true
Expand Down Expand Up @@ -177,7 +176,6 @@ module Make = (M: Editor.Meta.S) => {
/* Here f should be a function which results in strict d-wards
movement of the caret. Iterate f until we get to the closet
caret position to a target derived from the initial position */
print_endline("Move.do_vertical");
let cur_p = caret_point(z);
let goal =
Measured.Point.{
Expand Down Expand Up @@ -239,10 +237,10 @@ module Make = (M: Editor.Meta.S) => {
| Some(z) => Some(z)
};

let jump_to_id = (~init=Direction.Left, z: t, id: Id.t): option(t) => {
let jump_to_id = (z: t, id: Id.t): option(t) => {
let* {origin, _} = Measured.find_by_id(id, M.measured_projected);
let z =
switch (init == Left ? to_start(z) : to_end(z)) {
switch (to_start(z)) {
| None => z
| Some(z) => z
};
Expand Down
Loading

0 comments on commit a473d33

Please sign in to comment.