Skip to content

Commit a548bc2

Browse files
Add reify ast
1 parent 272d01c commit a548bc2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

evalo/reify.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ast
2+
from kanren import reify
3+
from unification.more import reify_object
4+
from copy import deepcopy
5+
6+
def reify_ast(s):
7+
"""
8+
Reify ast objects in s
9+
"""
10+
objects = []
11+
for s_dict in s:
12+
for k,v in s_dict.items():
13+
s_without_k = deepcopy(s_dict)
14+
del s_without_k[k]
15+
print('Reifying {}:{} with {}'.format(k, v, s_without_k))
16+
try:
17+
o = reify_object(v, s_without_k)
18+
except AttributeError:
19+
o = reify(v, s_without_k)
20+
objects.append(o)
21+
return [ast_dump_if_possible(o) for o in objects]
22+
23+
def ast_dump_if_possible(a):
24+
if isinstance(a, ast.AST):
25+
return ast.dump(a)
26+
return a

0 commit comments

Comments
 (0)