diff --git a/package.json b/package.json index ae56105..bcd82c8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "preview": "vite preview", "res:build": "rescript", "res:clean": "rescript clean", - "res:dev": "rescript -w" + "res:dev": "rescript -w", + "res:format": "rescript format -all" }, "dependencies": { "@rescript/react": "^0.13.1", diff --git a/src/AxiomSet.res b/src/AxiomSet.res index f4f8410..d52933d 100644 --- a/src/AxiomSet.res +++ b/src/AxiomSet.res @@ -1,68 +1,83 @@ open Signatures open Component module Make = ( - Term : TERM, - Judgment : JUDGMENT with module Term := Term, - JudgmentView : JUDGMENT_VIEW with module Term := Term and module Judgment := Judgment) => { - module Rule = Rule.Make(Term,Judgment) - module RuleView = RuleView.Make(Term,Judgment,JudgmentView) - module Ports = Ports(Term,Judgment) - type props = { content: string, imports: Ports.t, onLoad: (~exports:Ports.t,~string:string=?) => (), onChange: (string,~exports:Ports.t) => () } - + Term: TERM, + Judgment: JUDGMENT with module Term := Term, + JudgmentView: JUDGMENT_VIEW with module Term := Term and module Judgment := Judgment, +) => { + module Rule = Rule.Make(Term, Judgment) + module RuleView = RuleView.Make(Term, Judgment, JudgmentView) + module Ports = Ports(Term, Judgment) + type props = { + content: string, + imports: Ports.t, + onLoad: (~exports: Ports.t, ~string: string=?) => unit, + onChange: (string, ~exports: Ports.t) => unit, + } + let deserialise = (str: string) => { let cur = ref(str) let go = ref(true) - let results = Dict.make() + let results = Dict.make() let ret = ref(Error("impossible")) while go.contents { - switch Rule.parseTopLevel(cur.contents,~scope=[]) { - | Ok((t,n),rest) => { - if n->String.trim == "" { + switch Rule.parseTopLevel(cur.contents, ~scope=[]) { + | Ok((t, n), rest) => if n->String.trim == "" { + go := false + ret := Error("Rule given with no name") + } else { + Dict.set(results, n, t) + if rest->String.trim == "" { go := false - ret := Error("Rule given with no name") - } else { - Dict.set(results,n,t) - if rest->String.trim == "" { - go := false - ret := Ok(results) - } else { - cur := rest - } + ret := Ok(results) + } else { + cur := rest } } - | Error(e) => { go := false; ret := Error(e) } + | Error(e) => { + go := false + ret := Error(e) + } } } ret.contents } - - let make = (props ) => { + + let make = props => { switch deserialise(props.content) { | Ok(s) => { React.useEffect(() => { - // Run effects - props.onLoad(~exports= {Ports.facts: s, ruleStyle: None}); + // Run effects + props.onLoad(~exports={Ports.facts: s, ruleStyle: None}) None // or Some(() => {}) }, []) - -
String.concat(String.make(props.imports.ruleStyle->Option.getOr(Hybrid)))}> - { Dict.toArray(s)->Array.mapWithIndex(((n,r), i) => - Option.getOr(Hybrid)}> - {React.string(n)} - // Error("BLAH!")} /> - ) - ->React.array - } + +
String.concat( + String.make(props.imports.ruleStyle->Option.getOr(Hybrid)), + )}> + {Dict.toArray(s) + ->Array.mapWithIndex(((n, r), i) => + Option.getOr(Hybrid)}> + {React.string(n)} + // Error("BLAH!")} /> + + ) + ->React.array}
} | Error(e) => { - React.useEffect(() => { - // Run effects - props.onLoad(~exports= {Ports.facts: Dict.make(), ruleStyle: None}); - None // or Some(() => {}) - }, []) -
{React.string(e)}
+ React.useEffect(() => { + // Run effects + props.onLoad(~exports={Ports.facts: Dict.make(), ruleStyle: None}) + None // or Some(() => {}) + }, []) +
{React.string(e)}
} } } -} \ No newline at end of file +} diff --git a/src/Component.res b/src/Component.res index 56dd6cf..a847d75 100644 --- a/src/Component.res +++ b/src/Component.res @@ -1,21 +1,26 @@ open Signatures module type PORTS = { type t - let combine : (t,t) => t + let combine: (t, t) => t let empty: t } -module Ports = (Term : TERM, Judgment : JUDGMENT with module Term := Term) => { +module Ports = (Term: TERM, Judgment: JUDGMENT with module Term := Term) => { module Rule = Rule.Make(Term, Judgment) - type t = { facts: Dict.t, ruleStyle: option } - let empty = { facts: Dict.make(), ruleStyle: None } - let combine = (p1,p2) => { - let facts = Dict.copy(p1.facts)->Dict.assign(p2.facts); - let ruleStyle = p2.ruleStyle->Option.mapOr(p1.ruleStyle, x => Some(x)); - { facts, ruleStyle } + type t = {facts: Dict.t, ruleStyle: option} + let empty = {facts: Dict.make(), ruleStyle: None} + let combine = (p1, p2) => { + let facts = Dict.copy(p1.facts)->Dict.assign(p2.facts) + let ruleStyle = p2.ruleStyle->Option.mapOr(p1.ruleStyle, x => Some(x)) + {facts, ruleStyle} } } module type COMPONENT = { - module Ports : PORTS - type props = { content: string, imports: Ports.t, onLoad: (~exports:Ports.t, ~string:string=?) => (),onChange: (string,~exports:Ports.t) => () } - let make : props => React.element + module Ports: PORTS + type props = { + content: string, + imports: Ports.t, + onLoad: (~exports: Ports.t, ~string: string=?) => unit, + onChange: (string, ~exports: Ports.t) => unit, + } + let make: props => React.element } diff --git a/src/ConfigBlock.res b/src/ConfigBlock.res index 2e2b0f4..6be9d6b 100644 --- a/src/ConfigBlock.res +++ b/src/ConfigBlock.res @@ -1,37 +1,48 @@ open Signatures open Component -module Make = ( - Term : TERM, - Judgment : JUDGMENT with module Term := Term -) => { - module Ports = Ports(Term,Judgment) +module Make = (Term: TERM, Judgment: JUDGMENT with module Term := Term) => { + module Ports = Ports(Term, Judgment) open RuleView - type props = { content: string, imports: Ports.t, onLoad: (~exports:Ports.t) => (), onChange: (string,~exports:Ports.t) => () } - let deserialise = (str) => switch str { - | "Gentzen" => Gentzen - | "Linear" => Linear - | "Hybrid" => Hybrid - | _ => Hybrid + type props = { + content: string, + imports: Ports.t, + onLoad: (~exports: Ports.t) => unit, + onChange: (string, ~exports: Ports.t) => unit, } - let make = (props) => { - let (style,setStyle) = React.useState (_=>deserialise(props.content)) + let deserialise = str => + switch str { + | "Gentzen" => Gentzen + | "Linear" => Linear + | "Hybrid" => Hybrid + | _ => Hybrid + } + let make = props => { + let (style, setStyle) = React.useState(_ => deserialise(props.content)) React.useEffect(() => { - props.onLoad(~exports={Ports.facts: Dict.make(), ruleStyle:Some(style)}) + props.onLoad(~exports={Ports.facts: Dict.make(), ruleStyle: Some(style)}) None - },[]) - let onChange= (e) => { + }, []) + let onChange = e => { let target = JsxEvent.Form.target(e) let value: string = target["value"] let sty = deserialise(value) setStyle(_ => sty) - - props.onChange(value,~exports={Ports.facts: Dict.make(), ruleStyle:Some(sty)}) + + props.onChange(value, ~exports={Ports.facts: Dict.make(), ruleStyle: Some(sty)}) } - [Gentzen,Linear,Hybrid]->Array.map(n => - String.concat(String.make(n))} key={String.make(n)} name="style" onChange value={String.make(n)} checked={style==n}/> - )->React.array - + [Gentzen, Linear, Hybrid] + ->Array.map(n => + String.concat(String.make(n))} + key={String.make(n)} + name="style" + onChange + value={String.make(n)} + checked={style == n} + /> + ) + ->React.array } } - diff --git a/src/Editable.res b/src/Editable.res index a6f304a..82c6afd 100644 --- a/src/Editable.res +++ b/src/Editable.res @@ -1,44 +1,53 @@ open Component -module TextArea = (Underlying : COMPONENT) => { +module TextArea = (Underlying: COMPONENT) => { module Ports = Underlying.Ports - type props = { content: string, imports: Ports.t, onLoad: (~exports:Ports.t, ~string:string=?) => (), onChange: (string,~exports:Ports.t) => () } - let make = (props) => { - let (editing,setEditing) = React.useState (_ => false) - let (text,setText) = React.useState (_ => props.content) - let onTextChange= (ev: JsxEvent.Form.t) => { + type props = { + content: string, + imports: Ports.t, + onLoad: (~exports: Ports.t, ~string: string=?) => unit, + onChange: (string, ~exports: Ports.t) => unit, + } + let make = props => { + let (editing, setEditing) = React.useState(_ => false) + let (text, setText) = React.useState(_ => props.content) + let onTextChange = (ev: JsxEvent.Form.t) => { let target = JsxEvent.Form.target(ev) let value: string = target["value"] setText(_ => value) } - let done = (_) => { - setEditing(_=>false) + let done = _ => { + setEditing(_ => false) } if editing {