コード例 #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
                });
            }
            else if (IsIn(FilterTokenType.Function))
            {
                return(ParseFunctionExpression(firstArgument));
            }

            FilterToken function = Expect(FilterTokenType.Function);

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

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

            return(functionNode);
        }
コード例 #2
0
        private IFilterNode ParsePropertyExpression()
        {
            FilterToken property = Expect(FilterTokenType.Property);

            return(new PropertyNode
            {
                Name = property.Value
            });
        }
コード例 #3
0
        private IFilterNode ParseNull()
        {
            FilterToken stringToken = Expect(FilterTokenType.Null);

            return(new NullNode
            {
                Value = null
            });
        }
コード例 #4
0
        private IFilterNode ParseBoolean()
        {
            FilterToken stringToken = Expect(FilterTokenType.Boolean);

            return(new BooleanNode
            {
                Value = Convert.ToBoolean(stringToken.Value)
            });
        }
コード例 #5
0
        private IFilterNode ParseStringExpression()
        {
            FilterToken stringToken = Expect(FilterTokenType.String);

            return(new StringNode
            {
                Value = stringToken.Value
            });
        }
コード例 #6
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)
            });
        }
コード例 #7
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)
            });
        }
コード例 #8
0
        private FilterToken Expect(FilterTokenType tokenType)
        {
            if (!Is(tokenType))
            {
                throw new FilterParserException("Expected " + tokenType);
            }

            FilterToken token = Peek();

            currentTokenIndex++;
            return(token);
        }
コード例 #9
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);
        }
コード例 #10
0
        private bool IsIn(FilterTokenType tokenType)
        {
            FilterToken token = Peek();

            return(token != null && token.TokenType == tokenType && token.Value.Equals("in", StringComparison.CurrentCultureIgnoreCase));
        }
コード例 #11
0
        private bool Is(FilterTokenType tokenType)
        {
            FilterToken token = Peek();

            return(token != null && token.TokenType == tokenType);
        }
コード例 #12
0
 public static FilterOperator ToFilterOperator(this FilterToken token)
 {
     return(tokenToOperator[token.Value]);
 }