Debian Codegraph @

third_party/python/fluent.migrate/fluent/migrate/evaluator.py

raw
1 from fluent.syntax import ast as FTL
2 from fluent.syntax.visitor import Transformer
3
4 from .transforms import Transform
5
6
7 class Evaluator(Transformer):
8 """An AST transformer for evaluating migration Transforms.
9
10 An AST transformer (i.e. a visitor capable of modifying the AST) which
11 walks an AST hierarchy and evaluates nodes which are migration Transforms.
12 """
13
14 def __init__(self, ctx):
15 self.ctx = ctx
16
17 def visit(self, node):
18 if not isinstance(node, FTL.BaseNode):
19 return node
20
21 if isinstance(node, Transform):
22 # Some transforms don't expect other transforms as children.
23 # Evaluate the children first.
24 transform = self.generic_visit(node)
25 # Then, evaluate this transform.
26 return transform(self.ctx)
27
28 return self.generic_visit(node)