/// <summary> /// Matches the specified <paramref name="parser"/> one or more times consecutively, making the least number of matches possible. /// This is the non-greedy variant of <see cref="OneOrMore{TSource,TResult}(IObservableParser{TSource,TResult})"/>. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to match one or more times consecutively.</param> /// <returns>A parser that yields matches from the specified <paramref name="parser"/> one or more times consecutively, /// making the least number of matches possible.</returns> public static IObservableParser <TSource, IObservable <TResult> > OneOrMoreNonGreedy <TSource, TResult>( this IObservableParser <TSource, TResult> parser) { Contract.Requires(parser != null); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); return(parser.AtLeast <TSource, TResult, TResult>("OneOrMore-NonGreedy", 1, nonGreedy: true)); }
/// <summary> /// Matches the specified <paramref name="parser"/> zero or more times consecutively. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to match zero or more times consecutively.</param> /// <returns>A parser that yields matches from the specified <paramref name="parser"/> zero or more times consecutively.</returns> public static IObservableParser <TSource, IObservable <TResult> > NoneOrMore <TSource, TResult>( this IObservableParser <TSource, TResult> parser) { Contract.Requires(parser != null); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); return(parser.AtLeast <TSource, TResult, TResult>("NoneOrMore", 0)); }
/// <summary> /// Matches the specified <paramref name="parser"/> one or more times consecutively, /// matching the specified <paramref name="separator"/> in between. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TSeparator">The type of the separator elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to match one or more times consecutively.</param> /// <param name="separator">The parser that matches between consecutive matches of the specified <paramref name="parser"/>.</param> /// <returns>A parser that yields matches from the specified <paramref name="parser"/> one or more times consecutively, /// matching the specified <paramref name="separator"/> in between.</returns> public static IObservableParser <TSource, IObservable <TResult> > OneOrMore <TSource, TSeparator, TResult>( this IObservableParser <TSource, TResult> parser, IObservableParser <TSource, TSeparator> separator) { Contract.Requires(parser != null); Contract.Requires(separator != null); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); return(parser.AtLeast("OneOrMore-Separated", 1, separator: separator)); }
/// <summary> /// Matches the specified <paramref name="parser"/> zero or more times consecutively, matching the specified /// <paramref name="separator"/> in between and making the least number of matches possible. /// This is the non-greedy variant of <see cref="NoneOrMore{TSource,TSeparator,TResult}(IObservableParser{TSource,TResult},IObservableParser{TSource,TSeparator})"/>. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to match zero or more times consecutively.</param> /// <param name="separator">The parser that matches between consecutive matches of the specified <paramref name="parser"/>.</param> /// <returns>A parser that yields matches from the specified <paramref name="parser"/> zero or more times consecutively, /// matching the specified <paramref name="separator"/> in between and making the least number of matches possible.</returns> public static IObservableParser <TSource, IObservable <TResult> > NoneOrMoreNonGreedy <TSource, TResult>( this IObservableParser <TSource, TResult> parser, IObservableParser <TSource, TResult> separator) { Contract.Requires(parser != null); Contract.Requires(separator != null); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); return(parser.AtLeast("NoneOrMore-Separated-NonGreedy", 0, separator: separator, nonGreedy: true)); }
/// <summary> /// Matches the specified <paramref name="parser"/> consecutively a minimum number of times, making the least number of matches possible. /// This is the non-greedy variant of <see cref="AtLeast{TSource,TResult}(IObservableParser{TSource,TResult},int)"/>. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to be matched consecutively a minimum number of times.</param> /// <param name="count">The minimum number of times to match the specified <paramref name="parser"/> consecutively.</param> /// <returns>A parser that consecutively matches the specified <paramref name="parser"/> the minimum /// number of times specified by <paramref name="count"/>, making the least number of matches possible.</returns> public static IObservableParser <TSource, IObservable <TResult> > AtLeastNonGreedy <TSource, TResult>( this IObservableParser <TSource, TResult> parser, int count) { Contract.Requires(parser != null); Contract.Requires(count > 0); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); var name = "AtLeast-NonGreedy-" + count; Contract.Assume(!string.IsNullOrEmpty(name)); return(parser.AtLeast <TSource, TResult, TResult>(name, count, nonGreedy: true)); }
/// <summary> /// Matches the specified <paramref name="parser"/> consecutively between the specified number of times, inclusive, /// making the least number of matches possible. /// This is the non-greedy variant of <see cref="AtLeast{TSource,TResult}(IObservableParser{TSource,TResult},int,int)"/>. /// </summary> /// <typeparam name="TSource">The type of the source elements.</typeparam> /// <typeparam name="TResult">The type of the elements that are generated from parsing the source elements.</typeparam> /// <param name="parser">The parser to be matched consecutively a minimum number of times.</param> /// <param name="count">The minimum number of times to match the specified <paramref name="parser"/> consecutively.</param> /// <param name="maximum">The maximum number of times to match the specified <paramref name="parser"/> consecutively.</param> /// <returns>A parser that consecutively matches the specified <paramref name="parser"/> between the specified number of /// times, inclusive, making the least number of matches possible.</returns> public static IObservableParser <TSource, IObservable <TResult> > AtLeastNonGreedy <TSource, TResult>( this IObservableParser <TSource, TResult> parser, int count, int maximum) { Contract.Requires(parser != null); Contract.Requires(count > 0); Contract.Requires(maximum >= count); Contract.Ensures(Contract.Result <IObservableParser <TSource, IObservable <TResult> > >() != null); if (maximum == count) { return(parser.Exactly(count)); } else { var name = "AtLeast-NonGreedy-" + count + "-to-" + maximum; Contract.Assume(!string.IsNullOrEmpty(name)); return(parser.AtLeast <TSource, TResult, TResult>(name, count, maximum, nonGreedy: true)); } }