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); } }
private IFilterNode ParseDateTimeExpression() { FilterToken filterToken = Expect(FilterTokenType.DateTime); return(new DateTimeNode { Value = DateTime.ParseExact(filterToken.Value, "yyyy-MM-ddTHH-mm-ss", null) }); }
private IFilterNode ParsePropertyExpression() { FilterToken filterToken = Expect(FilterTokenType.Property); return(new PropertyNode { Name = filterToken.Value }); }
private IFilterNode ParseNumberExpression() { FilterToken filterToken = Expect(FilterTokenType.Number); return(new NumberNode { Value = Convert.ToDouble(filterToken.Value, CultureInfo.InvariantCulture) }); }
private IFilterNode ParseBoolean() { FilterToken filterToken = Expect(FilterTokenType.Boolean); return(new BooleanNode { Value = Convert.ToBoolean(filterToken.Value) }); }
private IFilterNode ParseStringExpression() { FilterToken filterToken = Expect(FilterTokenType.String); return(new StringNode { Value = filterToken.Value }); }
private bool Is(FilterTokenType tokenType) { FilterToken filterToken = Peek(); if (filterToken != null) { return(filterToken.TokenType == tokenType); } return(false); }
private FilterToken Expect(FilterTokenType tokenType) { if (!Is(tokenType)) { throw new FilterParserException("Expected " + tokenType); } FilterToken filterToken = Peek(); ++currentTokenIndex; return(filterToken); }
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]); }