コード例 #1
0
        /// <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 IParser <TSource, IEnumerable <TResult> > NoneOrMore <TSource, TResult>(
            this IParser <TSource, TResult> parser)
        {
            Contract.Requires(parser != null);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <TResult> > >() != null);

            return(parser.AtLeast <TSource, TResult, TResult>("NoneOrMore", 0));
        }
コード例 #2
0
        /// <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}(IParser{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 IParser <TSource, IEnumerable <TResult> > OneOrMoreNonGreedy <TSource, TResult>(
            this IParser <TSource, TResult> parser)
        {
            Contract.Requires(parser != null);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <TResult> > >() != null);

            return(parser.AtLeast <TSource, TResult, TResult>("OneOrMore-NonGreedy", 1, nonGreedy: true));
        }
コード例 #3
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="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 IParser <TSource, IEnumerable <TResult> > OneOrMore <TSource, TResult>(
            this IParser <TSource, TResult> parser,
            IParser <TSource, TResult> separator)
        {
            Contract.Requires(parser != null);
            Contract.Requires(separator != null);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <TResult> > >() != null);

            return(parser.AtLeast("OneOrMore-Separated", 1, separator: separator));
        }
コード例 #4
0
        /// <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,TResult}(IParser{TSource,TResult},IParser{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 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 IParser <TSource, IEnumerable <TResult> > NoneOrMoreNonGreedy <TSource, TResult>(
            this IParser <TSource, TResult> parser,
            IParser <TSource, TResult> separator)
        {
            Contract.Requires(parser != null);
            Contract.Requires(separator != null);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <TResult> > >() != null);

            return(parser.AtLeast("NoneOrMore-Separated-NonGreedy", 0, separator: separator, nonGreedy: true));
        }
コード例 #5
0
        /// <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}(IParser{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 IParser <TSource, IEnumerable <TResult> > AtLeastNonGreedy <TSource, TResult>(
            this IParser <TSource, TResult> parser,
            int count)
        {
            Contract.Requires(parser != null);
            Contract.Requires(count > 0);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <TResult> > >() != null);

            var name = "AtLeast-NonGreedy-" + count;

            Contract.Assume(!string.IsNullOrEmpty(name));

            return(parser.AtLeast <TSource, TResult, TResult>(name, count, nonGreedy: true));
        }
コード例 #6
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}(IParser{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 IParser <TSource, IEnumerable <TResult> > AtLeastNonGreedy <TSource, TResult>(
            this IParser <TSource, TResult> parser,
            int count,
            int maximum)
        {
            Contract.Requires(parser != null);
            Contract.Requires(count > 0);
            Contract.Requires(maximum >= count);
            Contract.Ensures(Contract.Result <IParser <TSource, IEnumerable <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));
            }
        }
コード例 #7
0
 /// <summary>
 /// Succeeds if the parser succeeds at least once. The value is a collection of as many items as can be successfully parsed.
 /// </summary>
 public static IParser <IReadOnlyList <T> > AtLeastOnce <T>(this IParser <T> parser) => parser.AtLeast(1);
コード例 #8
0
 /// <summary>
 /// Always succeeds. The value is a collection of as many items as can be successfully parsed.
 /// </summary>
 public static IParser <IReadOnlyList <T> > Many <T>(this IParser <T> parser) => parser.AtLeast(0);
コード例 #9
0
ファイル: Parser-Repeat.cs プロジェクト: ejball/Parsing
 /// <summary>
 /// Succeeds if the parser succeeds at least once. The value is a collection of as many items as can be successfully parsed.
 /// </summary>
 public static IParser <IReadOnlyList <T> > AtLeastOnce <T>(this IParser <T> parser)
 {
     return(parser.AtLeast(1));
 }
コード例 #10
0
ファイル: Parser-Repeat.cs プロジェクト: ejball/Parsing
 /// <summary>
 /// Always succeeds. The value is a collection of as many items as can be successfully parsed.
 /// </summary>
 public static IParser <IReadOnlyList <T> > Many <T>(this IParser <T> parser)
 {
     return(parser.AtLeast(0));
 }