Back Under The Hood Again

Here's the backtracking implementation of AndP:

class And2P (Pattern):
   def Match (self, subject):
      for result1 in self.pat1.Match (subject):
         for result2 in self.pat2.Match (subject):
            yield None
   def __init__ (self, pat1, pat2):
      self.pat1 = pat1
      self.pat2 = pat2

(This is a special-case implementation of the bactracking AndP that's used by the "&" operator.)

New Models for Processing Text and XML with Python Sam Wilmott
Slide 24 of 51         example www.wilmott.ca