예제 #1
0
 def translate(self):
     self.parser = Parser(self.surlex)
     self.node_list = self.parser.get_node_list()
     self.scribe = RegexScribe(
         self.node_list,
         self.macro_registry,
     )
     self.regex = self.scribe.translate()
     return self.regex
예제 #2
0
 def translate(self):
     self.parser = Parser(self.surlex)
     self.node_list = self.parser.get_node_list()
     self.scribe = RegexScribe(
         self.node_list,
         self.macro_registry,
     )
     self.regex = self.scribe.translate()
     return self.regex
예제 #3
0
class Surlex(object):
    def __init__(self, surlex, macro_registry=DefaultMacroRegistry()):
        self.translated = False
        self.surlex = surlex
        self.macro_registry = macro_registry

    def translate(self):
        self.parser = Parser(self.surlex)
        self.node_list = self.parser.get_node_list()
        self.scribe = RegexScribe(
            self.node_list,
            self.macro_registry,
        )
        self.regex = self.scribe.translate()
        return self.regex

    @property
    def groupmacros(self):
        macros = {}
        if not self.translated:
            self.translate()
        for node in get_all_nodes(self.node_list):
            if isinstance(node, MacroTagNode):
                macros[node.name] = node.macro
        return macros

    @property
    def to_regex(self):
        if not self.translated:
            self.translate()
        return self.regex

    def match(self, subject):
        m = re.match(self.to_regex, subject)
        if m:
            return m.groupdict()

    def reverse_match(self, args):
        return reverse_match(self,args)
예제 #4
0
class Surlex(object):
    def __init__(self, surlex, macro_registry=DefaultMacroRegistry()):
        self.translated = False
        self.surlex = surlex
        self.macro_registry = macro_registry

    def translate(self):
        self.parser = Parser(self.surlex)
        self.node_list = self.parser.get_node_list()
        self.scribe = RegexScribe(
            self.node_list,
            self.macro_registry,
        )
        self.regex = self.scribe.translate()
        return self.regex

    @property
    def groupmacros(self):
        macros = {}
        if not self.translated:
            self.translate()
        for node in get_all_nodes(self.node_list):
            if isinstance(node, MacroTagNode):
                macros[node.name] = node.macro
        return macros

    @property
    def to_regex(self):
        if not self.translated:
            self.translate()
        return self.regex

    def match(self, subject):
        m = re.match(self.to_regex, subject)
        if m:
            return m.groupdict()
예제 #5
0
def surlex_to_regex(surlex):
    parser = Parser(surlex)
    scribe = RegexScribe(parser.get_node_list())
    return scribe.translate()
예제 #6
0
def surlex_to_regex(surlex):
    parser = Parser(surlex)
    scribe = RegexScribe(parser.get_node_list())
    return scribe.translate()