예제 #1
0
 def __init__(self, expr):
     ParserElement.__init__(self)
     self.expr = expr = engine.CURRENT.normalize(expr)
     if is_forward(expr):
         expr.track(self)
     self.parser_config.mayIndexError = expr.parser_config.mayIndexError
     self.parser_config.mayReturnEmpty = expr.parser_config.mayReturnEmpty
예제 #2
0
    def __init__(self, expr=Null):
        ParserElement.__init__(self)
        self.expr = None
        self.used_by = []

        self._str = None  # avoid recursion
        if expr:
            self << engine.CURRENT.normalize(expr)
예제 #3
0
 def __init__(self, expr=Null):
     ParserElement.__init__(self)
     self.expr = None
     self.used_by = []
     self.parser_config.mayIndexError = expr.parser_config.mayIndexError
     self.parser_config.mayReturnEmpty = expr.parser_config.mayReturnEmpty
     self.strRepr = None  # avoid recursion
     if expr:
         self << engine.CURRENT.normalize(expr)
예제 #4
0
 def copy(self):
     output = ParserElement.copy(self)
     if self.engine is engine.CURRENT:
         output.exprs = self.exprs
     else:
         output.exprs = [e.copy() for e in self.exprs]
     return output
예제 #5
0
    def copy(self):
        output = ParserElement.copy(self)
        output.expr = self
        output._str = None

        output.used_by = []
        return output
예제 #6
0
    def copy(self):
        output = ParserElement.copy(self)

        output.flags = self.flags
        output.pattern = self.pattern
        output.re = self.re
        return output
예제 #7
0
 def copy(self):
     output = ParserElement.copy(self)
     if self.engine is engine.CURRENT:
         output.expr = self.expr
     else:
         output.expr = self.expr.copy()
     return output
예제 #8
0
    def __call__(self, name):
        if not name:
            return self
        # for e in self.exprs:
        #     if isinstance(e, ParserElement) and e.token_name:
        #         Log.error("token name is already set in child, use Group() to clarify")

        return ParserElement.__call__(self, name)
예제 #9
0
 def copy(self):
     output = ParserElement.copy(self)
     output.asKeyword = self.asKeyword
     output.bodyChars = self.bodyChars
     output.initChars = self.initChars
     output.maxLen = self.maxLen
     output.maxSpecified = self.maxSpecified
     output.minLen = self.minLen
     return output
예제 #10
0
    def __init__(self, maps):
        ParserElement.__init__(self)

        all_keys = set()
        lookup = OrderedDict()
        for m in maps:
            for k, ee in m.items():
                all_keys.add(k)
                lookup.setdefault(k, []).extend(ee)

        # patterns must be mutually exclusive to work
        items = list(lookup.items())
        if len(maps) - max(len(v) for k, v in items) < LOOKUP_COST:
            Log.error("not useful")

        compact = []
        for k, e in items:
            min_k = k
            # FIND SHORTEST PREFIX
            for kk, ee in items:
                if ee and min_k.startswith(kk):
                    min_k = kk
            # COLLECT
            acc = []
            for kk, ee in items:
                if kk.startswith(min_k):
                    acc.extend(ee)
                    ee.clear()
            if acc:
                compact.append((min_k, acc))
        if len(maps) - max(len(v) for k, v in compact) < LOOKUP_COST:
            Log.error("not useful")

        # patterns can be shortened so far as they remain exclusive
        shorter = [
            (k[:min_length], e)
            for k, e in sorted(compact, key=lambda p: p[0])
            for min_length in [max(_distinct(k, kk) for kk, _ in compact if kk != k)]
        ]

        self.lookup = {k: e for k, e in shorter}
        self.regex = regex_compile("|".join(regex_caseless(k) for k, _ in shorter))
        self.all_keys = list(sorted(all_keys))
예제 #11
0
 def __init__(self, expr):
     ParserElement.__init__(self)
     self.expr = expr = engine.CURRENT.normalize(expr)
     if is_forward(expr):
         expr.track(self)
예제 #12
0
 def __init__(self):
     ParserElement.__init__(self)
     self.streamlined = True
예제 #13
0
 def __init__(self, expr):
     ParserElement.__init__(self)
     self.expr = expr = self.engine.normalize(expr)
     self.parser_config.mayIndexError = expr.parser_config.mayIndexError
     self.parser_config.mayReturnEmpty = expr.parser_config.mayReturnEmpty
예제 #14
0
 def copy(self):
     output = ParserElement.copy(self)
     output.exprs = self.exprs
     return output
예제 #15
0
 def copy(self):
     output = ParserElement.copy(self)
     output.notChars = self.notChars
     output.minLen = self.minLen
     output.maxLen = self.maxLen
     return output
예제 #16
0
 def copy(self):
     output = ParserElement.copy(self)
     output.match = self.match
     return output
예제 #17
0
 def __init__(self, expr):
     ParserElement.__init__(self)
     self.expr = self.engine.normalize(expr)
예제 #18
0
 def copy(self):
     output = ParserElement.copy(self)
     output.match = self.match
     output.identChars = self.identChars
     return output