Add evaluate partial for back compatibility

This commit is contained in:
Umur Ozkul 2022-04-29 19:03:58 +02:00
parent 351381339c
commit 3bbc5e7149
3 changed files with 19 additions and 0 deletions

View File

@ -11,4 +11,5 @@ type expressionValue = ReducerInterface_ExpressionValue.expressionValue
type externalBindings = ReducerInterface_ExpressionValue.externalBindings type externalBindings = ReducerInterface_ExpressionValue.externalBindings
let evaluate = Expression.evaluate let evaluate = Expression.evaluate
let evaluateUsingOptions = Expression.evaluateUsingOptions let evaluateUsingOptions = Expression.evaluateUsingOptions
let evaluatePartialUsingExternalBindings = Expression.evaluatePartialUsingExternalBindings
let parse = Expression.parse let parse = Expression.parse

View File

@ -21,6 +21,12 @@ let evaluateUsingOptions: (
string, string,
) => result<expressionValue, errorValue> ) => result<expressionValue, errorValue>
@genType @genType
let evaluatePartialUsingExternalBindings: (
string,
QuriSquiggleLang.ReducerInterface_ExpressionValue.externalBindings,
QuriSquiggleLang.ReducerInterface_ExpressionValue.environment,
) => result<externalBindings, errorValue>
@genType
let evaluate: string => result<expressionValue, errorValue> let evaluate: string => result<expressionValue, errorValue>
let parse: string => result<Expression.expression, errorValue> let parse: string => result<Expression.expression, errorValue>

View File

@ -114,3 +114,15 @@ let evaluate = (code: string): result<expressionValue, errorValue> => {
evaluateUsingOptions(~environment=None, ~externalBindings=None, code) evaluateUsingOptions(~environment=None, ~externalBindings=None, code)
} }
let eval = evaluate let eval = evaluate
let evaluatePartialUsingExternalBindings = (
code: string,
externalBindings: ReducerInterface_ExpressionValue.externalBindings,
environment: ReducerInterface_ExpressionValue.environment,
): result<externalBindings, errorValue> => {
let rAnswer = evaluateUsingOptions(~environment=Some(environment), ~externalBindings=Some(externalBindings), code)
switch rAnswer {
| Ok(EvRecord(externalBindings)) => Ok(externalBindings)
| Ok(_) => Error(Reducer_ErrorValue.RESyntaxError(`Partials must end with an assignment or record`))
| Error(err) => err->Error
}
}