-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (64 loc) · 1.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from devtools import pprint
from asty.nodes import (
BasicLitNode,
CallExprNode,
FileNode,
IdentNode,
MatchRuleNode,
SelectorExprNode,
)
from asty.visitors import (
Matcher,
NodeTransformer,
)
class TestNodeTransformer(NodeTransformer):
def visit_CallExprNode(self, node):
match node:
case CallExprNode(
fun=IdentNode(name='print'),
args=args,
):
return CallExprNode.construct(
fun=SelectorExprNode.construct(
x=IdentNode.construct(name='log'),
sel=IdentNode.construct(name='Print'),
),
args=args,
)
return super().generic_visit(node)
pattern = MatchRuleNode.construct(
name='call',
rules=[
CallExprNode.construct(
fun=IdentNode.construct(name='print'),
args=[
MatchRuleNode.construct(
name='constant',
rules=[
BasicLitNode.construct(
kind='STRING',
),
]
)
],
),
],
)
if __name__ == '__main__':
filename = "/Users/evgenus/tfc/asty/output.json"
tree = FileNode.parse_file(filename)
# transformer = TestNodeTransformer()
# tree = transformer.visit(tree)
# from devtools import pprint
# pprint(tree)
matcher = Matcher(pattern)
matcher.match(tree)
pprint(matcher)
# output = "/Users/evgenus/tfc/asty/output-processed.json"
# data = tree.json(
# exclude_unset=True,
# by_alias=True,
# indent=2,
# )
# with open(output, 'w') as stream:
# stream.write(data)