public IEnumerable <MatchResult <T> > FindMatchesIn(IEnumerable <T> sequence)
        {
            var indexedSequence = new IndexedSequence <T>(sequence);
            var context         = new MatchContext <T>(indexedSequence);

            while (!context.IsEndOfSequence)
            {
                var startIndex = context.Index;
                var newContext = Match(context).FirstOrDefault();
                if (newContext != null)
                {
                    yield return(new MatchResult <T>(newContext, startIndex));
                }

                int newIndex = (newContext != null && newContext.Index > context.Index) ? newContext.Index : context.Index + 1;
                context = new MatchContext <T>(indexedSequence).WithIndex(newIndex);
            }
        }
Beispiel #2
0
 public MatchContext(IndexedSequence <T> inputSequence)
 {
     InputSequence   = inputSequence;
     MatchReferences = ImmutableDictionary <int, MatchReference> .Empty;
 }