Exemple #1
0
        public IToken NextToken()
        {
            if (_caretToken == null)
            {
                IToken token = _source.NextToken();
                if (token.StopIndex + 1 < _caretOffset)
                {
                    // the caret is after this token; nothing special to do
                }
                else if (token.StartIndex > _caretOffset)
                {
                    // the token is after the caret; no need to include it
                    token       = new CaretToken(_tokenFactorySourcePair, TokenConstants.DefaultChannel, _caretOffset, _caretOffset);
                    _caretToken = token;
                }
                else
                {
                    if (token.StopIndex + 1 == _caretOffset && token.StopIndex >= token.StartIndex)
                    {
                        if (!IsWordToken(token))
                        {
                            // the caret is at the end of this token, and this isn't a word token or a zero-length token
                            return(token);
                        }
                    }

                    // the caret is in the middle of or at the end of this token
                    token       = new CaretToken(token);
                    _caretToken = token;
                }

                return(token);
            }

            throw new InvalidOperationException("Attempted to look past the caret.");
        }
        public IToken NextToken()
        {
            if (_caretToken == null)
            {
                IToken token = _source.NextToken();
                if (token.StopIndex + 1 < _caretOffset)
                {
                    // the caret is after this token; nothing special to do
                }
                else if (token.StartIndex > _caretOffset)
                {
                    // the token is after the caret; no need to include it
                    token = new CaretToken(_tokenFactorySourcePair, TokenConstants.DefaultChannel, _caretOffset, _caretOffset);
                    _caretToken = token;
                }
                else
                {
                    if (token.StopIndex + 1 == _caretOffset && token.StopIndex >= token.StartIndex)
                    {
                        if (!IsWordToken(token))
                        {
                            // the caret is at the end of this token, and this isn't a word token or a zero-length token
                            return token;
                        }
                    }

                    // the caret is in the middle of or at the end of this token
                    token = new CaretToken(token);
                    _caretToken = token;
                }

                return token;
            }

            throw new InvalidOperationException("Attempted to look past the caret.");
        }