From 5e33e5a037e60194c54fe56aeb9a53804d674e47 Mon Sep 17 00:00:00 2001 From: Milan Lustig Date: Mon, 16 Sep 2024 15:44:29 -0400 Subject: [PATCH] Finished fixing errors related to filtering logic in meld/walker/wald & updated js grammar --- src/core/grammar/Grammar.rei | 5 --- src/core/grammar/Sorts.re | 4 +-- src/core/material/Mtrl.re | 4 ++- src/core/material/Tile.re | 5 ++- src/core/material/Walker.re | 13 ++++--- src/core/parser/Grouter.re | 4 +-- src/core/structure/Token.re | 2 +- src/ts/Grammar.re | 68 +++++++++++++++++++----------------- src/web/dune | 6 +--- src/web/view/dec/Meld.re | 2 +- 10 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/core/grammar/Grammar.rei b/src/core/grammar/Grammar.rei index 5012ea50..903967fc 100644 --- a/src/core/grammar/Grammar.rei +++ b/src/core/grammar/Grammar.rei @@ -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)); diff --git a/src/core/grammar/Sorts.re b/src/core/grammar/Sorts.re index 0acf3560..daf8d383 100644 --- a/src/core/grammar/Sorts.re +++ b/src/core/grammar/Sorts.re @@ -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); diff --git a/src/core/material/Mtrl.re b/src/core/material/Mtrl.re index e932bcf8..94ca4f7d 100644 --- a/src/core/material/Mtrl.re +++ b/src/core/material/Mtrl.re @@ -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 diff --git a/src/core/material/Tile.re b/src/core/material/Tile.re index 6eb453c0..32026651 100644 --- a/src/core/material/Tile.re +++ b/src/core/material/Tile.re @@ -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 = diff --git a/src/core/material/Walker.re b/src/core/material/Walker.re index 5987c872..2f8c819d 100644 --- a/src/core/material/Walker.re +++ b/src/core/material/Walker.re @@ -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) => { @@ -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 @@ -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 = @@ -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) => @@ -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 diff --git a/src/core/parser/Grouter.re b/src/core/parser/Grouter.re index 11316780..3378b17d 100644 --- a/src/core/parser/Grouter.re +++ b/src/core/parser/Grouter.re @@ -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, @@ -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)); diff --git a/src/core/structure/Token.re b/src/core/structure/Token.re index 6db026d2..6a32ed32 100644 --- a/src/core/structure/Token.re +++ b/src/core/structure/Token.re @@ -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) => diff --git a/src/ts/Grammar.re b/src/ts/Grammar.re index 0da162fe..8d0d415c 100644 --- a/src/ts/Grammar.re +++ b/src/ts/Grammar.re @@ -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)] @@ -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]))]); @@ -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("="), @@ -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([ @@ -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), @@ -197,8 +193,8 @@ 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, @@ -206,7 +202,7 @@ and Exp: SORT = { 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]), @@ -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, @@ -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]); @@ -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, @@ -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), @@ -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, @@ -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()]); @@ -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, diff --git a/src/web/dune b/src/web/dune index 8df5965d..76697422 100644 --- a/src/web/dune +++ b/src/web/dune @@ -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 diff --git a/src/web/view/dec/Meld.re b/src/web/view/dec/Meld.re index 675773c7..17fb33d7 100644 --- a/src/web/view/dec/Meld.re +++ b/src/web/view/dec/Meld.re @@ -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 = {