Ejemplo n.º 1
0
        private void NextTokenForValue()
        {
            var start = _position;

            switch (_c)
            {
            case '\n':
                _token = new SyntaxTokenValue(TokenKind.NewLine, start, _position);
                NextChar();
                break;

            case '\r':
                NextChar();
                // case of: \r\n
                if (_c == '\n')
                {
                    _token = new SyntaxTokenValue(TokenKind.NewLine, start, _position);
                    NextChar();
                    break;
                }
                // case of \r
                _token = new SyntaxTokenValue(TokenKind.NewLine, start, start);
                break;

            case '#':
                NextChar();
                ReadComment(start);
                break;

            case ',':
                _token = new SyntaxTokenValue(TokenKind.Comma, start, start);
                NextChar();
                break;

            case '[':
                NextChar();
                _token = new SyntaxTokenValue(TokenKind.OpenBracket, start, start);
                break;

            case ']':
                NextChar();
                _token = new SyntaxTokenValue(TokenKind.CloseBracket, start, start);
                break;

            case '{':
                _token = new SyntaxTokenValue(TokenKind.OpenBrace, _position, _position);
                NextChar();
                break;

            case '}':
                _token = new SyntaxTokenValue(TokenKind.CloseBrace, _position, _position);
                NextChar();
                break;

            case '"':
                ReadString(start, true);
                break;

            case '\'':
                ReadStringLiteral(start, true);
                break;

            case Eof:
                _token = new SyntaxTokenValue(TokenKind.Eof, _position, _position);
                break;

            default:
                // Eat any whitespace
                if (ConsumeWhitespace())
                {
                    break;
                }

                // Handle inf, +inf, -inf, true, false
                if (_c == '+' || _c == '-' || CharHelper.IsIdentifierStart(_c))
                {
                    ReadSpecialToken();
                    break;
                }

                if (CharHelper.IsDigit(_c))
                {
                    ReadNumberOrDate();
                    break;
                }

                // invalid char
                _token = new SyntaxTokenValue(TokenKind.Invalid, _position, _position);
                NextChar();
                break;
            }
        }