def ParsePosCharGroup(self): """Returns a CharClass representing a positive range""" cClass = CharClass() nRanges = 0 while True: savePos = self.pos if self.theChar == 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.AddChar(u"-") self.NextChar() break else: # this is all wrong raise RegularExpressionError( "hyphen must be first or last character in posCharGroup [%i]" % self.pos) try: cClass.AddClass(self.ParseCharRange()) nRanges += 1 continue except RegularExpressionError: self.SetPos(savePos) pass try: cClass.AddClass(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