/// <summary>
        /// Parse compute expression text into a token.
        /// </summary>
        /// <returns>The lexical token representing the compute expression text.</returns>
        internal ComputeExpressionToken ParseComputeExpression()
        {
            // expression
            QueryToken expression = this.ParseExpression();

            // "as" alias
            StringLiteralToken alias = this.ParseAggregateAs();

            return(new ComputeExpressionToken(expression, alias.Text));
        }
        private StringLiteralToken ParseAggregateAs()
        {
            if (!TokenIdentifierIs(ExpressionConstants.KeywordAs))
            {
                throw ParseError(ODataErrorStrings.UriQueryExpressionParser_AsExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText));
            }

            lexer.NextToken();

            var alias = new StringLiteralToken(lexer.CurrentToken.Text);

            lexer.NextToken();

            return(alias);
        }
Ejemplo n.º 3
0
        internal AggregateTokenBase ParseAggregateExpression()
        {
            try
            {
                this.parseAggregateExpresionDepth++;

                // expression
                QueryToken expression = ParseLogicalOr();

                if (this.lexer.CurrentToken.Kind == ExpressionTokenKind.OpenParen)
                {
                    // When there's a parenthesis after the expression we have a entity set aggregation.
                    // The syntax is the same as the aggregate expression itself, so we recurse on ParseAggregateExpressions.
                    this.aggregateExpressionParents.Push(expression);
                    List <AggregateTokenBase> statements = ParseAggregateExpressions();
                    this.aggregateExpressionParents.Pop();

                    return(new EntitySetAggregateToken(expression, statements));
                }

                AggregationMethodDefinition verb;

                // "with" verb
                EndPathToken endPathExpression = expression as EndPathToken;
                if (endPathExpression != null && endPathExpression.Identifier == ExpressionConstants.QueryOptionCount)
                {
                    // e.g. aggregate($count as Count)
                    verb = AggregationMethodDefinition.VirtualPropertyCount;
                }
                else
                {
                    // e.g. aggregate(UnitPrice with sum as Total)
                    verb = this.ParseAggregateWith();
                }

                // "as" alias
                StringLiteralToken alias = this.ParseAggregateAs();

                return(new AggregateExpressionToken(expression, verb, alias.Text));
            }
            finally
            {
                this.parseAggregateExpresionDepth--;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the primary expressions.
        /// </summary>
        /// <returns>The lexical token representing the expression.</returns>
        private QueryToken ParsePrimary()
        {
            QueryToken expr = null;

            this.RecurseEnter();

            switch (this.lexer.CurrentToken.Kind)
            {
            case ExpressionTokenKind.OpenParen:
                expr = this.ParseParenExpression();
                break;

            case ExpressionTokenKind.StringLiteral:
                expr = new StringLiteralToken(this.lexer.CurrentToken.Text);
                this.lexer.NextToken();
                break;

            default:
                throw new ODataException(ODataErrorStrings.UriQueryExpressionParser_ExpressionExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText));
            }

            this.RecurseLeave();
            return(expr);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Binds a StringLiteral token.
 /// </summary>
 /// <param name="stringLiteralToken">The StringLiteral token to bind.</param>
 /// <returns>The bound StringLiteral token.</returns>
 protected virtual QueryNode BindStringLiteral(StringLiteralToken stringLiteralToken)
 {
     return(new SearchTermNode(stringLiteralToken.Text));
 }