internal IEnumerable <PatternMatchProgress> MakeStep(MatchElement currentElement) { if (_currentPatternPart >= Pattern.PartCount) { yield break; } var isVariable = Pattern.IsVariable(_currentPatternPart); var currentPatternPart = Pattern.GetCurrentPart(_currentPatternPart); var isPartHardMatched = !isVariable && currentElement.Pattern.Representation.Equals(currentPatternPart); if (isPartHardMatched) { //only way hard match can appear is via non-variable yield return(NextStep()); } if (isVariable) { var newVarBuffers = extendBuffers(currentElement); //first possibility, variable ends after this word. yield return(new PatternMatchProgress(Pattern, _currentPatternPart + 1, newVarBuffers, _varSubstitutions)); //second, variable accepts the word keep accepting other word(s) yield return(new PatternMatchProgress(Pattern, _currentPatternPart, newVarBuffers, _varSubstitutions)); } }
private void registerChild(MatchElement child) { if (child.Parent != null) { throw new NotSupportedException("Cannot register child with parent"); } child.Parent = this; }
private MatchElement[][] extendBuffers(MatchElement currentElement) { var extendedBuffers = new MatchElement[_varBuffers.Length][]; Array.Copy(_varBuffers, extendedBuffers, extendedBuffers.Length); var previousBuffer = extendedBuffers[_currentPatternPart]; if (previousBuffer == null) { extendedBuffers[_currentPatternPart] = new[] { currentElement } } ; else { extendedBuffers[_currentPatternPart] = previousBuffer.Concat(new[] { currentElement }).ToArray(); } return(extendedBuffers); }
internal Match(MatchElement rootElement) { RootElement = rootElement; }