def greedy_replace(self, seq):
if not self._suffix_links_set:<EOL><INDENT>self._set_suffix_links()<EOL><DEDENT>current = self.root<EOL>buffered = '<STR_LIT>'<EOL>outstr = '<STR_LIT>'<EOL>for char in seq:<EOL><INDENT>while char not in current:<EOL><INDENT>if current.has_dict_suffix:<EOL><INDENT>current = current.dict_suffix<EOL>outstr += buffered[:-current.depth]<EOL>outstr += current.value<EOL>buffered = '<STR_LIT>'<EOL>current = self.root<EOL>break<EOL><DEDENT>elif current.has_suffix:<EOL><INDENT>current = current.suffix<EOL>if current.depth:<EOL><INDENT>outstr += buffered[:-current.depth]<EOL>buffered = buffered[-current.depth:]<EOL><DEDENT>else:<EOL><INDENT>outstr += buffered<EOL>buffered = '<STR_LIT>'<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>current = self.root<EOL>outstr += buffered<EOL>buffered = '<STR_LIT>'<EOL>break<EOL><DEDENT><DEDENT>if char in current:<EOL><INDENT>buffered += char<EOL>current = current[char]<EOL>if current.has_value:<EOL><INDENT>outstr += buffered[:-current.depth]<EOL>outstr += current.value<EOL>buffered = '<STR_LIT>'<EOL>current = self.root<EOL><DEDENT><DEDENT>else:<EOL><INDENT>assert current is self.root<EOL>outstr += buffered + char<EOL>buffered = '<STR_LIT>'<EOL><DEDENT><DEDENT>if current.has_dict_suffix:<EOL><INDENT>current = current.dict_suffix<EOL>outstr += buffered[:-current.depth]<EOL>outstr += current.value<EOL><DEDENT>else:<EOL><INDENT>outstr += buffered<EOL><DEDENT>return outstr<EOL>
Greedily matches strings in ``seq``, and replaces them with their
node values.

Arguments:
- `seq`: an iterable of characters to perform search-and-replace on