コード例 #1
0
 def parse_qualified(self):
     """
     Parse the string from its current index into a repetition or an expression that can be contained by an repetition.
     @return: a visitable regular expression object from the Regex package.
     """
     child = self.parse_character()
     if self.get_next_if(u'*'):
         return Regex.Repetition(child, 0, Regex.Repetition.Infinity)
     elif self.get_next_if(u'+'):
         return Regex.Repetition(child, 1, Regex.Repetition.Infinity)
     elif self.get_next_if(u'?'):
         return Regex.Repetition(child, 0, 1)
     # Need to look ahead two characters because it might be a variable following this one
     elif self.next_is(u'{') and self.nth_next_is_not(
             2, string.ascii_letters + '.'):
         self.get_next()
         return self.parse_repetition(child)
     else:
         return child
コード例 #2
0
 def parse_repetition(self, child):
     """
     Parse a {min, max} expression from the string at its current index
     @param child: a visital object from the Regex package containing the repeated expression.
     @return: a Regex.Repetition object representing the repetition.
     """
     first = self.parse_integer()
     self.expect(u',')
     last = self.parse_integer()
     self.expect(u'}')
     if first > last:
         raise RegexParserExceptionInternal(
             "Minimum repetition (%d) cannot be larger than maximum repetition (%d)."
             % (first, last))
     return Regex.Repetition(child, first, last)
コード例 #3
0
 def visit_repetition(self, repetition):
     new_repetition = Regex.Repetition(None, repetition.min, repetition.max)
     repetition.child.accept(self)
     new_repetition.child = self.stack.pop()
     self.stack.append(new_repetition)