Пример #1
0
 def regexes(self):
     if not self.diffs:
         self._generate_diffs()
     regexes = []
     for s0_id, diff_dict in self.diffs.viewitems():
         for s1_id, diff in diff_dict.viewitems():
             s0, s1 = self.sequences[s0_id], self.sequences[s1_id]
             bookmark_i = 0
             bookmark_j = 0
             this_regex = [r'^']
             for i, j, n in diff:
                 nonmatches_i = s0[bookmark_i:i]
                 nonmatches_j = s1[bookmark_j:j]
                 mismatch_group = retools.char_set_to_smart_group(nonmatches_i + nonmatches_j)
                 this_regex.append(mismatch_group)
                 match_group = retools.escaped(s0[i:i+n])
                 this_regex.append(match_group)
                 bookmark_i = i+n
                 bookmark_j = j+n
             this_regex.append(r'$')
             regexes.append(''.join(this_regex))
     return regexes
Пример #2
0
 def __init__(self, left, right, data, fill=False):
     super(ChoiceOptNode, self).__init__(left, right, data, 'choice_opt', fill)
     self.regex = lambda: r'(%s)?' % '|'.join([retools.escaped(x) for x in self.data])
Пример #3
0
 def __init__(self, left, right, data, fill=False):
     super(ConcatOptNode, self).__init__(left, right, data, 'concat_opt', fill)
     self.regex = lambda: r'(%s)?' % retools.escaped(self.data)