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); }
private IFilterNode ParsePropertyExpression() { FilterToken property = Expect(FilterTokenType.Property); return(new PropertyNode { Name = property.Value }); }
private IFilterNode ParseBoolean() { FilterToken stringToken = Expect(FilterTokenType.Boolean); return(new BooleanNode { Value = Convert.ToBoolean(stringToken.Value) }); }
private IFilterNode ParseStringExpression() { FilterToken stringToken = Expect(FilterTokenType.String); return(new StringNode { Value = stringToken.Value }); }
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) }); }
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) }); }
private FilterToken Expect(FilterTokenType tokenType) { if (!Is(tokenType)) { throw new FilterParserException("Expected " + tokenType); } FilterToken token = Peek(); currentTokenIndex++; return(token); }
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); }
private bool Is(FilterTokenType tokenType) { FilterToken token = Peek(); return(token != null && token.TokenType == tokenType); }
private bool Is(FilterTokenType tokenType) { FilterToken token = Peek(); return(token != null && !token.Value.Equals("null") && token.TokenType == tokenType); }