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); } }
public MatchContext(IndexedSequence <T> inputSequence) { InputSequence = inputSequence; MatchReferences = ImmutableDictionary <int, MatchReference> .Empty; }