Example #1
0
        public void TheConstructorShouldSetValue()
        {
            // Arrange
            var token = new Token("foo", TokenType.Identifier, 0);

            // Act
            var error = new UnexpectedTokenError(token);

            // Assert
            Assert.Equal(token.Value, error.Value);
        }
Example #2
0
        /// <summary>
        /// Raises an error on an unexepcted token
        /// </summary>
        /// <param name="stem">The size of the generation's stem</param>
        private void OnUnexpectedToken(int stem)
        {
            // build the list of expected terminals
            List <Symbol> expected = new List <Symbol>();
            GSSGeneration genData  = gss.GetGeneration();

            for (int i = 0; i != genData.Count; i++)
            {
                LRExpected expectedOnHead = parserAutomaton.GetExpected(gss.GetRepresentedState(i + genData.Start), lexer.Terminals);
                // register the terminals for shift actions
                foreach (Symbol terminal in expectedOnHead.Shifts)
                {
                    if (!expected.Contains(terminal))
                    {
                        expected.Add(terminal);
                    }
                }
                if (i < stem)
                {
                    // the state was in the stem, also look for reductions
                    foreach (Symbol terminal in expectedOnHead.Reductions)
                    {
                        if (!expected.Contains(terminal) && CheckIsExpected(i + genData.Start, terminal))
                        {
                            expected.Add(terminal);
                        }
                    }
                }
            }
            // register the error
            UnexpectedTokenError error = new UnexpectedTokenError(lexer.tokens[nextToken.Index], new ROList <Symbol>(expected));

            allErrors.Add(error);
#if !NETSTANDARD1_0
            if (ModeDebug)
            {
                Console.WriteLine("==== RNGLR parsing error:");
                Console.Write("\t");
                Console.WriteLine(error);
                TextContext context = lexer.Input.GetContext(error.Position);
                Console.Write("\t");
                Console.WriteLine(context.Content);
                Console.Write("\t");
                Console.WriteLine(context.Pointer);
                gss.Print();
            }
#endif
        }