Esempio n. 1
0
        /// <summary>
        /// Visit the anyof expression.
        /// </summary>
        /// <param name="expr">AnyOf expression.</param>
        /// <returns></returns>
        public object VisitAnyOf(AnyOfExpr expr)
        {
            var result     = false;
            var leftExpr   = expr.CompareExpr;
            var leftResult = leftExpr.Evaluate(this) as LObject;

            if (expr.ParamListExpressions == null || expr.ParamListExpressions.Count == 0)
            {
                return(new LBool(result));
            }

            // Resolve the parameters.
            ParamHelper.ResolveNonNamedParameters(expr.ParamListExpressions, expr.ParamList, this);

            foreach (var rvalue in expr.ParamList)
            {
                var rightResult   = rvalue as LObject;
                var compareResult = EvalHelper.Compare(expr, Operator.EqualEqual, leftResult, rightResult) as LObject;
                if (compareResult != null && compareResult.Type == LTypes.Bool && ((LBool)compareResult).Value == true)
                {
                    result = true;
                    break;
                }
            }
            return(new LBool(result));
        }
Esempio n. 2
0
        /// <summary>
        /// Evaluate > >= != == less less than
        /// </summary>
        /// <returns></returns>
        public object VisitCompare(CompareExpr expr)
        {
            var node = expr;
            var op   = expr.Op;

            // TODO: This should be here ( find a better solution )
            //  e.g. allow expression to support comparable ??
            if (expr.Right.Nodetype == NodeTypes.SysAnyOf)
            {
                var anyOf = ((AnyOfExpr)expr.Right);
                anyOf.CompareExpr = expr.Left;
                return(this.VisitAnyOf(anyOf));
            }

            var left  = (LObject)expr.Left.Evaluate(this);
            var right = (LObject)expr.Right.Evaluate(this);

            return(EvalHelper.Compare(node, op, left, right));
        }