Beispiel #1
0
        public void ManyTillTest()
        {
            Combinator.ManyTill(
                Parser.Fail <Char, Char>("Failure"),
                Parser.Fail <Char, Unit>("Failure"))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => { /* OK */ },
                success: (restStream, _) => Assert.Fail());

            Combinator.ManyTill(
                Parser.Fail <Char, Char>("Failure"),
                Parser.Return <Char, Unit>(Unit.Instance))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.False(value.Any());
            });

            /*
             * line comment parser example:
             */
            var lineCommentBegin = Chars.Sequence("//");
            var lineCommentEnd   = Chars.EndOfInput().Or(Chars.Char('\n').Ignore());
            var lineComment      = lineCommentBegin
                                   .Bindr(Combinator.ManyTill(Chars.Any(), lineCommentEnd))
                                   .Ignore();

            var foobar = Chars.Sequence("foobar");

            lineComment.Bindr(foobar)
            .Run("//comment comment comment\nfoobar".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "foobar"));
            });
        }