Ejemplo n.º 1
0
        public void explicitly_casting_a_parser_to_a_BNF_wraps_that_parser()
        {
            Parser parser = new LiteralCharacter(';');
            var subject = (BNF)parser;

            var result = subject.Result();

            Assert.That(result, Is.InstanceOf<LiteralCharacter>());
        }
Ejemplo n.º 2
0
        public void casting_a_parser_to_a_BNF_wraps_that_parser()
        {
            Parser parser = new LiteralCharacter('?');
            BNF subject = parser; //must be class, can't cast interfaces :-(

            var result = subject.Result();

            Assert.That(result, Is.InstanceOf<LiteralCharacter>());
        }
Ejemplo n.º 3
0
        public void a_recursive_parser_pattern()
        {
            // Build a parser for patterns of nested square brackets
            subject = Recursion.Over(recursive =>
            {
                var left = new LiteralCharacter('[');
                var right = new LiteralCharacter(']');

                var mrec = new Repetition(recursive, 0, int.MaxValue);
                var lrec = new Sequence(left, mrec);
                var lr = new Sequence(lrec, right);

                return lr;
            });

            valid_recursive = new ScanStrings("[[[][]]]");
            valid_simple = new ScanStrings("[]");
            invalid_recursive = new ScanStrings("[[[][[[]]]"); // unbalanced
            invalid_simple = new ScanStrings("hello, world");
        }
Ejemplo n.º 4
0
 public void semicolon_delimited_list()
 {
     alpha = new RegularExpression("[a-zA-Z]+");
     semi = new LiteralCharacter(';');
     subject = new DelimitedList(alpha, semi);
 }