eval method
dynamic
eval(
- Expression expression,
- Map<
String, dynamic> context, { - void onValueAssigned(
- String key,
- dynamic value
inherited
Implementation
dynamic eval(
Expression expression,
Map<String, dynamic> context, {
void Function(String key, dynamic value)? onValueAssigned,
}) {
dynamic result;
final ctx = Map<String, dynamic>.from(context);
_delegate.forEach((key, value) => ctx.putIfAbsent(key, () => value));
if (expression is Literal) {
result = evalLiteral(expression, ctx);
} else if (expression is Variable) {
result = evalVariable(expression, ctx);
} else if (expression is ThisExpression) {
result = evalThis(expression, ctx);
} else if (expression is MemberExpression) {
result = evalMemberExpression(
expression,
ctx,
nullable: expression.nullable,
);
} else if (expression is IndexExpression) {
result = evalIndexExpression(
expression,
ctx,
nullable: expression.nullable,
);
} else if (expression is CallExpression) {
result = evalCallExpression(expression, ctx);
} else if (expression is UnaryExpression) {
result = evalUnaryExpression(expression, ctx);
} else if (expression is BinaryExpression) {
result = evalBinaryExpression(
expression,
ctx,
onValueAssigned: onValueAssigned,
);
} else if (expression is ConditionalExpression) {
result = evalConditionalExpression(expression, ctx);
} else {
throw ArgumentError(
"Unknown expression type '${expression.runtimeType}'");
}
_logger.finest(
'[eval]: evaluated.... [${expression.toTokenString()}] => [$result]',
);
return result;
}