예제 #1
0
        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));
        }
예제 #2
0
        public override ArrowExpression ToArrowExpression()
        {
            ArrowExpression arrow = new ArrowExpression(new IdentifierList(itemName), null, null);

            arrow.Expression = predicate;
            return(arrow);
        }
예제 #3
0
        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");
            }
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        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));
        }
예제 #6
0
 internal ArrowComparer2Args(Context context, bool descending, ArrowExpression arrow)
     : base(context, descending, arrow)
 {
 }
예제 #7
0
 internal ArrowComparer(Context context, bool descending, ArrowExpression arrow)
 {
     this.context    = context;
     this.descending = descending;
     this.arrow      = arrow;
 }