public (List <Token> tokens, List <Error> errors, List <Warning> warnings) GetTokens() { TokenReader tokenReaderChain = TokenReaderBuilder.BuildChainOfResponsibility(); int line = 0; int currentCharIndex = 0; ReadOnlySpan <char> source = _sourceText.AsSpan(); int sourceLength = source.Length; while (currentCharIndex < sourceLength - 1) { try { TokenReadResult result = tokenReaderChain.HandleRequest(source.Slice(currentCharIndex), line); line += result.LinesTraversed; currentCharIndex += result.CharactersUsed; if (!result.IgnoreToken) { _tokens.Add(result.Token); } } catch (Exception e) { _errors.Add(new Error(line, e.Message)); currentCharIndex++; } } return(_tokens, _errors, _warnings); }