Skip to content

Commit

Permalink
Finished fixing errors related to filtering logic in meld/walker/wald…
Browse files Browse the repository at this point in the history
… & updated js grammar
  • Loading branch information
green726 committed Sep 16, 2024
1 parent ce010bc commit 5e33e5a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 55 deletions.
5 changes: 0 additions & 5 deletions src/core/grammar/Grammar.rei
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
module Filter: {
[@deriving (show({with_path: false}), sexp, yojson, ord)]
type t = list(string);
};

module Sym: {
[@deriving (show({with_path: false}), sexp, yojson, ord)]
type t = Sym.t(Label.t, (Filter.t, Sort.t));
Expand Down
4 changes: 2 additions & 2 deletions src/core/grammar/Sorts.re
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ module Deps = {
let kids = (s: Sort.t): Deps.t =>
Tile.Sym.all(s)
|> List.filter_map(Sym.get_nt)
|> List.map(snd)
// |> List.map(snd)
|> List.fold_left(
(deps, (s, bound)) => Deps.add(s, Dep.mk(bound), deps),
(deps, ((_, s), bound)) => Deps.add(s, Dep.mk(bound), deps),
Deps.empty,
);
let kids = Stds.Memo.general(kids);
Expand Down
4 changes: 3 additions & 1 deletion src/core/material/Mtrl.re
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ module T = {
let compare = compare;
});
let sort: t => Sorted.t =
map(~space=Fun.const(), ~grout=Grout.T.sort, ~tile=Tile.T.sort);
map(~space=Fun.const(), ~grout=Grout.T.sort, ~tile=t =>
([], Tile.T.sort(t))
);
let padding =
fun
| Space(_) => Padding.none
Expand Down
5 changes: 4 additions & 1 deletion src/core/material/Tile.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ module NT = {
[@deriving (show({with_path: false}), sexp, yojson, ord)]
type t = ((Filter.t, Sort.t), Bound.t(Mold.t));
let root = (([], Sort.root), Bound.Root);
let mk = (~mold=Bound.Root, ~filter: Filter.t=[], s) => ((filter, s), mold);
let mk = (~mold=Bound.Root, ~filter: Filter.t=[], s) => (
(filter, s),
mold,
);

let sort = fst;
let bounds =
Expand Down
13 changes: 8 additions & 5 deletions src/core/material/Walker.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Stds;
open Walk;

let mtrlize_tile =
Memo.general(((l, r, s, from)) =>
Memo.general(((l, r, (filter, s), from)) =>
Grammar.v
|> Sort.Map.find(s)
|> Prec.Table.mapi(((p, a), rgx) => {
Expand All @@ -15,7 +15,7 @@ let mtrlize_tile =
let enter_from = (from: Dir.t) =>
// currently filtering without assuming single operator form
// for each prec level. this may need to change.
RZipper.enter(~from, rgx)
RZipper.enter(~from, ~filter, rgx)
|> List.filter_map(
fun
| Bound.Root => None
Expand All @@ -31,7 +31,8 @@ let mtrlize_tile =
})
|> List.concat
);
let mtrlize_tile = (~l=Bound.Root, ~r=Bound.Root, s: Sort.t, ~from: Dir.t) =>
let mtrlize_tile =
(~l=Bound.Root, ~r=Bound.Root, s: (Filter.t, Sort.t), ~from: Dir.t) =>
mtrlize_tile((l, r, s, from));

let mtrlize_grout =
Expand All @@ -50,8 +51,9 @@ let mtrlize_grout =
|> List.map(Sym.t);

let mtrlize =
(~l=Bound.Root, ~r=Bound.Root, s: Sort.t, ~from: Dir.t): list(Mtrl.Sym.t) =>
List.map(Mtrl.Sym.of_grout, mtrlize_grout(~l, s, ~r))
(~l=Bound.Root, ~r=Bound.Root, s: (Filter.t, Sort.t), ~from: Dir.t)
: list(Mtrl.Sym.t) =>
List.map(Mtrl.Sym.of_grout, mtrlize_grout(~l, snd(s), ~r))
@ List.map(Mtrl.Sym.of_tile, mtrlize_tile(~l, s, ~r, ~from));

let swing_over = (w: Walk.t, ~from: Dir.t) =>
Expand Down Expand Up @@ -110,6 +112,7 @@ let swing_into = (w: Walk.t, ~from: Dir.t) => {
// any descendant sort T.
Swing.height(swing) == 0
? Sorts.deps(s)
|> List.map(s => ([], s))
|> List.concat_map(mtrlize(~from))
|> List.map(sym => arrive(sym, w, ~from))
|> Index.union_all
Expand Down
4 changes: 2 additions & 2 deletions src/core/parser/Grouter.re
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let fill_default =
| Mtrl.Space(_) => Cell.dirty
// grout case isn't quite right... but shouldn't arise
| Grout(s)
| Tile((s, _)) =>
| Tile(((_, s), _)) =>
Cell.put(
Meld.of_tok(
~l=Cell.dirty,
Expand All @@ -164,7 +164,7 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
|> Option.some
: None;
| Grout(s)
| Tile((s, _)) =>
| Tile(((_, s), _)) =>
open Options.Syntax;
let (nt_l, nt_r) =
Walk.Swing.is_eq(sw) ? (bot, bot) : Dir.order(from, (top, bot));
Expand Down
2 changes: 1 addition & 1 deletion src/core/structure/Token.re
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Molded = {
Mtrl.map(
~space=Fun.id,
~grout=fst,
~tile=((_, m: Mold.t)) => m.sort,
~tile=((_, m: Mold.t)) => ([], m.sort),
tok.mtrl,
);
let length = (tok: t) =>
Expand Down
68 changes: 36 additions & 32 deletions src/ts/Grammar.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

//TODO: Look into writing an extension to the tylr grammar to do more of a ts precedence with a table of named values and each individual form associated with a particular named value - also with the nested arrays for separate precedence levels by form/sort?

open Sexplib.Std;
open Ppx_yojson_conv_lib.Yojson_conv.Primitives;

module Sym = {
include Sym;
[@deriving (show({with_path: false}), sexp, yojson, ord)]
Expand All @@ -37,12 +34,11 @@ let nt = (filter: Filter.t, srt: Sort.t) =>
*/

let c = (~p=Padding.none, s) => t(Label.const(~padding=p, s));
let kw = (~l=true, ~r=true, ~indent=true) =>
c(~p=Padding.kw(~l, ~r, ~indent, ()));
let op = (~l=true, ~r=true, ~indent=true) =>
c(~p=Padding.op(~l, ~r, ~indent, ()));
let kw = (~space=(true, true), ~break=(false, false), ~indent=true) =>
c(~p=Padding.kw(~space, ~break, ~indent, ()));
let op = (~space=(true, true), ~break=(false, false), ~indent=true) =>
c(~p=Padding.op(~space, ~break, ~indent, ()));
let brc = (side: Dir.t) => c(~p=Padding.brc(side));

let tokop_alt = ss => alt(List.map(op, ss));

let comma_sep = (r: Regex.t) => seq([r, star(seq([c(","), r]))]);
Expand Down Expand Up @@ -94,7 +90,7 @@ module rec Pat: SORT = {
alt([Pat.atom(), assignment_pat(Exp.atom, Pat.atom)]),
]);

let obj_assignmnet_pat =
let obj_assignment_pat =
seq([
alt([t(Id_lower)]),
c("="),
Expand All @@ -108,13 +104,13 @@ module rec Pat: SORT = {
comma_sep(
alt([
Pat.atom(~filter=["pair_pat", "rest_pat"], ()),
obj_assignmnet_pat,
obj_assignment_pat,
]),
),
brc(R, "}"),
]);

let destruct_pat = alt([Pat.atom(~filter=["obj_pat"], ()), array_pat]);
let destruct_pat = alt([obj_pat, array_pat]);

let lhs_exp =
alt([
Expand Down Expand Up @@ -158,13 +154,13 @@ and Exp: SORT = {

let method_def =
seq([
opt(kw(~l=false, ~indent=false, "static")),
opt(kw(~l=false, ~indent=false, "async")),
opt(kw(~space=(false, true), ~indent=false, "static")),
opt(kw(~space=(false, true), ~indent=false, "async")),
opt(
alt([
kw(~l=false, ~indent=false, "get"),
kw(~l=false, ~indent=false, "set"),
kw(~l=false, ~indent=false, "*"),
kw(~space=(false, true), ~indent=false, "get"),
kw(~space=(false, true), ~indent=false, "set"),
kw(~space=(false, true), ~indent=false, "*"),
]),
),
t(Id_lower),
Expand Down Expand Up @@ -197,16 +193,16 @@ and Exp: SORT = {
let call_signature = params(Exp.atom, Pat.atom);
let func_exp =
seq([
opt(kw(~l=false, ~indent=false, "async")),
kw(~l=false, "function"),
opt(kw(~space=(false, true), ~indent=false, "async")),
kw(~space=(false, true), "function"),
opt(t(Id_lower)),
call_signature,
stat_block,
]);

let arrow_function =
seq([
opt(kw(~l=false, ~indent=false, "async")),
opt(kw(~space=(false, true), ~indent=false, "async")),
alt([t(Id_lower), call_signature]),
op("=>"),
alt([atom(), stat_block]),
Expand All @@ -216,9 +212,9 @@ and Exp: SORT = {

let generator_function =
seq([
opt(kw(~l=false, ~indent=false, "async")),
opt(kw(~space=(false, true), ~indent=false, "async")),
c("function"),
kw(~l=false, "*"),
kw(~space=(false, true), "*"),
opt(t(Id_lower)),
call_signature,
stat_block,
Expand All @@ -227,7 +223,11 @@ and Exp: SORT = {
let _initializer = seq([op("="), atom()]);

let field_def =
seq([opt(kw(~l=false, "static")), property_name, opt(_initializer)]);
seq([
opt(kw(~space=(false, true), "static")),
property_name,
opt(_initializer),
]);

let class_static_block = seq([kw("static"), c(";"), stat_block]);

Expand All @@ -248,7 +248,7 @@ and Exp: SORT = {

let _class =
seq([
kw(~l=false, "class"),
kw(~space=(false, true), "class"),
opt(t(Id_lower)),
opt(class_heritage),
class_body,
Expand Down Expand Up @@ -373,13 +373,13 @@ and Stat: SORT = {

let method_def =
seq([
opt(kw(~l=false, ~indent=false, "static")),
opt(kw(~l=false, ~indent=false, "async")),
opt(kw(~space=(false, true), ~indent=false, "static")),
opt(kw(~space=(false, true), ~indent=false, "async")),
opt(
alt([
kw(~l=false, ~indent=false, "get"),
kw(~l=false, ~indent=false, "set"),
kw(~l=false, ~indent=false, "*"),
kw(~space=(false, true), ~indent=false, "get"),
kw(~space=(false, true), ~indent=false, "set"),
kw(~space=(false, true), ~indent=false, "*"),
]),
),
t(Id_lower),
Expand Down Expand Up @@ -450,8 +450,8 @@ and Stat: SORT = {

let func_declaration =
seq([
opt(kw(~l=false, ~indent=false, "async")),
kw(~l=false, "function"),
opt(kw(~space=(false, true), ~indent=false, "async")),
kw(~space=(false, true), "function"),
opt(t(Id_lower)),
call_signature,
stat_block,
Expand All @@ -461,7 +461,11 @@ and Stat: SORT = {
let property_name = alt([t(Id_lower)]);
let _initializer = seq([op("="), Exp.atom()]);
let field_def =
seq([opt(kw(~l=false, "static")), property_name, opt(_initializer)]);
seq([
opt(kw(~space=(false, true), "static")),
property_name,
opt(_initializer),
]);

let class_static_block = seq([kw("static"), c(";"), stat_block]);
let class_heritage = seq([kw("extends"), Exp.atom()]);
Expand All @@ -481,7 +485,7 @@ and Stat: SORT = {

let class_declaration =
seq([
kw(~l=false, "class"),
kw(~space=(false, true), "class"),
opt(t(Id_lower)),
opt(class_heritage),
class_body,
Expand Down
6 changes: 1 addition & 5 deletions src/web/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
(executable
(name main)
(modules Main)
<<<<<<< HEAD
(libraries tylr_web tylr_ts)
=======
(libraries tylr_web tylr_hazel core)
>>>>>>> origin/melds
(libraries tylr_web tylr_ts core)
(modes js)
(js_of_ocaml)
(preprocess
Expand Down
2 changes: 1 addition & 1 deletion src/web/view/dec/Meld.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let sort_clss = (s: Mtrl.Sorted.t) =>
switch (s) {
| Space(_) => ["Space"]
| Grout(s) => ["Grout", Sort.to_str(s)]
| Tile(s) => ["Tile", Sort.to_str(s)]
| Tile(s) => ["Tile", Sort.to_str(snd(s))]
};

module Child = {
Expand Down

0 comments on commit 5e33e5a

Please sign in to comment.