def go(ast): for s, action in rules: matches = P.matches(P.make_pattern(s), ast) if matches is not None: return action(**matches) else: raise ValueError('Failed to parse ast node: ' + P.pretty(P.explode(ast)))
def __str__(self): return '{}\nfor:\n{}'.format( P.pretty(P.explode(self.ast)), '\n'.join('{}\n{}'.format(r.name, U.indent(' ', str(e))) for r, e in self.errors))
def __str__(self): if self.s is not None: return '{} ({})'.format(self.s, self.name) else: return '{} ({})'.format(P.pretty(P.explode(self.pattern)), self.name)
print(s.check() == z3.sat) print( parse('array[?n + 1 + m*(n+3), 1, 2, True, False, int(?a), bool(a)]')) try_unify(parse('?a'), parse('array[?a]'), σ) try_unify(parse('?a'), parse('array[b]'), σ) try_unify(parse('array[a, b, c]'), parse('array[d]'), σ) try_unify(parse('(a, b, c)'), parse('(d, e)'), σ) try_unify(parse('Fun(True, False)'), parse('Fun(False, False)'), σ) try_unify(parse('Fun(array[n], array[n + 1])'), parse('Fun(array[n], array[1 + n])'), σ) arg = P.matches(P.make_pattern('def f(__a):\n pass'), A.parse('def f(a : int):\n pass').body[0]) arg = arg['a'][0] print(P.pretty(P.explode(arg))) print(from_ast(arg), str(from_ast(arg)[1])) arg = P.matches(P.make_pattern('def f(__a):\n pass'), A.parse('def f(a : array[1 + n]):\n pass').body[0]) arg = arg['a'][0] print(P.pretty(P.explode(arg))) print(from_ast(arg), str(from_ast(arg)[1])) arg = P.matches(P.make_pattern('def f() -> _r:\n pass'), A.parse('def f() -> array[1 + n]:\n pass').body[0])['r'] print(P.pretty(P.explode(arg))) print(from_ast(arg))