public ParseTreeValue(TypeTokenPair valuePair)
        {
            _typeTokenPair         = valuePair;
            ParsesToConstantValue  = false;
            _exceedsValueTypeRange = null;
            _hashCode            = valuePair.Token.GetHashCode();
            _dateValue           = null;
            _stringConstant      = null;
            IsMismatchExpression = false;

            if (valuePair.ValueType.Equals(Tokens.Date))
            {
                ParsesToConstantValue = LetCoerce.TryCoerce(_typeTokenPair.Token, out _dateValue);
            }
            else if (valuePair.ValueType.Equals(Tokens.String) && IsStringConstant(valuePair.Token))
            {
                _stringConstant       = new StringLiteralExpression(new ConstantExpression(new StringValue(_typeTokenPair.Token)));
                ParsesToConstantValue = true;
            }
            else if (valuePair.ValueType.Equals(Tokens.String) &&
                     TryGetNonPrintingControlCharCompareToken(valuePair.Token, out _))
            {
                ParsesToConstantValue = true;
            }
        }
Exemple #2
0
 private static bool TryParseAsDateLiteral(string valueString, out ComparableDateValue value)
 {
     value = default;
     if (IsDateLiteral(valueString))
     {
         return(LetCoerce.TryCoerce(valueString, out value));
     }
     return(false);
 }
Exemple #3
0
        private static TypeTokenPair ConformTokenToDate(string valueToken, bool allowOverflow = false)
        {
            var goalValueType = Tokens.Date;

            if (LetCoerce.TryCoerce(valueToken, out ComparableDateValue dvComparable))
            {
                return(new TypeTokenPair(goalValueType, dvComparable.AsDateLiteral()));
            }
            return(new TypeTokenPair(goalValueType, null));
        }
Exemple #4
0
        private static TypeTokenPair ConformTokenToBoolean(string valueToken, bool allowOverflow = false)
        {
            var goalValueType = Tokens.Boolean;

            if (LetCoerce.TryCoerce(valueToken, out bool newVal))
            {
                return(new TypeTokenPair(goalValueType, newVal.ToString(CultureInfo.InvariantCulture)));
            }
            return(new TypeTokenPair(goalValueType, null));
        }
Exemple #5
0
        private static TypeTokenPair ConformTokenToLongLong(string valueToken, bool allowOverflow = false)
        {
            var goalValueType = Tokens.LongLong;

            if (LetCoerce.TryCoerce(valueToken, out long newVal) ||
                TryParseAsHexLiteral(valueToken, out newVal) ||
                TryParseAsOctalLiteral(valueToken, out newVal))
            {
                return(new TypeTokenPair(goalValueType, newVal.ToString(CultureInfo.InvariantCulture)));
            }

            return(new TypeTokenPair(goalValueType, null));
        }
Exemple #6
0
        private static TypeTokenPair ConformTokenToCurrency(string valueToken, bool allowOverflow = true)
        {
            var goalValueType = Tokens.Currency;

            if (LetCoerce.TryCoerce(valueToken, out decimal newVal))
            {
                return(new TypeTokenPair(goalValueType, newVal.ToString(CultureInfo.InvariantCulture)));
            }

            if (allowOverflow && LetCoerce.TryCoerce(valueToken, out double overflowValue))
            {
                return(new TypeTokenPair(goalValueType, overflowValue.ToString(CultureInfo.InvariantCulture)));
            }
            return(new TypeTokenPair(goalValueType, null));
        }
Exemple #7
0
        private static TypeTokenPair ConformTokenToByte(string valueToken, bool allowOverflow = true)
        {
            var goalValueType = Tokens.Byte;

            if (LetCoerce.TryCoerce(valueToken, out byte newVal))
            {
                return(new TypeTokenPair(goalValueType, newVal.ToString(CultureInfo.InvariantCulture)));
            }

            if (allowOverflow && LetCoerce.TryCoerce(valueToken, out long overflowValue))
            {
                return(new TypeTokenPair(goalValueType, overflowValue.ToString(CultureInfo.InvariantCulture)));
            }
            return(new TypeTokenPair(goalValueType, null));
        }
Exemple #8
0
        private static TypeTokenPair ConformTokenToInteger(string valueToken, bool allowOverflow = true)
        {
            var goalValueType = Tokens.Integer;

            if (LetCoerce.TryCoerce(valueToken, out short newVal) ||
                TryParseAsHexLiteral(valueToken, out newVal) ||
                TryParseAsOctalLiteral(valueToken, out newVal))
            {
                return(new TypeTokenPair(goalValueType, newVal.ToString(CultureInfo.InvariantCulture)));
            }

            if (allowOverflow && LetCoerce.TryCoerce(valueToken, out long overflowValue))
            {
                return(new TypeTokenPair(goalValueType, overflowValue.ToString(CultureInfo.InvariantCulture)));
            }

            return(new TypeTokenPair(goalValueType, null));
        }