eval method

dynamic eval(
  1. Expression expression,
  2. Map<String, dynamic> context, {
  3. void onValueAssigned(
    1. String key,
    2. 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;
}