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
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)
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)
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
def copy(self): output = ParserElement.copy(self) output.expr = self output._str = None output.used_by = [] return output
def copy(self): output = ParserElement.copy(self) output.flags = self.flags output.pattern = self.pattern output.re = self.re return output
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
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)
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
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))
def __init__(self, expr): ParserElement.__init__(self) self.expr = expr = engine.CURRENT.normalize(expr) if is_forward(expr): expr.track(self)
def __init__(self): ParserElement.__init__(self) self.streamlined = True
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
def copy(self): output = ParserElement.copy(self) output.exprs = self.exprs return output
def copy(self): output = ParserElement.copy(self) output.notChars = self.notChars output.minLen = self.minLen output.maxLen = self.maxLen return output
def copy(self): output = ParserElement.copy(self) output.match = self.match return output
def __init__(self, expr): ParserElement.__init__(self) self.expr = self.engine.normalize(expr)
def copy(self): output = ParserElement.copy(self) output.match = self.match output.identChars = self.identChars return output