reducer semantics ternary (tested)
This commit is contained in:
parent
4d801c0b10
commit
c810c4576d
|
@ -1,9 +1,9 @@
|
|||
open Jest
|
||||
open Reducer_TestHelpers
|
||||
|
||||
Skip.describe("Parse ternary operator", () => {
|
||||
testParseToBe("true ? 'YES' : 'NO'", "Ok('YES')")
|
||||
testParseToBe("false ? 'YES' : 'NO'", "Ok('NO')")
|
||||
describe("Parse ternary operator", () => {
|
||||
testParseToBe("true ? 'YES' : 'NO'", "Ok((:$$ternary true 'YES' 'NO'))")
|
||||
testParseToBe("2>1 ? 'YES' : 'NO'", "Ok((:$$ternary (:larger 2 1) 'YES' 'NO'))")
|
||||
})
|
||||
|
||||
Skip.describe("Evaluate ternary operator", () => {
|
||||
|
|
|
@ -116,6 +116,19 @@ let rec fromNode = (mathJsNode: Parse.node): result<expression, errorValue> =>
|
|||
rExpr
|
||||
}
|
||||
| MjBlockNode(bNode) => bNode["blocks"]->Belt.Array.map(toTagOrNode)->caseTagOrNodes
|
||||
| MjConditionalNode(cndNode) => {
|
||||
let rCondition = fromNode(cndNode["condition"])
|
||||
let rTrueExpr = fromNode(cndNode["trueExpr"])
|
||||
let rFalse = fromNode(cndNode["falseExpr"])
|
||||
|
||||
rCondition->Result.flatMap(condition =>
|
||||
rTrueExpr->Result.flatMap(trueExpr =>
|
||||
rFalse->Result.flatMap(falseExpr =>
|
||||
Builder.passToFunction("$$ternary", list{condition, trueExpr, falseExpr})->Ok
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
| MjConstantNode(cNode) =>
|
||||
cNode["value"]->JavaScript.Gate.jsToEv->Result.flatMap(v => v->ExpressionT.EValue->Ok)
|
||||
| MjFunctionAssignmentNode(faNode) => caseFunctionAssignmentNode(faNode)
|
||||
|
|
Loading…
Reference in New Issue
Block a user