예제 #1
0
        /// <summary>
        /// Matches the specified <paramref name="parser"/> when the specified <paramref name="notParser"/> does not match.
        /// </summary>
        /// <typeparam name="TSource">The type of the source elements.</typeparam>
        /// <typeparam name="TNotResult">The type of the elements that are generated by the <paramref name="notParser"/>.</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 when the specified <paramref name="notParser"/> does not match.</param>
        /// <param name="notParser">The parser that when it matches will cause the matches from the specified
        /// <paramref name="parser"/> to be ignored.</param>
        /// <returns>A parser that matches the specified <paramref name="parser"/> when the specified <paramref name="notParser"/>
        /// does not match.</returns>
        public static IObservableParser <TSource, TResult> Not <TSource, TNotResult, TResult>(
            this IObservableParser <TSource, TResult> parser,
            IObservableParser <TSource, TNotResult> notParser)
        {
            Contract.Requires(parser != null);
            Contract.Requires(notParser != null);
            Contract.Ensures(Contract.Result <IObservableParser <TSource, TResult> >() != null);

            return(notParser.None(default(TNotResult)).SelectMany(_ => parser, (_, result) => result));
        }