kill mj acronym

This commit is contained in:
Umur Ozkul 2022-03-30 10:22:51 +02:00
parent a9df64230e
commit 9a6522ff29
2 changed files with 11 additions and 11 deletions

View File

@ -47,7 +47,7 @@ let parse = (expr: string): result<node, errorValue> =>
| Js.Exn.Error(obj) => REJs(Js.Exn.message(obj), Js.Exn.name(obj))->Error | Js.Exn.Error(obj) => REJs(Js.Exn.message(obj), Js.Exn.name(obj))->Error
} }
type mjNode = type mathJsNode =
| MjAccessorNode(accessorNode) | MjAccessorNode(accessorNode)
| MjArrayNode(arrayNode) | MjArrayNode(arrayNode)
| MjConstantNode(constantNode) | MjConstantNode(constantNode)
@ -72,7 +72,7 @@ let castNodeType = (node: node) =>
| _ => RETodo(`Argg, unhandled MathJsNode: ${node["type"]}`)->Error | _ => RETodo(`Argg, unhandled MathJsNode: ${node["type"]}`)->Error
} }
let rec show = (mjNode: mjNode): string => { let rec show = (mathJsNode: mathJsNode): string => {
let showValue = (a: 'a): string => let showValue = (a: 'a): string =>
if Js.typeof(a) == "string" { if Js.typeof(a) == "string" {
`'${Js.String.make(a)}'` `'${Js.String.make(a)}'`
@ -103,7 +103,7 @@ let rec show = (mjNode: mjNode): string => {
->Belt.Array.map(each => showResult(each->castNodeType)) ->Belt.Array.map(each => showResult(each->castNodeType))
->Js.String.concatMany("") ->Js.String.concatMany("")
switch mjNode { switch mathJsNode {
| MjAccessorNode(aNode) => `${aNode["object"]->showMathJsNode}[${aNode["index"]->showIndexNode}]` | MjAccessorNode(aNode) => `${aNode["object"]->showMathJsNode}[${aNode["index"]->showIndexNode}]`
| MjArrayNode(aNode) => `[${aNode["items"]->showNodeArray}]` | MjArrayNode(aNode) => `[${aNode["items"]->showNodeArray}]`
| MjConstantNode(cNode) => cNode["value"]->showValue | MjConstantNode(cNode) => cNode["value"]->showValue
@ -115,9 +115,9 @@ let rec show = (mjNode: mjNode): string => {
| MjSymbolNode(sNode) => sNode["name"] | MjSymbolNode(sNode) => sNode["name"]
} }
} }
and showResult = (rmjnode: result<mjNode, errorValue>): string => and showResult = (rMathJsNode: result<mathJsNode, errorValue>): string =>
switch rmjnode { switch rMathJsNode {
| Error(e) => showError(e) | Error(e) => showError(e)
| Ok(mjNode) => show(mjNode) | Ok(mathJsNode) => show(mathJsNode)
} }
and showMathJsNode = node => node->castNodeType->showResult and showMathJsNode = node => node->castNodeType->showResult

View File

@ -9,8 +9,8 @@ type expression = ExtressionT.expression
type expressionValue = ExpressionValue.expressionValue type expressionValue = ExpressionValue.expressionValue
type errorValue = ErrorValue.errorValue type errorValue = ErrorValue.errorValue
let rec fromNode = (mjnode: Parse.node): result<expression, errorValue> => let rec fromNode = (mathJsNode: Parse.node): result<expression, errorValue> =>
Parse.castNodeType(mjnode)->Result.flatMap(typedMjNode => { Parse.castNodeType(mathJsNode)->Result.flatMap(typedMathJsNode => {
let fromNodeList = (nodeList: list<Parse.node>): result<list<expression>, 'e> => let fromNodeList = (nodeList: list<Parse.node>): result<list<expression>, 'e> =>
Belt.List.reduceReverse(nodeList, Ok(list{}), (racc, currNode) => Belt.List.reduceReverse(nodeList, Ok(list{}), (racc, currNode) =>
racc->Result.flatMap(acc => racc->Result.flatMap(acc =>
@ -52,9 +52,9 @@ let rec fromNode = (mjnode: Parse.node): result<expression, errorValue> =>
let rpropertyCodeList = Belt.List.reduceReverse( let rpropertyCodeList = Belt.List.reduceReverse(
iNode["dimensions"]->Belt.List.fromArray, iNode["dimensions"]->Belt.List.fromArray,
Ok(list{}), Ok(list{}),
(racc, currentPropertyMjNode) => (racc, currentPropertyMathJsNode) =>
racc->Result.flatMap(acc => racc->Result.flatMap(acc =>
fromNode(currentPropertyMjNode)->Result.map(propertyCode => list{propertyCode, ...acc}) fromNode(currentPropertyMathJsNode)->Result.map(propertyCode => list{propertyCode, ...acc})
), ),
) )
rpropertyCodeList->Result.map(propertyCodeList => ExtressionT.EList(propertyCodeList)) rpropertyCodeList->Result.map(propertyCodeList => ExtressionT.EList(propertyCodeList))
@ -70,7 +70,7 @@ let rec fromNode = (mjnode: Parse.node): result<expression, errorValue> =>
}) })
} }
switch typedMjNode { switch typedMathJsNode {
| MjArrayNode(aNode) => | MjArrayNode(aNode) =>
aNode["items"]->Belt.List.fromArray->fromNodeList->Result.map(list => ExtressionT.EList(list)) aNode["items"]->Belt.List.fromArray->fromNodeList->Result.map(list => ExtressionT.EList(list))
| MjConstantNode(cNode) => | MjConstantNode(cNode) =>