示例#1
0
        private bool ProcessIdentifier(IList <Token> tokens)
        {
            FileLocation location = GetCurrentLocation();
            int          next;

            while ((next = Peek()) != -1)
            {
                char nextChar = (char)next;

                if (!IsValidIdentifierCharacter(nextChar))
                {
                    // Token is finished. Determine whether it is a reserved keyword or a normal identifier.
                    string    value = _valueBuffer.ToString();
                    TokenType type;

                    if (Keyword.IsKeyword(value))
                    {
                        type = TokenType.Keyword;
                    }
                    else
                    {
                        type = TokenType.Identifier;
                    }

                    // All done!
                    _valueBuffer.Length = 0;
                    tokens.Add(new Token(type, value, location));
                    return(true);
                }

                _valueBuffer.Append(nextChar);
                Consume();
            }

            // Incomplete.
            return(false);
        }