Exemplo n.º 1
0
 def parse_alternation(self):
     """
     Parse the string from its current index into an alternation or an expression that can be contained by an alternation.
     @return: a visitable regular expression object from the Regex package.
     """
     concatenations = [self.parse_concatenation()]
     while self.get_next_if(u'|'):
         concatenations.append(self.parse_concatenation())
     if len(concatenations) > 1:
         return Regex.Alternation(concatenations)
     else:
         return concatenations[0]
Exemplo n.º 2
0
 def visit_alternation(self, alternation):
     new_alternation = Regex.Alternation([])
     for child in alternation.children:
         child.accept(self)
         new_alternation.children.append(self.stack.pop())
     self.stack.append(new_alternation)