Example #1
0
        static void _RunMatch()
        {
            var test = "foo123_ _bar";

            var word = CharFA <string> .Repeat(
                CharFA <string> .Set(new CharRange[] { new CharRange('A', 'Z'), new CharRange('a', 'z') }),
                1, -1
                , "Word");

            var         dfaWord      = word.ToDfa();
            var         dfaTableWord = word.ToDfaStateTable();
            CharFAMatch match;
            var         pc = ParseContext.Create(test);

            Console.WriteLine("Matching words with an NFA:");
            while (null != (match = word.Match(pc)))
            {
                Console.WriteLine("Found match at {0}: {1}", match.Position, match.Value);
            }
            Console.WriteLine();
            pc = ParseContext.Create(test);
            Console.WriteLine("Matching words with a DFA:");
            while (null != (match = dfaWord.MatchDfa(pc)))
            {
                Console.WriteLine("Found match at {0}: {1}", match.Position, match.Value);
            }
            Console.WriteLine();
            pc = ParseContext.Create(test);
            Console.WriteLine("Matching words with a DFA state table:");
            while (null != (match = CharFA <string> .MatchDfa(dfaTableWord, pc)))
            {
                Console.WriteLine("Found match at {0}: {1}", match.Position, match.Value);
            }
            Console.WriteLine();
            pc = ParseContext.Create(test);
            Console.WriteLine("Matching words with a compiled DFA:");
            while (null != (match = Match(pc)))
            {
                Console.WriteLine("Found match at {0}: {1}", match.Position, match.Value);
            }
            Console.WriteLine();
        }