Example #1
0
 private void EatRawValue()
 {
     string rawValue = EatNonWhitespace();
     _currentToken = new Token(TokenKind.Value, rawValue, _position);
 }
Example #2
0
 private void EatOption()
 {
     ++_position;
     string option = EatNonWhitespace();
     if (option.Length == 0)
     {
         _currentToken = new Token(TokenKind.Error, "No option name specified", _position);
     }
     else if (option[0] == '-')
     {
         if (option.Length == 1)
         {
             _currentToken = new Token(TokenKind.Error, "No option name specified", _position);
         }
         else
         {
             _currentToken = new Token(TokenKind.LongOption, option.Substring(1), _position);
         }
     }
     else if (option.Length == 1)
     {
         _currentToken = new Token(TokenKind.ShortOption, option, _position);
     }
     else
     {
         _currentToken = new Token(TokenKind.Error, "Short option name must be a single character", _position);
     }
 }
Example #3
0
        private void EatQuotedValue()
        {
            string quotedValue = "";
            ++_position;
            while (!AtEnd && CurrentChar != '"')
            {
                quotedValue += CurrentChar;
                ++_position;
            }
            if (CurrentChar == '"')
                ++_position; // Skip trailing " if we saw it (might be we skipped the loop completely)

            _currentToken = new Token(TokenKind.Value, quotedValue, _position);
        }
Example #4
0
        private void Advance()
        {
            EatWhitespace();

            if (AtEnd)
            {
                _currentToken = null;
                return;
            }

            if (CurrentChar == '"')
            {
                EatQuotedValue();
            }
            else if (CurrentChar == '-')
            {
                if (CanPeek && Char.IsDigit(PeekNextChar))
                {
                    // It's actually a negative number, not an option
                    EatRawValue();
                }
                else
                {
                    EatOption();
                }
            }
            else
            {
                EatRawValue();
            }

            EatWhitespace();
        }