// parses $apply compute expression (.e.g. compute(UnitPrice mul SalesPrice as computePrice)
        internal ComputeToken ParseCompute()
        {
            Debug.Assert(TokenIdentifierIs(ExpressionConstants.KeywordCompute), "token identifier is compute");

            lexer.NextToken();
            // '('
            if (this.lexer.CurrentToken.Kind != ExpressionTokenKind.OpenParen)
            {
                throw ParseError(ODataErrorStrings.UriQueryExpressionParser_OpenParenExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText));
            }
            lexer.NextToken();

            List <ComputeExpressionToken> transformationTokens = new List <ComputeExpressionToken>();

            while (true)
            {
                ComputeExpressionToken computed = this.ParseComputeExpression();
                transformationTokens.Add(computed);
                if (this.lexer.CurrentToken.Kind != ExpressionTokenKind.Comma)
                {
                    break;
                }

                this.lexer.NextToken();
            }

            // ")"
            if (this.lexer.CurrentToken.Kind != ExpressionTokenKind.CloseParen)
            {
                throw ParseError(ODataErrorStrings.UriQueryExpressionParser_CloseParenOrCommaExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText));
            }
            this.lexer.NextToken();

            return(new ComputeToken(transformationTokens));
        }
        // parses $compute query option.
        internal ComputeToken ParseCompute(string compute)
        {
            Debug.Assert(compute != null, "compute != null");

            List <ComputeExpressionToken> transformationTokens = new List <ComputeExpressionToken>();

            if (string.IsNullOrEmpty(compute))
            {
                return(new ComputeToken(transformationTokens));
            }

            this.recursionDepth = 0;
            this.lexer          = CreateLexerForFilterOrOrderByOrApplyExpression(compute);

            while (true)
            {
                ComputeExpressionToken computed = this.ParseComputeExpression();
                transformationTokens.Add(computed);
                if (this.lexer.CurrentToken.Kind != ExpressionTokenKind.Comma)
                {
                    break;
                }

                this.lexer.NextToken();
            }

            this.lexer.ValidateToken(ExpressionTokenKind.End);

            return(new ComputeToken(transformationTokens));
        }
Ejemplo n.º 3
0
        private ComputeExpression BindComputeExpressionToken(ComputeExpressionToken token)
        {
            SingleValueNode   node       = this.bindMethod(token.Expression) as SingleValueNode;
            ComputeExpression expression = new ComputeExpression(node, token.Alias, node.TypeReference);

            return(expression);
        }