public override bool Evaluate(RuntimeValues runtimeEnv)
        {
            object leftVal  = left.GetRuntimeValue(runtimeEnv);
            object rightVal = right.GetRuntimeValue(runtimeEnv);

            IComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture);

            int compare;

            if (leftVal is IComparable)
            {
                compare = comparer.Compare(leftVal, rightVal);
            }
            else if (rightVal is IComparable)
            {
                compare = -comparer.Compare(rightVal, leftVal);
            }
            else
            {
                // Only do this if neither version is comparable.
                // The reason is IComparable objects can change the
                // meaning of Equals in surprising ways if necessary,
                // such as for version matching.
                if (opToken == XppTokenType.EQ)
                {
                    return(Equals(leftVal, rightVal));
                }
                if (opToken == XppTokenType.NEQ)
                {
                    return(!Equals(leftVal, rightVal));
                }

                throw new ArgumentException("Can't perform a compare on two objects that don't implement IComparable");
            }

            switch (opToken)
            {
            case XppTokenType.LT:
                return(compare < 0);

            case XppTokenType.LTE:
                return(compare <= 0);

            case XppTokenType.EQ:
                return(compare == 0);

            case XppTokenType.NEQ:
                return(compare != 0);

            case XppTokenType.GT:
                return(compare > 0);

            case XppTokenType.GTE:
                return(compare >= 0);

            default:
                throw new ArgumentException("Program error: Unexpected comparison operator in XppCompareExpr");
            }
        }
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     if (_or)
     {
         return(_left.Evaluate(runtimeEnv) || _right.Evaluate(runtimeEnv));
     }
     else
     {
         return(_left.Evaluate(runtimeEnv) && _right.Evaluate(runtimeEnv));
     }
 }
        public override bool Evaluate(RuntimeValues runtimeEnv)
        {
            Regex  regex;
            object patternObj = pattern.GetRuntimeValue(runtimeEnv);

            if (patternObj is string)
            {
                regex = new Regex((string)patternObj, DEFAULT_REGEX_OPTIONS);
            }
            else if (patternObj is Regex)
            {
                regex = (Regex)patternObj;
            }
            else
            {
                throw new ArgumentException("Right-hand side of regex operator wasn't a string or regex");
            }

            return(not ^ regex.IsMatch(val.GetRuntimeValue(runtimeEnv).ToString()));
        }
 public object GetRuntimeValue(RuntimeValues runtimeEnv)
 {
     if (TokenType == XppTokenType.Identifier)
     {
         return(runtimeEnv.Get(Value));
     }
     else if (TokenType == XppTokenType.StringLiteral)
     {
         return(Value);
     }
     else if (TokenType == XppTokenType.VersionLiteral)
     {
         return(new Version(Value));
     }
     else if (TokenType == XppTokenType.RegexLiteral)
     {
         return(new Regex(Value, XppRegexExpr.DEFAULT_REGEX_OPTIONS));
     }
     else
     {
         throw new ArgumentException("Program error: Cannot get value for something that is not an identifier, string, or version");
     }
 }
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     return(val);
 }
 public bool Evaluate(RuntimeValues runtimeEnv)
 {
     return(Parse().Evaluate(runtimeEnv));
 }
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     return(!expr.Evaluate(runtimeEnv));
 }
 public abstract bool Evaluate(RuntimeValues runtimeEnv);
        public override bool Evaluate(RuntimeValues runtimeEnv)
        {
            object leftVal = left.GetRuntimeValue(runtimeEnv);
            object rightVal = right.GetRuntimeValue(runtimeEnv);

            IComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture);

            int compare;
            if (leftVal is IComparable)
                compare = comparer.Compare(leftVal, rightVal);
            else if (rightVal is IComparable)
                compare = -comparer.Compare(rightVal, leftVal);
            else
            {
                // Only do this if neither version is comparable.
                // The reason is IComparable objects can change the
                // meaning of Equals in surprising ways if necessary,
                // such as for version matching.
                if (opToken == XppTokenType.EQ)
                    return Equals(leftVal, rightVal);
                if (opToken == XppTokenType.NEQ)
                    return !Equals(leftVal, rightVal);

                throw new ArgumentException("Can't perform a compare on two objects that don't implement IComparable");
            }

            switch (opToken)
            {
                case XppTokenType.LT:
                    return compare < 0;
                case XppTokenType.LTE:
                    return compare <= 0;
                case XppTokenType.EQ:
                    return compare == 0;
                case XppTokenType.NEQ:
                    return compare != 0;
                case XppTokenType.GT:
                    return compare > 0;
                case XppTokenType.GTE:
                    return compare >= 0;
                default:
                    throw new ArgumentException("Program error: Unexpected comparison operator in XppCompareExpr");
            }
        }
Пример #10
0
        public override bool Evaluate(RuntimeValues runtimeEnv)
        {
            Regex regex;
            object patternObj = pattern.GetRuntimeValue(runtimeEnv);
            if (patternObj is string)
            {
                regex = new Regex((string)patternObj, DEFAULT_REGEX_OPTIONS);
            }
            else if (patternObj is Regex)
            {
                regex = (Regex)patternObj;
            }
            else
            {
                throw new ArgumentException("Right-hand side of regex operator wasn't a string or regex");
            }

            return not ^ regex.IsMatch(val.GetRuntimeValue(runtimeEnv).ToString());
        }
Пример #11
0
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     return val;
 }
Пример #12
0
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     if (_or)
         return _left.Evaluate(runtimeEnv) || _right.Evaluate(runtimeEnv);
     else
         return _left.Evaluate(runtimeEnv) && _right.Evaluate(runtimeEnv);
 }
Пример #13
0
 public bool Evaluate(RuntimeValues runtimeEnv)
 {
     return Parse().Evaluate(runtimeEnv);
 }
Пример #14
0
 public override bool Evaluate(RuntimeValues runtimeEnv)
 {
     return !expr.Evaluate(runtimeEnv);
 }
Пример #15
0
 public abstract bool Evaluate(RuntimeValues runtimeEnv);
Пример #16
0
 public object GetRuntimeValue(RuntimeValues runtimeEnv)
 {
     if (TokenType == XppTokenType.Identifier)
         return runtimeEnv.Get(Value);
     else if (TokenType == XppTokenType.StringLiteral)
         return Value;
     else if (TokenType == XppTokenType.VersionLiteral)
         return new Version(Value);
     else if (TokenType == XppTokenType.RegexLiteral)
         return new Regex(Value, XppRegexExpr.DEFAULT_REGEX_OPTIONS);
     else
         throw new ArgumentException("Program error: Cannot get value for something that is not an identifier, string, or version");
 }