Glossary#

constant#

An ast.Constant object that represents a hard-coded literal in the source code.

engine#

Engine is the core transformation loop that resides within a session. It is responsible for traversing the AST, managing rules and their context as well as running them on each node and continuously transform the source code until nothing more can be done with it.

rule#

A rule is a static analyzing component that holds the information about an analysis’s contract and transformation. A more concrete definition includes every class that inherits from Rule and implements a match() method.

class DummyRule(refactor.Rule):

    def match(self, node):
        assert isinstance(node, ast.Name)
        assert node.id != "dummy"
        return Replace(node, ast.Name("dummy", ctx=node.ctx))
contract#

A contract is an informal section of a rule’s match() method that filters the nodes.

class DummyRule(refactor.Rule):

    def match(self, node):
        assert isinstance(node, ast.Name)
        assert node.id != "dummy"
        return Replace(node, ast.Name("dummy", ctx=node.ctx))
transformation#

A transformation is an informal section of a rule’s match() method that prepares the action for source transformation.

class DummyRule(refactor.Rule):

    def match(self, node):
        assert isinstance(node, ast.Name)
        assert node.id != "dummy"
        return Replace(node, ast.Name("dummy", ctx=node.ctx))
action#

An action, or a source transformation action, is an object that implements the BaseAction protocol. There are multiple built-in ones, like Replace or InsertAfter, in addition to the ones that the user can write.

class DummyAction(LazyReplace):
    def build(self):
        return ast.Name("dummy", ctx=self.nod.ctx)

class DummyRule(Rule):
    def match(self, node):
        assert isinstance(node, ast.Name)
        assert node.id != "dummy"
        return DummyAction(node)
context#

A Context object that represents the state of the current processed module (including the raw source code, full tree, as well as all the initialized context providers). Shared between all rules in the same session.

session#

A Session object that represents a collection of rules to run together.