Exemple #1
0
        public void AttemptTest()
        {
            Combinator.Attempt(Combinator.Sequence("inpXtString".Select(Chars.Char)))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) =>
            {
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('i', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Column);
            },
                success: (restStream, value) => Assert.Fail());

            Combinator.Attempt(Combinator.Sequence("inputString".Select(Chars.Char)))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "inputString"));
                Assert.False(restStream.Current.HasValue);
            });
        }
Exemple #2
0
 public static Parser <Char, IEnumerable <Char> > Sequence(IEnumerable <Char> enumerble)
 {
     return(Combinator.Attempt(Combinator.Sequence(enumerble.Select(Chars.Char))));
 }