Exemple #1
0
 private IFilterNode ParseComparisonExpression(IFilterNode firstArgument)
 {
     if (Is(FilterTokenType.ComparisonOperator))
     {
         FilterToken token      = Expect(FilterTokenType.ComparisonOperator);
         IFilterNode filterNode = PrimaryExpression();
         return(new ComparisonNode
         {
             First = firstArgument,
             FilterOperator = token.ToFilterOperator(),
             Second = filterNode
         });
     }
     else
     {
         FilterToken token        = Expect(FilterTokenType.Function);
         var         functionNode = new FunctionNode
         {
             FilterOperator = token.ToFilterOperator()
         };
         functionNode.Arguments.Add(firstArgument);
         functionNode.Arguments.Add(PrimaryExpression());
         return(functionNode);
     }
 }
Exemple #2
0
        private IFilterNode ParseDateTimeExpression()
        {
            FilterToken filterToken = Expect(FilterTokenType.DateTime);

            return(new DateTimeNode
            {
                Value = DateTime.ParseExact(filterToken.Value, "yyyy-MM-ddTHH-mm-ss", null)
            });
        }
Exemple #3
0
        private IFilterNode ParsePropertyExpression()
        {
            FilterToken filterToken = Expect(FilterTokenType.Property);

            return(new PropertyNode
            {
                Name = filterToken.Value
            });
        }
Exemple #4
0
        private IFilterNode ParseNumberExpression()
        {
            FilterToken filterToken = Expect(FilterTokenType.Number);

            return(new NumberNode
            {
                Value = Convert.ToDouble(filterToken.Value, CultureInfo.InvariantCulture)
            });
        }
Exemple #5
0
        private IFilterNode ParseBoolean()
        {
            FilterToken filterToken = Expect(FilterTokenType.Boolean);

            return(new BooleanNode
            {
                Value = Convert.ToBoolean(filterToken.Value)
            });
        }
Exemple #6
0
        private IFilterNode ParseStringExpression()
        {
            FilterToken filterToken = Expect(FilterTokenType.String);

            return(new StringNode
            {
                Value = filterToken.Value
            });
        }
Exemple #7
0
        private bool Is(FilterTokenType tokenType)
        {
            FilterToken filterToken = Peek();

            if (filterToken != null)
            {
                return(filterToken.TokenType == tokenType);
            }
            return(false);
        }
Exemple #8
0
        private FilterToken Expect(FilterTokenType tokenType)
        {
            if (!Is(tokenType))
            {
                throw new FilterParserException("Expected " + tokenType);
            }
            FilterToken filterToken = Peek();

            ++currentTokenIndex;
            return(filterToken);
        }
Exemple #9
0
        private IFilterNode ParseFunctionExpression()
        {
            FilterToken token        = Expect(FilterTokenType.Function);
            var         functionNode = new FunctionNode
            {
                FilterOperator = token.ToFilterOperator()
            };

            Expect(FilterTokenType.LeftParenthesis);
            functionNode.Arguments.Add(Expression());
            while (Is(FilterTokenType.Comma))
            {
                Expect(FilterTokenType.Comma);
                functionNode.Arguments.Add(Expression());
            }
            Expect(FilterTokenType.RightParenthesis);
            return(functionNode);
        }
 public static FilterOperator ToFilterOperator(this FilterToken token)
 {
     return(tokenToOperator[token.Value]);
 }