Esempio n. 1
0
 def ParsePosCharGroup(self):
     """Returns a CharClass representing a positive range"""
     cClass = CharClass()
     nRanges = 0
     while True:
         savepos = self.pos
         if self.the_char == u"-" and nRanges:
             # This had better be the last hyphen in the posCharGroup
             if self.match(u"-["):
                 # a subtraction
                 break
             elif self.match(u"-]") or self.match(u"--["):
                 cClass.add_char(u"-")
                 self.next_char()
                 break
             else:
                 # this is all wrong
                 raise RegularExpressionError(
                     "hyphen must be first or last character in posCharGroup [%i]" % self.pos)
         try:
             cClass.add_class(self.ParseCharRange())
             nRanges += 1
             continue
         except RegularExpressionError:
             self.setpos(savepos)
             pass
         try:
             cClass.add_class(self.ParseCharClassEsc())
             nRanges += 1
             continue
         except RegularExpressionError:
             if nRanges:
                 self.setpos(savepos)
                 break
             else:
                 # We expected either a charRange or a charClassEsc
                 raise RegularExpressionError(
                     "Expected charRange or charClassEsc at [%i]" % self.pos)
     return cClass