Jurassic.Compiler.Lexer.ReadPunctuator C# (CSharp) Method

ReadPunctuator() private method

Reads a punctuation token.
private ReadPunctuator ( int firstChar ) : Jurassic.Compiler.Token
firstChar int The first character of the punctuation token.
return Jurassic.Compiler.Token
        private Token ReadPunctuator(int firstChar)
        {
            // The most likely case is the the punctuator is a single character and is followed by a space.
            var punctuator = PunctuatorToken.FromString(new string((char)firstChar, 1));
            if (this.reader.Peek() == ' ')
                return punctuator;

            // Otherwise, read characters until we find a string that is not a punctuator.
            var punctuatorText = new StringBuilder(4);
            punctuatorText.Append((char)firstChar);
            while (true)
            {
                int c = this.reader.Peek();
                if (c == -1)
                    break;

                // Try to parse the text as a punctuator.
                punctuatorText.Append((char)c);
                var longPunctuator = PunctuatorToken.FromString(punctuatorText.ToString());
                if (longPunctuator == null)
                    break;
                punctuator = longPunctuator;

                // Advance the input stream.
                ReadNextChar();
            }
            return punctuator;
        }