Esempio n. 1
0
        public void AnyTest()
        {
            Prims.Any <Char>()
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, errorMessage) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.AreEqual('i', value);
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(2, restStream.Current.Value.Item1.Column);
            });

            Prims.Any <Char>()
            .Run("".AsStream())
            .Case(
                failure: (restStream, errorMessage) => { /* OK */ },
                success: (restStream, value) => Assert.Fail());
        }
Esempio n. 2
0
 private static Parser <TToken, Unit> DiscardBefore <TToken, T>(Parser <TToken, T> p) =>
 Combinator.Choice(p.Lookahead().Ignore(),
                   from junk in Prims.Any <TToken>().Ignore()
                   from pAhead in DiscardBefore(p)
                   select junk);
Esempio n. 3
0
 private static Parser <Card, Rank> ParseNOfAKind(int n, RankType rankType) =>
 from first in Prims.Any <Card>().Lookahead()
 from tuple in Prims.Satisfy <Card>(card => card.Value == first.Value).Repeat(n)
 select new Rank(rankType, first.Value);