Пример #1
0
 /// <summary>
 /// Visits the compare expression tree
 /// </summary>
 /// <param name="exp"></param>
 public object VisitCompare(CompareExpr exp)
 {
     _callBackOnNodeStart(exp);
     _callBackOnNodeStart(exp.Left);
     _callBackOnNodeStart(exp.Right);
     return null;
 }
Пример #2
0
 /// <summary>
 /// Creates a unary expression with symbol scope, context, script refernce set.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Expr Compare(Expr left, Operator op, Expr right, TokenData token)
 {
     var exp = new CompareExpr();
     exp.Left = left;
     exp.Op = op;
     exp.Right = right;
     SetupContext(exp, token);
     return exp;
 }
Пример #3
0
        /// <summary>
        /// Evaluate > >= != == less less than
        /// </summary>
        /// <returns></returns>
        public static object EvalCompare(CompareExpr expr)
        {
            // Validate
            object result = null;
            var node = expr;
            var op = expr.Op;
            var left = (LObject)expr.Left.Evaluate();
            var right = (LObject)expr.Right.Evaluate();

            // Both double
            if (left.Type == LTypes.Number && right.Type == LTypes.Number)
                result = EvalHelper.CompareNumbers(node, (LNumber)left, (LNumber)right, op);

            // Both strings
            else if (left.Type == LTypes.String && right.Type == LTypes.String)
                result = EvalHelper.CompareStrings(node, (LString)left, (LString)right, op);

            // Both bools
            else if (left.Type == LTypes.Bool && right.Type == LTypes.Bool)
                result = EvalHelper.CompareBools(node, (LBool)left, (LBool)right, op);

            // Both dates
            else if (left.Type == LTypes.Date && right.Type == LTypes.Date)
                result = EvalHelper.CompareDates(node, (LDate)left, (LDate)right, op);

            // Both Timespans
            else if (left.Type == LTypes.Time && right.Type == LTypes.Time)
                result = EvalHelper.CompareTimes(node, (LTime)left, (LTime)right, op);

            // 1 or both null
            else if (left == LObjects.Null || right == LObjects.Null)
                result = EvalHelper.CompareNull(left, right, op);

            // Day of week ?
            else if (left.Type == LTypes.DayOfWeek || right.Type == LTypes.DayOfWeek)
                result = EvalHelper.CompareDays(node, left, right, op);

            // Units
            //else if (left.Type == LTypes.Unit || right.Type == LTypes.Unit)
            else if (left.Type.Name == "LUnit" || right.Type.Name == "LUnit")
                result = EvalHelper.CompareUnits(node, (LUnit)((LClass)left).Value, (LUnit)((LClass)right).Value, op);

            return result;
        }
Пример #4
0
 /// <summary>
 /// Creates a unary expression with symbol scope, context, script refernce set.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public Expr ToCompareExpr(Expr left, Operator op, Expr right, TokenData token)
 {
     var exp = new CompareExpr(left, op, right);
     this.SetupContext(exp, token);
     return exp;
 }