open Component module Term = HOTerm module Judgment = HOTerm module Ports = Ports(Term, Judgment) type state = {grammar: MixfixGrammar.grammar, compiled: MixfixGrammar.compiled} type props = { content: state, imports: Ports.t, onChange: (state, ~exports: Ports.t=?) => unit, reset: unit => unit, } let serialise = (s, ~imports as _: Ports.t) => MixfixGrammar.prettyPrintGrammar(s.grammar) let deserialise = (input: string, ~imports as _: Ports.t) => switch MixfixGrammar.parseDecls(String.trim(input)) { | Ok((grammar, "")) => switch MixfixGrammar.compile(grammar) { | Ok(compiled) => Ok(({grammar, compiled}, {Ports.facts: Dict.make(), ruleStyle: None, grammar: compiled})) | Error(s) => Error(s) } | Error(s) => Error(s) | Ok((_, s)) => Error("Unable to read from: " ++ s) } module AssocBadge = { @react.component let make = (~assoc: MixfixGrammar.assoc) => { let (label, cls) = switch assoc { | Left => ("infixl", "assoc-left") | Right => ("infixr", "assoc-right") | NonAssoc => ("infix", "assoc-none") } {React.string(label)} } } module OpRow = { @react.component let make = (~op: MixfixGrammar.opDecl) =>
{React.string(op.category)}
} module TighterRow = { @react.component let make = (~tighter: string, ~looser: string) =>
{React.string(tighter)} {React.string("binds tighter than")} {React.string(looser)}
} let make = props => { let {grammar} = props.content
{if Array.length(grammar.ops) == 0 { React.null } else {
{React.string("Operators")}
{grammar.ops->Array.mapWithIndex((op, i) => )->React.array}
}} {if Array.length(grammar.tighterThan) == 0 { React.null } else {
{React.string("Precedence")}
{grammar.tighterThan ->Array.mapWithIndex(((tighter, looser), i) => ) ->React.array}
}} {if Array.length(grammar.ops) == 0 && Array.length(grammar.tighterThan) == 0 {
{React.string("No declarations")}
} else { React.null }}
}