예제 #1
0
        public void Sequence_FailingSequence_ReturnsError()
        {
            var parser = Parse.Sequence(Chars.Char('x'),
                                        Chars.Char('y'),
                                        Chars.Char('z'));
            var result = parser.Parse("xy");

            ParseAssert.IsError(result);
        }
예제 #2
0
        public void Sequence_SucceedingSequence_ReturnsResults()
        {
            var parser = Parse.Sequence(Chars.Char('x'),
                                        Chars.Char('y'),
                                        Chars.Char('z'));
            var result = parser.Parse("xyz");

            ParseAssert.ValueEquals(new char[] { 'x', 'y', 'z' }, result);
        }
예제 #3
0
        /// <summary>
        /// Repeats a parser a given number of times.
        /// </summary>
        public static IParser <IEnumerable <TValue> > Repeat <TValue>(this IParser <TValue> parser, int repeatCount)
        {
            if (repeatCount <= 0)
            {
                return(Parse.Succeed(Enumerable.Empty <TValue>()));
            }

            return(Parse.Sequence(Enumerable.Repeat(parser, repeatCount)));
        }
예제 #4
0
 public void Sequence_ParsersNull_ThrowsException()
 {
     Parse.Sequence <Unit>(null);
 }