Esempio n. 1
0
        /// <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));
            }
        }