Exemplo n.º 1
0
        /// <summary>
        /// Run the parser on a list of tokens.
        /// </summary>
        /// <param name="tokenTypes">The type of tokens to pass to the parser.</param>
        private static bool RunParser(params TokenType[] tokenTypes)
        {
            // Fake the column number of the token so the parser
            // can at least specify which token caused the error.
            int column = 0;

            // Construct the token list.
            List<Token> tokens = new List<Token>();
            foreach (TokenType type in tokenTypes)
            {
                tokens.Add(new Token(type, 0, column++));
            }

            // Run the parser.
            Parser parser = new Parser();
            bool result = parser.Parse(tokens);

            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run the parser on a list of tokens.
        /// </summary>
        /// <param name="expect">The expected result of the parse.</param>
        /// <param name="tokenTypes">The type of tokens to pass to the parser.</param>
        private void RunParser(bool expect, params TokenType[] tokenTypes)
        {
            // Fake the column number of the token so the parser
            // can at least specify which token caused the error.
            int column = 0;

            // Construct the token list.
            List<Token> tokens = new List<Token>();
            foreach (TokenType type in tokenTypes)
            {
                tokens.Add(new Token(type, 0, column++));
            }

            // Run the parser.
            Parser parser = new Parser();
            bool result = parser.Parse(tokens);

            // Check the result.
            Assert.AreEqual(result, expect);
        }