示例#1
0
        private static IParseResult <IEnumerable <TValue> > YieldMany <TValue>(
            this IParseResult <TValue> result,
            TValue value,
            int length)
        {
            Contract.Requires(result != null);
            Contract.Requires(length >= 0);
            Contract.Ensures(Contract.Result <IParseResult <IEnumerable <TValue> > >() != null);

            var lookAhead = result as ILookAheadParseResult <TValue>;

            if (lookAhead != null)
            {
                var newLookAhead = new LookAheadParseResult <IEnumerable <TValue> >(
                    new List <TValue>()
                {
                    value
                }
                    .AsReadOnly(),
                    length);

                newLookAhead.Subscribe(lookAhead.OnCompleted);

                return(newLookAhead);
            }
            else
            {
                return(new ParseResult <IEnumerable <TValue> >(
                           new List <TValue>()
                {
                    value
                }
                           .AsReadOnly(),
                           length));
            }
        }
示例#2
0
        internal static IParseResult <TNewValue> Yield <TOldValue, TNewValue>(
            this IParseResult <TOldValue> result,
            TNewValue value,
            int length)
        {
            Contract.Requires(result != null);
            Contract.Requires(length >= 0);
            Contract.Ensures(Contract.Result <IParseResult <TNewValue> >() != null);

            var lookAhead = result as ILookAheadParseResult <TOldValue>;

            if (lookAhead != null)
            {
                var newLookAhead = new LookAheadParseResult <TNewValue>(value, length);

                newLookAhead.Subscribe(lookAhead.OnCompleted);

                return(newLookAhead);
            }
            else
            {
                return(new ParseResult <TNewValue>(value, length));
            }
        }