Exemple #1
0
        private static Syntax ParseVector(Token thisToken, Tokenizer moreTokens)
        {
            var   listContents = new List <object>();
            Token dotToken     = null;

            var nextToken = moreTokens.ReadToken();

            while (nextToken != null && nextToken.Type != TokenType.CloseBracket)
            {
                // Parse this token
                listContents.Add(ParseToken(nextToken, moreTokens));

                // Fetch the next token
                nextToken = moreTokens.ReadToken();
                if (nextToken == null)
                {
                    throw SchemeError.SyntaxError("parser", "Improperly formed list.", dotToken);
                }

                //if (!improper && nextToken.Type == TokenType.Symbol && dotSymbol.Equals(nextToken.Value) && thisToken.Type == TokenType.OpenBracket)
                if (nextToken.Type == TokenType.Dot)
                {
                    throw SchemeError.SyntaxError("parser", "Improperly formed dotted list", nextToken);
                }
            }

            if (nextToken == null) // Missing ')'
            {
                throw SchemeError.SyntaxError("parser", "Missing close parenthesis", thisToken);
            }

            return(new Syntax(ValueList.FromList(listContents), thisToken));
        }