eval partial tested
This commit is contained in:
parent
4826337a6a
commit
a02bc27852
|
@ -32,7 +32,7 @@ describe("Parse for Bindings", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
Only.describe("Eval with Bindings", () => {
|
describe("Eval with Bindings", () => {
|
||||||
testEvalBindingsToBe(
|
testEvalBindingsToBe(
|
||||||
"x",
|
"x",
|
||||||
list{("x", ExpressionValue.EvNumber(1.))},
|
list{("x", ExpressionValue.EvNumber(1.))},
|
||||||
|
@ -50,11 +50,12 @@ Only.describe("Eval with Bindings", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Eval Partial", () => {
|
Only.describe("Eval Partial", () => {
|
||||||
testEvalPartialBindingsToBe(
|
MyOnly.testEvalPartialBindingsToBe(
|
||||||
|
// A partial cannot end with an expression
|
||||||
"x",
|
"x",
|
||||||
list{("x", ExpressionValue.EvNumber(1.))},
|
list{("x", ExpressionValue.EvNumber(1.))},
|
||||||
"????",
|
"Error(Assignment expected)",
|
||||||
)
|
)
|
||||||
testEvalPartialBindingsToBe(
|
testEvalPartialBindingsToBe(
|
||||||
"y=x",
|
"y=x",
|
||||||
|
|
|
@ -59,6 +59,28 @@ let dispatchMacroCall = (list: list<expression>, bindings: ExpressionT.bindings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let doExportVariableExpression = (bindings: ExpressionT.bindings) => {
|
||||||
|
let emptyDictionary: Js.Dict.t<ExpressionValue.expressionValue> = Js.Dict.empty()
|
||||||
|
let reducedBindings = bindings->Belt.Map.String.keep (
|
||||||
|
(key, value) =>
|
||||||
|
switch value {
|
||||||
|
| ExpressionT.EValue(_) => true
|
||||||
|
| _ => false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
let externalBindings = reducedBindings->Belt.Map.String.reduce(
|
||||||
|
emptyDictionary,
|
||||||
|
(acc, key, expressionValue) => {
|
||||||
|
let value = switch expressionValue {
|
||||||
|
| EValue(aValue) => aValue
|
||||||
|
| _ => EvSymbol("internal")
|
||||||
|
}
|
||||||
|
Js.Dict.set(acc, key, value); acc
|
||||||
|
}
|
||||||
|
)
|
||||||
|
externalBindings->EvRecord->ExpressionT.EValue->Ok
|
||||||
|
}
|
||||||
|
|
||||||
switch list {
|
switch list {
|
||||||
| list{ExpressionT.EValue(EvCall("$$bindings"))} => bindings->ExpressionT.EBindings->Ok
|
| list{ExpressionT.EValue(EvCall("$$bindings"))} => bindings->ExpressionT.EBindings->Ok
|
||||||
|
|
||||||
|
@ -68,6 +90,11 @@ let dispatchMacroCall = (list: list<expression>, bindings: ExpressionT.bindings)
|
||||||
statement,
|
statement,
|
||||||
} =>
|
} =>
|
||||||
doBindStatement(statement, bindings)
|
doBindStatement(statement, bindings)
|
||||||
|
| list{
|
||||||
|
ExpressionT.EValue(EvCall("$$bindExpression")),
|
||||||
|
ExpressionT.EBindings(bindings),
|
||||||
|
ExpressionT.EList(list{EValue(EvCall("$exportVariableExpression")), ..._}),
|
||||||
|
} => doExportVariableExpression(bindings)
|
||||||
| list{
|
| list{
|
||||||
ExpressionT.EValue(EvCall("$$bindExpression")),
|
ExpressionT.EValue(EvCall("$$bindExpression")),
|
||||||
ExpressionT.EBindings(bindings),
|
ExpressionT.EBindings(bindings),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user