/// <summary> /// Creates a parser which parses the specified string. /// </summary> /// <param name="expectedString"></param> /// <returns></returns> public static Parser <string> OfString(string expectedString) { return (Create(source => ParseResultModule.If( source.StartsWith(expectedString), () => (expectedString, source.Substring(expectedString.Length)), () => source ))); }
/// <summary> /// Creates a parser which parses a character which satisfies the specified condition. /// </summary> /// <param name="expectedChars"></param> /// <returns></returns> public static Parser <char> Satisfy(Func <char, bool> satisfies) { return (Create(source => ParseResultModule.If( source.Length >= 1 && satisfies(source[0]), () => (source[0], source.Substring(1)), () => source ))); }
public Parser <Y> Select <Y>(Func <TValue, Y> func) { return (ParserModule.Create(source => { var result = Parse(source); return ParseResultModule.If( result.IsOk, () => (func(result.Value), result.Rest), () => source ); })); }