Ejemplo n.º 1
0
    def setUp(self):

        # Get an ast we can visit with our visitors
        self.ast_to_visit = get_test_ast()

        # How should the visited ast look like (further modified by tests)?
        self.ast_should = get_test_ast()

        self.text_change_visitor = TextChangeVisitor()
        self.politeness_visitor = PolitenessVisitor()
        self.enlarge_visitor = EnlargeVisitor()
        self.gui_visitor = GuiVisitor()
#!/usr/bin/env python

from pyml_ast import get_test_ast
import base_visitor


class TextChangeVisitor(base_visitor.BaseVisitor):
    """Adds a prefix to all Button and Label texts."""

    def visit_button(self, button):
        button.text = "BUTTON: " + button.text

    def visit_label(self, label):
        label.text = "LABEL: " + label.text


if __name__ == '__main__':
    ast = get_test_ast()
    v = TextChangeVisitor()
    v.visit(ast)
    print ast.repr()