evaluateExpr method

EvaluateOutput evaluateExpr(
  1. EvaluateInput input
)

Implementation

EvaluateOutput evaluateExpr(EvaluateInput input) {
  try {
    config.beforeEvaluate(input);
  } catch (e) {
    return EvaluateOutput(
      status: EvaluateOutput_Status.UNKNOWN_ERROR,
      errorPath: input.expr.path,
      errorMessage: 'beforeEvaluate failed: ${e.toString()}',
    );
  }

  late EvaluateOutput output;
  switch (input.expr.kind) {
    case Expr_Kind.EVAL:
      output = evaluateEval(input);
    case Expr_Kind.SCALAR:
      output = evaluateScalar(input);
    case Expr_Kind.REF:
      output = evaluateRef(input);
    case Expr_Kind.OBJ:
      output = evaluateObj(input);
    case Expr_Kind.ARR:
      output = evaluateArr(input);
    case Expr_Kind.JSON:
      output = evaluateJson(input);
    case Expr_Kind.ITER:
      output = evaluateIter(input);
    case Expr_Kind.ELEM:
      output = evaluateElem(input);
    case Expr_Kind.CALL:
      output = evaluateCall(input);
    case Expr_Kind.CASES:
      output = evaluateCases(input);
    case Expr_Kind.OP_UNARY:
      output = evaluateOpUnary(input);
    case Expr_Kind.OP_BINARY:
      output = evaluateOpBinary(input);
    case Expr_Kind.OP_VARIADIC:
      output = evaluateOpVariadic(input);
    default:
      throw ArgumentError('given expression must be validated');
  }

  try {
    config.afterEvaluate(input, output);
  } catch (e) {
    return EvaluateOutput(
      status: EvaluateOutput_Status.UNKNOWN_ERROR,
      errorPath: input.expr.path,
      errorMessage: 'afterEvaluate failed: ${e.toString()}',
    );
  }

  return output;
}