···1414module Atom = {
1515 type t = t
1616 type subst = Map.t<schematic, t>
1717+ type AtomDef.atomTag<_> += Tag: AtomDef.atomTag<t>
1718 let substitute = (term: t, subst: subst) =>
1819 Array.flatMap(term, piece => {
1920 switch piece {
···282283 switch Option.getUnsafe(substs[var - from]) {
283284 | Some(v) => v
284285 | None =>
285285- throw(
286286- SExpFunc.SubstNotCompatible(`index ${Int.toString(var - from)} not of sort string`),
287287- )
286286+ throw(SExp.SubstNotCompatible(`index ${Int.toString(var - from)} not of sort string`))
288287 }
289288 } else {
290289 [Var({idx: var - to})]
···333332334333 type gen = ref<int>
335334336336- let prettyPrintVar = (idx: int, scope: array<string>) =>
337337- "$" ++
338338- switch scope[idx] {
339339- | Some(n) if Array.indexOf(scope, n) == idx => n
340340- | _ => "\\"->String.concat(String.make(idx))
341341- }
342335 let prettyPrint = (term: t, ~scope: array<string>) =>
343336 `"${Array.map(term, piece => {
344337 switch piece {
345338 | String(str) => str
346346- | Var({idx}) => prettyPrintVar(idx, scope)
347347- | Schematic({schematic, allowed}) => {
348348- let allowedStr =
349349- allowed
350350- ->Array.map(idx => prettyPrintVar(idx, scope))
351351- ->Array.join(" ")
352352- `?${Int.toString(schematic)}(${allowedStr})`
353353- }
339339+ | Var({idx}) => Util.prettyPrintVar(idx, scope)
340340+ | Schematic({schematic, allowed}) => Util.prettyPrintSchematic(schematic, allowed, scope)
354341 }
355342 })->Array.join(" ")}"`
356343···468455469456 acc.contents->Result.map(r => (r, str->String.sliceToEnd(~start=pos.contents)))
470457 }
471471-472472- let lowerSchematic = (schematic, allowed) => Some([Schematic({schematic, allowed})])
473473- let lowerVar = idx => Some([Var({idx: idx})])
474458 let concrete = t =>
475459 t->Array.every(p =>
476460 switch p {
···493477 {React.int(props.idx)}
494478 </span>
495479 }
496496-497497- let makeMeta = (str: string) =>
498498- <span className="rule-binder">
499499- {React.string(str)}
500500- {React.string(".")}
501501- </span>
502480503481 let parenthesise = f =>
504482 [
+2-2
src/StringA.resi
···44 | Schematic({schematic: int, allowed: array<int>})
55type t = array<piece>
6677-module Atom: SExpFunc.ATOM with type t = t
88-module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom
77+module Atom: AtomDef.ATOM with type t = t
88+module AtomView: AtomDef.ATOM_VIEW with module Atom := Atom
···11-type t = StringS(StringA.Atom.t) | ConstS(string)
22-33-module Atom: SExpFunc.ATOM with type t = t = {
44- type t = t
55- type subst = Map.t<int, t>
66- type gen = ref<int>
77- let parse = (s, ~scope, ~gen: option<gen>=?) => {
88- StringA.Atom.parse(s, ~scope, ~gen?)
99- ->Result.map(((r, rest)) => (StringS(r), rest))
1010- ->Util.Result.or(() =>
1111- Symbolic.Atom.parse(s, ~scope, ~gen?)->Result.map(((r, rest)) => (ConstS(r), rest))
1212- )
1313- }
1414- let prettyPrint = (s, ~scope) =>
1515- switch s {
1616- | StringS(s) => StringA.Atom.prettyPrint(s, ~scope)
1717- | ConstS(s) => Symbolic.Atom.prettyPrint(s, ~scope)
1818- }
1919- let unify = (s1, s2, ~gen=?) =>
2020- switch (s1, s2) {
2121- | (StringS(s1), StringS(s2)) =>
2222- StringA.Atom.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => StringS(v)))
2323- | (ConstS(s1), ConstS(s2)) =>
2424- Symbolic.Atom.unify(s1, s2, ~gen?)->Seq.map(subst => subst->Util.mapMapValues(v => ConstS(v)))
2525- | (_, _) => Seq.empty
2626- }
2727- let substitute = (s, subst: subst) =>
2828- switch s {
2929- | StringS(s) => {
3030- let stringSubs =
3131- subst
3232- ->Map.entries
3333- ->Iterator.toArrayWithMapper(((i, v)) =>
3434- switch v {
3535- | StringS(s) => Some((i, s))
3636- | _ => None
3737- }
3838- )
3939- ->Array.keepSome
4040- ->Map.fromArray
4141- StringS(StringA.Atom.substitute(s, stringSubs))
4242- }
4343- | ConstS(s) => ConstS(s)
4444- }
4545- let upshift = (s, amount: int, ~from=?) =>
4646- switch s {
4747- | StringS(s) => StringS(s->StringA.Atom.upshift(amount, ~from?))
4848- | ConstS(s) => ConstS(s)
4949- }
5050- let lowerVar = idx => Some(StringS([StringA.Var({idx: idx})]))
5151- let lowerSchematic = (schematic, allowed) => Some(
5252- StringS([StringA.Schematic({schematic, allowed})]),
5353- )
5454- let substDeBruijn = (s, substs: array<option<t>>, ~from=?) =>
5555- switch s {
5656- | StringS(s) => {
5757- let stringSubs = substs->Array.map(s =>
5858- switch s {
5959- | Some(StringS(s)) => Some(s)
6060- | _ => None
6161- }
6262- )
6363- StringS(StringA.Atom.substDeBruijn(s, stringSubs, ~from?))
6464- }
6565- | ConstS(s) => ConstS(s)
6666- }
6767- let concrete = s =>
6868- switch s {
6969- | StringS(s) => StringA.Atom.concrete(s)
7070- | ConstS(_) => false
7171- }
7272-}
7373-7474-module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom = {
7575- type props = {name: Atom.t, scope: array<string>}
7676- let make = ({name, scope}: props) =>
7777- switch name {
7878- | StringS(name) => <StringA.AtomView name scope />
7979- | ConstS(name) => <Symbolic.AtomView name scope />
8080- }
8181-}
-3
src/StringSymbol.resi
···11-type t = StringS(StringA.Atom.t) | ConstS(string)
22-module Atom: SExpFunc.ATOM with type t = t
33-module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom
+2-2
src/Symbolic.res
···11type t = string
22module Atom = {
33+ open AtomDef
34 type t = string
45 type subst = Map.t<int, string>
66+ type atomTag<_> += Tag: atomTag<t>
57 let unify = (a, b, ~gen as _=?) =>
68 if a == b {
79 Seq.once(Map.make())
···1618 | _ => Error("constant symbol parse error")
1719 }
1820 let substitute = (name, _) => name
1919- let lowerVar = _ => None
2020- let lowerSchematic = (_, _) => None
2121 let substDeBruijn = (name, _, ~from as _=?) => name
2222 let concrete = _ => false
2323 let upshift = (t, _, ~from as _=?) => t
+2-2
src/Symbolic.resi
···11type t = string
22-module Atom: SExpFunc.ATOM with type t = t
33-module AtomView: SExpViewFunc.ATOM_VIEW with module Atom := Atom
22+module Atom: AtomDef.ATOM with type t = t
33+module AtomView: AtomDef.ATOM_VIEW with module Atom := Atom