Expr.fromJson constructor

Expr.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory Expr.fromJson(Map<String, Object?> json) {
  if (json.keys.length != 1) {
    throw FormatException('Expected exactly one key in JSON expression');
  }
  final MapEntry(:key, :value) = json.entries.first;
  final op = Op.fromJson(key);
  return switch (op) {
    OpBuiltin.value => ExprValue.fromJson(value),
    OpBuiltin.variable => ExprVariable.fromJson(value as String),
    OpBuiltin.slot => ExprSlot.fromJson(value as String),
    OpBuiltin.unknown => ExprUnknown.fromJson(value as Map<String, Object?>),
    OpBuiltin.not => ExprNot.fromJson(value as Map<String, Object?>),
    OpBuiltin.negate => ExprNegate.fromJson(value as Map<String, Object?>),
    OpBuiltin.equals => ExprEquals.fromJson(value as Map<String, Object?>),
    OpBuiltin.notEquals =>
      ExprNotEquals.fromJson(value as Map<String, Object?>),
    OpBuiltin.in_ => ExprIn.fromJson(value as Map<String, Object?>),
    OpBuiltin.lessThan =>
      ExprLessThan.fromJson(value as Map<String, Object?>),
    OpBuiltin.lessThanOrEquals =>
      ExprLessThanOrEquals.fromJson(value as Map<String, Object?>),
    OpBuiltin.greaterThan =>
      ExprGreaterThan.fromJson(value as Map<String, Object?>),
    OpBuiltin.greaterThanOrEquals =>
      ExprGreaterThanOrEquals.fromJson(value as Map<String, Object?>),
    OpBuiltin.and => ExprAnd.fromJson(value as Map<String, Object?>),
    OpBuiltin.or => ExprOr.fromJson(value as Map<String, Object?>),
    OpBuiltin.add => ExprAdd.fromJson(value as Map<String, Object?>),
    OpBuiltin.subtract => ExprSubt.fromJson(value as Map<String, Object?>),
    OpBuiltin.multiply => ExprMult.fromJson(value as Map<String, Object?>),
    OpBuiltin.contains =>
      ExprContains.fromJson(value as Map<String, Object?>),
    OpBuiltin.containsAll =>
      ExprContainsAll.fromJson(value as Map<String, Object?>),
    OpBuiltin.containsAny =>
      ExprContainsAny.fromJson(value as Map<String, Object?>),
    OpBuiltin.getAttribute =>
      ExprGetAttribute.fromJson(value as Map<String, Object?>),
    OpBuiltin.hasAttribute =>
      ExprHasAttribute.fromJson(value as Map<String, Object?>),
    OpBuiltin.like => ExprLike.fromJson(value as Map<String, Object?>),
    OpBuiltin.is_ => ExprIs.fromJson(value as Map<String, Object?>),
    OpBuiltin.ifThenElse =>
      ExprIfThenElse.fromJson(value as Map<String, Object?>),
    OpBuiltin.set => ExprSet.fromJson(value as List<Object?>),
    OpBuiltin.record => ExprRecord.fromJson(value as Map<String, Object?>),
    final OpExtension op => ExprExtensionCall(
        fn: op.name,
        args: (value as List<Object?>)
            .map((el) => Expr.fromJson(el as Map<String, Object?>))
            .toList(),
      ),
  };
}