/// <summary> /// Succeeds for any character for which the given predicate returns true. Returns the parsed character. /// </summary> public static IParser <char> Satisfy(Predicate <char> predicate) { Throw.IfNull(predicate, "predicate"); return(Parse.Try(from c in Any() where predicate(c) select c)); }
public void Try_Success_ReturnsSuccess() { var parser = from a in Parse.Try(Parse.Succeed("a")) from b in Parse.Try(Parse.Succeed("b")) select a + b; var result = parser.Parse("abc"); ParseAssert.ValueEquals("ab", result); }
public void Try_Error_ReturnsErrorAndResetsPosition() { var parser = Parse.Try(from x in Chars.Any() from y in Chars.Any() from f in Parse.Fail <char>("test") select x); IInputReader input = InputReader.Create("abc"); Position expectedPosition = input.GetPosition(); var result = parser.Parse(input); ParseAssert.IsError(result); Assert.AreEqual(expectedPosition, input.GetPosition()); }