public override IValue interpret(Context context) { IType sourceType = source.check(context); if (!(sourceType is IterableType)) { throw new InternalError("Illegal source type: " + sourceType.GetTypeName()); } IType itemType = ((IterableType)sourceType).GetItemType(); IValue value = source.interpret(context); if (value == null) { throw new NullReferenceError(); } if (!(value is IFilterable)) { throw new InternalError("Illegal fetch source: " + source); } IFilterable list = (IFilterable)value; ArrowExpression arrow = predicate.ToArrowExpression(); Predicate <IValue> filter = arrow.GetFilter(context, itemType); return(list.Filter(filter)); }
public override ArrowExpression ToArrowExpression() { ArrowExpression arrow = new ArrowExpression(new IdentifierList(itemName), null, null); arrow.Expression = predicate; return(arrow); }
private IType checkPredicate(Context context) { IType lt = left.check(context); if (lt is IterableType) { IType itemType = ((IterableType)lt).GetItemType(); ArrowExpression arrow = ((PredicateExpression)right).ToArrowExpression(); return(arrow.CheckFilter(context, itemType)); } else { throw new SyntaxError("Expecting collection"); } }
IValue interpretPredicate(Context context) { IValue lval = left.interpret(context); if (lval is IContainer) { IType itemType = ((ContainerType)lval.GetIType()).GetItemType(); ArrowExpression arrow = ((PredicateExpression)right).ToArrowExpression(); Predicate <IValue> predicate = arrow.GetFilter(context, itemType); return(interpretPredicate(context, (IContainer)lval, predicate)); } else { throw new SyntaxError("Expecting collection"); } }
public override IType check(Context context) { IType sourceType = source.check(context); if (!(sourceType is IterableType)) { throw new SyntaxError("Expecting an iterable type as data source!"); } IType itemType = ((IterableType)sourceType).GetItemType(); ArrowExpression arrow = predicate.ToArrowExpression(); IType filterType = arrow.CheckFilter(context, itemType); if (filterType != BooleanType.Instance) { throw new SyntaxError("Filtering expresion must return a bool!"); } return(new ListType(itemType)); }
internal ArrowComparer2Args(Context context, bool descending, ArrowExpression arrow) : base(context, descending, arrow) { }
internal ArrowComparer(Context context, bool descending, ArrowExpression arrow) { this.context = context; this.descending = descending; this.arrow = arrow; }