Exemplo n.º 1
0
        /// <summary>
        /// Parses a literal.
        /// Precondition: lexer is at a literal token type: Boolean, DateTime, Decimal, Null, String, Int64, Integer, Double, Single, Guid, Binary.
        /// </summary>
        /// <returns>The literal query token or null if something else was found.</returns>
        private object TryParseLiteral()
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(ExpressionLexer.IsLiteralType(this.CurrentToken.Kind), "TryParseLiteral called when not at a literal type token");

            switch (this.CurrentToken.Kind)
            {
            case ExpressionTokenKind.BooleanLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetBoolean(false)));

            case ExpressionTokenKind.DateTimeLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetTemporal(EdmPrimitiveTypeKind.DateTime, false)));

            case ExpressionTokenKind.DecimalLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetDecimal(false)));

            case ExpressionTokenKind.NullLiteral:
                return(this.ParseNullLiteral());

            case ExpressionTokenKind.StringLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetString(true)));

            case ExpressionTokenKind.Int64Literal:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetInt64(false)));

            case ExpressionTokenKind.IntegerLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetInt32(false)));

            case ExpressionTokenKind.DoubleLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetDouble(false)));

            case ExpressionTokenKind.SingleLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetSingle(false)));

            case ExpressionTokenKind.GuidLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetGuid(false)));

            case ExpressionTokenKind.BinaryLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetBinary(true)));

            case ExpressionTokenKind.DateTimeOffsetLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetDateTimeOffset(false)));

            case ExpressionTokenKind.TimeLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetTemporal(EdmPrimitiveTypeKind.Time, false)));

            case ExpressionTokenKind.GeographyLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, false)));

            case ExpressionTokenKind.GeometryLiteral:
                return(this.ParseTypedLiteral(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geometry, false)));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>Reads the next token, checks that it is a literal token type, converts to to a Common Language Runtime value as appropriate, and returns the value.</summary>
        /// <returns>The value represented by the next token.</returns>
        internal object ReadLiteralToken()
        {
            DebugUtils.CheckNoExternalCallers();

            this.NextToken();

            if (ExpressionLexer.IsLiteralType(this.CurrentToken.Kind))
            {
                return(this.TryParseLiteral());
            }

            throw new ODataException(o.Strings.ExpressionLexer_ExpectedLiteralToken(this.CurrentToken.Text));
        }