private void EnsureParenthesesAreWellFormed(Token token, AnalyzingContext context)
 {
     if (token.TokenType == TokenType.OpeningBracket)
     {
         context.NumberOfOpenedParentheses++;
     }
     else if (token.TokenType == TokenType.ClosingBracket)
     {
         context.NumberOfClosedParentheses++;
     }
 }
 private void EnsureStringsAreWellFormed(Token token, AnalyzingContext context)
 {
     if (!context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = true;
         context.OpenedStrings++;
     }
     else if (context.IsInString && token.TokenType == TokenType.String)
     {
         context.IsInString = false;
         context.ClosedStrings++;
     }
 }
 public Expression Create(Token token)
 {
     switch (token.TokenType)
     {
         case TokenType.Integer:
             return new IntegerExpression(token.Value);
         case TokenType.String:
             return new StringExpression(token.Value);
         case TokenType.Decimal:
             return new DecimalExpression(token.Value);
         case TokenType.Boolean:
             return new BooleanExpression(token.Value);
         case TokenType.ExcelAddress:
             return new ExcelAddressExpression(token.Value, _excelDataProvider, _parsingContext);
         case TokenType.NameValue:
             return new NamedValueExpression(token.Value, _parsingContext);
         default:
             return new StringExpression(token.Value);
     }
 }
 public UnrecognizedTokenException(Token token)
     : base("Unrecognized token: " + token.Value)
 {
 }
 private bool CharIsTokenSeparator(char c, out Token token)
 {
     var result = _tokenProvider.Tokens.ContainsKey(c.ToString());
     token = result ? token = _tokenProvider.Tokens[c.ToString()] : null;
     return result;
 }
 private bool IsWaste(Token token)
 {
     if (token.TokenType == TokenType.String)
     {
         return true;
     }
     return false;
 }
 public void AddToken(Token token)
 {
     _result.Add(token);
 }
 private void CreateAndAppendExpression(Expression parent, Token token)
 {
     if (IsWaste(token)) return;
     if (parent != null && token.TokenType == TokenType.Comma)
     {
         parent.PrepareForNextChild();
         return;
     }
     if (_negateNextExpression)
     {
         token.Negate();
         _negateNextExpression = false;
     }
     var expression = _expressionFactory.Create(token);
     if (parent == null)
     {
         _graph.Add(expression);
     }
     else
     {
         parent.AddChild(expression);
     }
 }
 public void ShouldReturnNamedValueExpressionWhenTokenIsNamedValue()
 {
     var token = new Token("NamedValue", TokenType.NameValue);
     var expression = _factory.Create(token);
     Assert.IsInstanceOfType(expression, typeof(NamedValueExpression));
 }
 public void ShouldReturnIntegerExpressionWhenTokenIsInteger()
 {
     var token = new Token("2", TokenType.Integer);
     var expression = _factory.Create(token);
     Assert.IsInstanceOfType(expression, typeof(IntegerExpression));
 }
 public void ShouldReturnExcelRangeExpressionWhenTokenIsExcelAddress()
 {
     var token = new Token("A1", TokenType.ExcelAddress);
     var expression = _factory.Create(token);
     Assert.IsInstanceOfType(expression, typeof(ExcelAddressExpression));
 }
 public void ShouldReturnDecimalExpressionWhenTokenIsDecimal()
 {
     var token = new Token("2.5", TokenType.Decimal);
     var expression = _factory.Create(token);
     Assert.IsInstanceOfType(expression, typeof(DecimalExpression));
 }
 public void ShouldReturnBooleanExpressionWhenTokenIsBoolean()
 {
     var token = new Token("true", TokenType.Boolean);
     var expression = _factory.Create(token);
     Assert.IsInstanceOfType(expression, typeof(BooleanExpression));
 }