def translate(self):
        output = ''
        for node in self.node_list:
            if isinstance(node, TextNode):
                output += node.token.replace('.', '\.')
            elif isinstance(node, WildcardNode):
                output += '.*'
            elif isinstance(node, OptionalNode):
                output += '(' + RegexScribe(node.node_list).translate() + ')?'
            elif isinstance(node, TagNode):
                if isinstance(node, MacroTagNode):
                    regex = self.macro_registry.get(node.macro)
                elif isinstance(node, RegexTagNode):
                    regex = node.regex
                else:
                    regex = '.+'
                if node.name:
                    output += '(?P<%s>%s)' % (node.name, regex)
                else:
                    output += regex
        return output
dataset/ETHPy150Open codysoyland/surlex/src/surlex/grammar.py/RegexScribe.translate/original