def test_overlap(self): m = TaggedFragments(UNICODE) m.append(Character([('b', 'd')], UNICODE), 'bd') m.append(Character([('c', 'e')], UNICODE), 'ce') l = list(m) assert l == [(('b', 'b'), ['bd']), (('c', 'd'), ['bd', 'ce']), (('e', 'e'), ['ce'])], l
def clone_any(use, original, restrict=None): ''' We can always convert Any() to a regular expression; the only question is whether we have an open range or not. ''' if restrict is None: char = Character([(alphabet_.min, alphabet_.max)], alphabet_) else: char = Character(((char, char) for char in restrict), alphabet_) log.debug(fmt('Any: cloned {0}', char)) regexp = Sequence(alphabet_, char) return RegexpContainer.build(original, regexp, alphabet_, regexp_type, use)
def clone_literal(use, original, text): ''' Literal values are easy to transform. ''' chars = [Character([(c, c)], alphabet_) for c in text] regexp = Sequence(alphabet_, *chars) log.debug(fmt('Literal: cloned {0}', regexp)) return RegexpContainer.build(original, regexp, alphabet_, regexp_type, use)
def __add_groups(self, src, groups, stack): ''' The target nfa nodes identified above are now used to create dfa nodes. ''' for nfa_nodes in groups: (intervals, terminals) = groups[nfa_nodes] char = Character(intervals, self.__alphabet) (new, dest) = self.dfa.node(nfa_nodes) self.dfa.connect(src, dest, char) if new: stack.append((dest, nfa_nodes, terminals))
def test_single(self): m = TaggedFragments(UNICODE) m.append(Character([('b', 'c')], UNICODE), 'bc') l = list(m) assert l == [(('b', 'c'), ['bc'])], l