module type ATOM_VIEW = AtomDef.ATOM_VIEW module Make = ( Atom: AtomDef.ATOM, AtomView: ATOM_VIEW with module Atom := Atom, SExp: module type of SExp.Make(Atom), ): { include Signatures.TERM_VIEW with module Term := SExp } => { type props = {term: SExp.t, scope: array} open Util type idx_props = {idx: int, scope: array} let viewVar = (props: idx_props) => switch props.scope[props.idx] { | Some(n) if Array.indexOf(props.scope, n) == props.idx => {React.string(n)} | _ => {React.string("\\")} {React.int(props.idx)} } let makeMeta = (str: string) => {React.string(str)} {React.string(".")} let parenthesise = f => [ {React.string("(")} , ...f, {React.string(")")} , ] let intersperse = a => a->Array.flatMapWithIndex((e, i) => if i == 0 { [e] } else { [React.string(" "), e] } ) module Inner = { @react.component let rec make = (~term: SExp.t, ~scope: array, ~parens: bool=true) => switch term { | Compound({subexps: bits}) => {bits ->Array.mapWithIndex((t, i) => Int.toString}> {React.createElement(React.component(make), {term: t, scope, parens: true})} ) ->intersperse ->(a => if parens { parenthesise(a) } else { a }) ->React.array} | Var({idx}) => viewVar({idx, scope}) | Atom(atom) => | Schematic({schematic: s, allowed: vs}) => {React.string("?")} {React.int(s)} {vs ->Array.mapWithIndex((v, i) => React.createElement(React.component(viewVar), withKey({idx: v, scope}, i)) ) ->intersperse ->parenthesise ->React.array} } } @react.componentWithProps let make = ({term, scope}) => }