Example #1
0
        public void TestLoopsWithOptimizedOutExitBranches() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : 'x'* ~'x'+ ;\n");
            string expecting =
                ".s0-'x'->:s1=>1\n" +
                ".s0-{'\\u0000'..'w', 'y'..'\\uFFFF'}->:s2=>2\n";

            checkDecision(g, 1, expecting, null);

            // The optimizer yanks out all exit branches from EBNF blocks
            // This is ok because we've already verified there are no problems
            // with the enter/exit decision
            DFAOptimizer optimizer = new DFAOptimizer(g);

            optimizer.Optimize();
            FASerializer serializer = new FASerializer(g);
            DFA          dfa        = g.GetLookaheadDFA(1);
            string       result     = serializer.Serialize(dfa.startState);

            expecting = ".s0-'x'->:s1=>1\n";
            assertEquals(expecting, result);
        }
        public void TestLoopsWithOptimizedOutExitBranches()
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : 'x'* ~'x'+ ;\n" );
            string expecting =
                ".s0-'x'->:s1=>1" + NewLine +
                ".s0-{'\\u0000'..'w', 'y'..'\\uFFFF'}->:s2=>2" + NewLine;
            checkDecision( g, 1, expecting, null );

            // The optimizer yanks out all exit branches from EBNF blocks
            // This is ok because we've already verified there are no problems
            // with the enter/exit decision
            DFAOptimizer optimizer = new DFAOptimizer( g );
            optimizer.Optimize();
            FASerializer serializer = new FASerializer( g );
            DFA dfa = g.GetLookaheadDFA( 1 );
            string result = serializer.Serialize( dfa.StartState );
            expecting = ".s0-'x'->:s1=>1" + NewLine;
            Assert.AreEqual( expecting, result );
        }