Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_cat(cat):
"""
ex. PPo1\.h --> PPo1\(PPs\Sm)
"""
rule = cat.rfind('.')
if rule >= 0:
cat = cat[:rule]
cat = drop_brackets(cat)
op_idx = find_non_nested_char(cat, '/\\')
if op_idx == -1:
return Atomic(FEATURE_PATTERN.sub('[\\1]', cat))
else:
left = parse_cat(cat[:op_idx])
slash = cat[op_idx:op_idx + 1]
right = parse_cat(cat[op_idx + 1:])
return Functor(left, slash, right)
def rec(cat):
if isinstance(cat, Atomic):
return str(cat)
right = rec(cat.right if cat.slash == '\\' else cat.left)
left = rec(cat.left if cat.slash == '\\' else cat.right)
return f'({right}{cat.slash}{left})'
return rec(self)[1:-1]