Example #1
0
        /// <summary>
        /// Gets the next token.
        /// </summary>
        /// <param name="item">The <see cref="LexicalItem"/> that will contain the next token, if any.</param>
        /// <returns>true if a next token was found; false otherwise.</returns>
        public bool GetToken(out LexicalItem item)
        {
            LexicalItem nextItem = NextItem();

            if (nextItem == null)
            {
                item = null;
                return(false);
            }

            item = nextItem;
            _tokenCollection.Append(item.Token);
            return(true);
        }
Example #2
0
        private LexicalItem NextItem()
        {
            LexicalItem item = null;
            char?       character;

            while ((character = _reader.Read()).HasValue)
            {
                if (character == CarriageReturnChar)
                {
                    _currentPosition.Line++;
                    _currentPosition.Column = 1;
                    continue;
                }

                if (character == LineFeedChar)
                {
                    character = _reader.Read().Value;

                    if (character == CarriageReturnChar)
                    {
                        _currentPosition.Line++;
                        _currentPosition.Column = 1;
                    }

                    continue;
                }

                if (character == CommentStart)
                {
                    ConsumeComment();
                    continue;
                }

                if (character == SpaceChar || character == TabChar)
                {
                    ConsumeCharacter(character.Value);
                    continue;
                }

                item = BuildItem();
                break;
            }

            return(item);
        }
Example #3
0
        /// <summary>
        /// Gets the next token.
        /// </summary>
        /// <param name="item">The <see cref="LexicalItem"/> that will contain the next token, if any.</param>
        /// <returns>true if a next token was found; false otherwise.</returns>
        public bool GetToken(out LexicalItem item)
        {
            LexicalItem nextItem = NextItem();

            if (nextItem == null)
            {
                item = null;
                return false;
            }

            item = nextItem;
            _tokenCollection.Append(item.Token);
            return true;
        }
        private void NextToken()
        {
            LexicalItem item = new LexicalItem();

            if (!_lexical.GetToken(out item))
            {
                RaiseUnexpectedEndOfFileMessage();
            }

            if (item.Error != null)
            {
                RaiseGeneralErrorMessage(item.Error.Message);
            }

            _token = item.Token;
        }