public void StartOfStringAssertionMidPatternTest(string input, bool expected)
        {
            string pattern = "^(a|^b*|c)$";
            var    target  = NFA.Alternation(NFA.Character('a'), NFA.Sequence(NFA.StartOfStringAssertion(), NFA.ZeroOrMany(NFA.Character('b'))), NFA.Character('c'));

            Test(input, expected, target, pattern);
        }
        public void RepeatedAlternation(string input, bool expected)
        {
            string pattern = "^(foo|bar)*$";
            var    target  = NFA.Sequence(NFA.ZeroOrMany(NFA.Alternation("foo", "bar")), "");

            Test(input, expected, target, pattern);
        }
        public void MultiAlternationNoHelpersTest(string input, bool expected)
        {
            string pattern = "^(a|b|c)$";
            var    target  = NFA.Alternation(NFA.Character('a'), NFA.Character('b'), NFA.Character('c'));

            Test(input, expected, target, pattern);
        }
        public void MultiAlternationTest(string input, bool expected)
        {
            string pattern = "^(a|b|c)$";
            var    target  = NFA.Alternation('a', 'b', 'c');

            Test(input, expected, target, pattern);
        }
        public void AlternationAndRepetitionTest(string input, bool expected)
        {
            string pattern = "^(a|b*|c)$";

            var target = NFA.Alternation(NFA.Character('a'), NFA.Alternation(NFA.ZeroOrMany(NFA.Character('b')), NFA.Character('c')));

            Test(input, expected, target, pattern);
        }
        public void Visit(Choice target)
        {
            target.one.Accept(this);
            var f1 = stack.Pop();

            target.two.Accept(this);
            var f2 = stack.Pop();

            stack.Push(NFA.Alternation(f1, f2));
        }
Example #7
0
        static void Main(string[] args)
        {
            NFA pat = NFA.Sequence(NFA.ZeroOrMany(NFA.Alternation("foo", "bar")), "");

            var strings = new [] {
                "foo", "bar", "foobar", "farboo", "boofar", "barfoo",
                "foofoobarfoo1", "foofoobarfoo"
            };

            Console.WriteLine("PATTERN : {0}", "(foo|bar)*");
            foreach (string s in strings)
            {
                Console.WriteLine(s + "\t:\t" + pat.Matches(s, matchEntireString: true));
            }

            Console.ReadLine();
        }