Exemplo n.º 1
0
        private IFilterNode ParseComparisonExpression(IFilterNode firstArgument)
        {
            if (Is(FilterTokenType.ComparisonOperator))
            {
                FilterToken comparison = Expect(FilterTokenType.ComparisonOperator);

                IFilterNode secondArgument = PrimaryExpression();

                return(new ComparisonNode
                {
                    First = firstArgument,
                    FilterOperator = comparison.ToFilterOperator(),
                    Second = secondArgument
                });
            }

            FilterToken function = Expect(FilterTokenType.Function);

            var functionNode = new FunctionNode
            {
                FilterOperator = function.ToFilterOperator()
            };

            functionNode.Arguments.Add(firstArgument);
            functionNode.Arguments.Add(PrimaryExpression());

            return(functionNode);
        }
Exemplo n.º 2
0
        private IFilterNode ParsePropertyExpression()
        {
            FilterToken property = Expect(FilterTokenType.Property);

            return(new PropertyNode
            {
                Name = property.Value
            });
        }
Exemplo n.º 3
0
        private IFilterNode ParseBoolean()
        {
            FilterToken stringToken = Expect(FilterTokenType.Boolean);

            return(new BooleanNode
            {
                Value = Convert.ToBoolean(stringToken.Value)
            });
        }
Exemplo n.º 4
0
        private IFilterNode ParseStringExpression()
        {
            FilterToken stringToken = Expect(FilterTokenType.String);

            return(new StringNode
            {
                Value = stringToken.Value
            });
        }
Exemplo n.º 5
0
        private IFilterNode ParseNumberExpression()
        {
            FilterToken number = Expect(FilterTokenType.Number);

            return(new NumberNode
            {
                // Always expect the decimal separator to be "." no matter what the current culture is
                Value = Convert.ToDouble(number.Value, CultureInfo.InvariantCulture)
            });
        }
Exemplo n.º 6
0
        private IFilterNode ParseDateTimeExpression()
        {
            FilterToken dateTime = Expect(FilterTokenType.DateTime);

            return(new DateTimeNode
            {
                //The actual XSD date format is yyyy-MM-ddTHH:mm:ss but ":" generates BAD REQUEST HTTP code when send via GET.
                //That's why we are using yyyy-MM-ddThh-mm-ss
                Value = DateTime.ParseExact(dateTime.Value, "yyyy-MM-ddTHH-mm-ss", null)
            });
        }
Exemplo n.º 7
0
        private FilterToken Expect(FilterTokenType tokenType)
        {
            if (!Is(tokenType))
            {
                throw new FilterParserException("Expected " + tokenType);
            }

            FilterToken token = Peek();

            currentTokenIndex++;
            return(token);
        }
Exemplo n.º 8
0
        private IFilterNode ParseFunctionExpression()
        {
            FilterToken function = Expect(FilterTokenType.Function);

            var functionNode = new FunctionNode
            {
                FilterOperator = function.ToFilterOperator()
            };

            Expect(FilterTokenType.LeftParenthesis);

            functionNode.Arguments.Add(Expression());

            while (Is(FilterTokenType.Comma))
            {
                Expect(FilterTokenType.Comma);
                functionNode.Arguments.Add(Expression());
            }

            Expect(FilterTokenType.RightParenthesis);

            return(functionNode);
        }
Exemplo n.º 9
0
        private bool Is(FilterTokenType tokenType)
        {
            FilterToken token = Peek();

            return(token != null && token.TokenType == tokenType);
        }