private void Handle() { var c = _context.FormulaChars[_tokenIndex]; Token tokenSeparator; if (CharIsTokenSeparator(c, out tokenSeparator)) { if (TokenSeparatorHandler.Handle(c, tokenSeparator, _context, this)) { return; } if (_context.CurrentTokenHasValue) { if (Regex.IsMatch(_context.CurrentToken, "^\"*$")) { _context.AddToken(_tokenFactory.Create(_context.CurrentToken, TokenType.StringContent)); } else { _context.AddToken(CreateToken(_context, Worksheet)); } //If the a next token is an opening parantheses and the previous token is interpeted as an address or name, then the currenct token is a function if (tokenSeparator.TokenType == TokenType.OpeningParenthesis && (_context.LastToken.TokenType == TokenType.ExcelAddress || _context.LastToken.TokenType == TokenType.NameValue)) { _context.LastToken.TokenType = TokenType.Function; } } if (tokenSeparator.Value == "-") { if (TokenIsNegator(_context)) { _context.AddToken(new Token("-", TokenType.Negator)); return; } } _context.AddToken(tokenSeparator); _context.NewToken(); return; } _context.AppendToCurrentToken(c); }
private void Handle() { var c = _context.FormulaChars[_tokenIndex]; if (this.CharIsTokenSeparator(c, out var tokenSeparator)) { if (TokenSeparatorHandler.Handle(c, tokenSeparator, _context, this)) { return; } if (_context.CurrentTokenHasValue) { if (Regex.IsMatch(_context.CurrentToken, "^\"*$")) { _context.AddToken(_tokenFactory.Create(_context.CurrentToken, TokenType.StringContent)); } else { _context.AddToken(CreateToken(_context, this.Worksheet)); } //If the a next token is an opening parantheses and the previous token is interpeted as an address or name, then the currenct token is a function if (tokenSeparator.TokenType == TokenType.OpeningParenthesis && (_context.LastToken.TokenType == TokenType.ExcelAddress || _context.LastToken.TokenType == TokenType.NameValue)) { _context.LastToken.TokenType = TokenType.Function; } } if (tokenSeparator.Value == "-") { if (TokenIsNegator(_context)) { _context.AddToken(new Token("-", TokenType.Negator)); return; } } _context.AddToken(tokenSeparator); _context.NewToken(); return; } else if (c == '#' && !_context.CurrentTokenHasValue && !_context.IsInSheetName && !_context.IsInString) { do { _context.AppendToCurrentToken(c); _tokenIndex++; if (_tokenIndex > _context.FormulaChars.Length - 1) { break; } c = _context.FormulaChars[_tokenIndex]; }while (!ExcelErrorValue.Values.TryGetErrorType(_context.CurrentToken, out _)); _tokenIndex--; if (this.CharIsTokenSeparator(c, out _) || _tokenIndex == _context.FormulaChars.Length - 1) { ExcelErrorValue.Values.TryGetErrorType(_context.CurrentToken, out eErrorType errorType); switch (errorType) { case eErrorType.Div0: _context.AddToken(new Token(_context.CurrentToken, TokenType.DivideByZeroError)); break; case eErrorType.NA: _context.AddToken(new Token(_context.CurrentToken, TokenType.NotApplicableError)); break; case eErrorType.Name: _context.AddToken(new Token(_context.CurrentToken, TokenType.NameError)); break; case eErrorType.Null: _context.AddToken(new Token(_context.CurrentToken, TokenType.Null)); break; case eErrorType.Num: _context.AddToken(new Token(_context.CurrentToken, TokenType.NumericError)); break; case eErrorType.Ref: // Let #REF! errors be handled in the TokenFactory. return; case eErrorType.Value: _context.AddToken(new Token(_context.CurrentToken, TokenType.ValueDataTypeError)); break; } _context.NewToken(); } return; } _context.AppendToCurrentToken(c); }