Adding simple block ability to parser
This commit is contained in:
parent
43704743af
commit
0d5de854e3
|
@ -33,6 +33,23 @@ module Form = ReForm.Make(FormConfig);
|
||||||
|
|
||||||
let schema = Form.Validation.Schema([||]);
|
let schema = Form.Validation.Schema([||]);
|
||||||
|
|
||||||
|
module FieldText = {
|
||||||
|
[@react.component]
|
||||||
|
let make = (~field, ~label) => {
|
||||||
|
<Form.Field
|
||||||
|
field
|
||||||
|
render={({handleChange, error, value, validate}) =>
|
||||||
|
<Antd.Form.Item label={label |> R.ste}>
|
||||||
|
<Antd.Input.TextArea
|
||||||
|
value
|
||||||
|
onChange={BsReform.Helpers.handleChange(handleChange)}
|
||||||
|
onBlur={_ => validate()}
|
||||||
|
/>
|
||||||
|
</Antd.Form.Item>
|
||||||
|
}
|
||||||
|
/>;
|
||||||
|
};
|
||||||
|
};
|
||||||
module FieldString = {
|
module FieldString = {
|
||||||
[@react.component]
|
[@react.component]
|
||||||
let make = (~field, ~label) => {
|
let make = (~field, ~label) => {
|
||||||
|
@ -337,7 +354,7 @@ let make = () => {
|
||||||
<Antd.Form onSubmit>
|
<Antd.Form onSubmit>
|
||||||
<Row _type=`flex className=Styles.rows>
|
<Row _type=`flex className=Styles.rows>
|
||||||
<Col span=24>
|
<Col span=24>
|
||||||
<FieldString
|
<FieldText
|
||||||
field=FormConfig.GuesstimatorString
|
field=FormConfig.GuesstimatorString
|
||||||
label="Guesstimator String"
|
label="Guesstimator String"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -6,7 +6,9 @@ module MathJsonToMathJsAdt = {
|
||||||
| Value(float)
|
| Value(float)
|
||||||
| Fn(fn)
|
| Fn(fn)
|
||||||
| Array(array(arg))
|
| Array(array(arg))
|
||||||
|
| Blocks(array(arg))
|
||||||
| Object(Js.Dict.t(arg))
|
| Object(Js.Dict.t(arg))
|
||||||
|
| Assignment(arg,arg)
|
||||||
and fn = {
|
and fn = {
|
||||||
name: string,
|
name: string,
|
||||||
args: array(arg),
|
args: array(arg),
|
||||||
|
@ -42,6 +44,19 @@ module MathJsonToMathJsAdt = {
|
||||||
let items = field("items", array(run), j);
|
let items = field("items", array(run), j);
|
||||||
Some(Array(items |> E.A.O.concatSomes));
|
Some(Array(items |> E.A.O.concatSomes));
|
||||||
| "SymbolNode" => Some(Symbol(field("name", string, j)))
|
| "SymbolNode" => Some(Symbol(field("name", string, j)))
|
||||||
|
| "AssignmentNode" => {
|
||||||
|
let object_ = j |> field("object", run);
|
||||||
|
let value_ = j |> field("value", run);
|
||||||
|
switch(object_, value_){
|
||||||
|
| (Some(o), Some(v)) => Some(Assignment(o,v))
|
||||||
|
| _ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| "BlockNode" => {
|
||||||
|
let block = r => r |> field("node", run);
|
||||||
|
let args = j |> field("blocks", array(block)) |> E.A.O.concatSomes;
|
||||||
|
Some(Blocks(args))
|
||||||
|
}
|
||||||
| n =>
|
| n =>
|
||||||
Js.log3("Couldn't parse mathjs node", j, n);
|
Js.log3("Couldn't parse mathjs node", j, n);
|
||||||
None;
|
None;
|
||||||
|
@ -84,6 +99,8 @@ module MathAdtToDistDst = {
|
||||||
| Array(args) => Array(args |> E.A.fmap(run))
|
| Array(args) => Array(args |> E.A.fmap(run))
|
||||||
| Symbol(s) => Symbol(s)
|
| Symbol(s) => Symbol(s)
|
||||||
| Value(v) => Value(v)
|
| Value(v) => Value(v)
|
||||||
|
| Blocks(args) => Blocks(args |> E.A.fmap(run))
|
||||||
|
| Assignment(a,b) => Assignment(a,run(b))
|
||||||
| Object(v) =>
|
| Object(v) =>
|
||||||
Object(
|
Object(
|
||||||
v
|
v
|
||||||
|
@ -283,13 +300,15 @@ module MathAdtToDistDst = {
|
||||||
Error("This type not currently supported");
|
Error("This type not currently supported");
|
||||||
};
|
};
|
||||||
|
|
||||||
let topLevel = inputVars =>
|
let rec topLevel = inputVars =>
|
||||||
fun
|
fun
|
||||||
| Value(_) as r => nodeParser(inputVars, r)
|
| Value(_) as r => nodeParser(inputVars, r)
|
||||||
| Fn(_) as r => nodeParser(inputVars, r)
|
| Fn(_) as r => nodeParser(inputVars, r)
|
||||||
| Array(_) => Error("Array not valid as top level")
|
| Array(_) => Error("Array not valid as top level")
|
||||||
| Symbol(s) => handleSymbol(inputVars, s)
|
| Symbol(s) => handleSymbol(inputVars, s)
|
||||||
| Object(_) => Error("Object not valid as top level");
|
| Object(_) => Error("Object not valid as top level")
|
||||||
|
| Assignment(_) => Error("Assignment not valid as top level")
|
||||||
|
| Blocks(blocks) => E.A.last(blocks) |> E.O.toResult("no blocks listed") |> E.R.bind(_, topLevel(inputVars))
|
||||||
|
|
||||||
let run =
|
let run =
|
||||||
(inputVars, r): result(ExpressionTypes.ExpressionTree.node, string) =>
|
(inputVars, r): result(ExpressionTypes.ExpressionTree.node, string) =>
|
||||||
|
@ -313,6 +332,7 @@ let fromString2 = (inputVars: inputVars, str) => {
|
||||||
Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered.
|
Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered.
|
||||||
*/
|
*/
|
||||||
let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath;
|
let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath;
|
||||||
|
Js.log2("toJson", mathJsToJson);
|
||||||
let mathJsParse =
|
let mathJsParse =
|
||||||
E.R.bind(mathJsToJson, r => {
|
E.R.bind(mathJsToJson, r => {
|
||||||
switch (MathJsonToMathJsAdt.run(r)) {
|
switch (MathJsonToMathJsAdt.run(r)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user