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); }
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); }
/// <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))); }
public void Sequence_ParsersNull_ThrowsException() { Parse.Sequence <Unit>(null); }