~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Lib/lib2to3/pytree.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
652
652
                if self.name:
653
653
                    r[self.name] = nodes[:count]
654
654
                yield count, r
 
655
        elif self.name == "bare_name":
 
656
            yield self._bare_name_matches(nodes)
655
657
        else:
656
658
            for count, r in self._recursive_matches(nodes, 0):
657
659
                if self.name:
658
660
                    r[self.name] = nodes[:count]
659
661
                yield count, r
660
662
 
 
663
    def _bare_name_matches(self, nodes):
 
664
        """Special optimized matcher for bare_name."""
 
665
        count = 0
 
666
        r = {}
 
667
        done = False
 
668
        max = len(nodes)
 
669
        while not done and count < max:
 
670
            done = True
 
671
            for leaf in self.content:
 
672
                if leaf[0].match(nodes[count], r):
 
673
                    count += 1
 
674
                    done = False
 
675
                    break
 
676
        r[self.name] = nodes[:count]
 
677
        return count, r
 
678
 
661
679
    def _recursive_matches(self, nodes, count):
662
680
        """Helper to recursively yield the matches."""
663
681
        assert self.content is not None
664
682
        if count >= self.min:
665
 
            r = {}
666
 
            if self.name:
667
 
                r[self.name] = nodes[:0]
668
 
            yield 0, r
 
683
            yield 0, {}
669
684
        if count < self.max:
670
685
            for alt in self.content:
671
686
                for c0, r0 in generate_matches(alt, nodes):