def make_replacements(match, alternatives): env = ( match.env if 'OLD' in match.env else updated(match.env, [('OLD', match.matched_items)]) ) return ChunkResult( alternatives.make_substitutions(env), match.xtail, match.env )
def match(self, x, env): if len(x) >= 1 and self.condition(x[0]): return [x[0]], x[1:], updated(env, ((self.name, [x[0]]),)) else: return None, None, None
def match(self, x, env): matched, xtail, new_env = self.target.match(x, env) if matched is not None: new_env = updated(new_env, [(self.name, matched)]) return matched, xtail, new_env