1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """A generic visitor abstract implementation.
19
20
21
22
23 """
24 __docformat__ = "restructuredtext en"
25
28
29
31
32 - def __init__(self, node, list_func, filter_func=None):
33 self._next = [(node, 0)]
34 if filter_func is None:
35 filter_func = no_filter
36 self._list = list_func(node, filter_func)
37
39 try:
40 return self._list.pop(0)
41 except :
42 return None
43
44
46
47 - def __init__(self, iterator_class, filter_func=None):
48 self._iter_class = iterator_class
49 self.filter = filter_func
50
51 - def visit(self, node, *args, **kargs):
52 """
53 launch the visit on a given node
54
55 call 'open_visit' before the beginning of the visit, with extra args
56 given
57 when all nodes have been visited, call the 'close_visit' method
58 """
59 self.open_visit(node, *args, **kargs)
60 return self.close_visit(self._visit(node))
61
63 iterator = self._get_iterator(node)
64 n = next(iterator)
65 while n:
66 result = n.accept(self)
67 n = next(iterator)
68 return result
69
71 return self._iter_class(node, self.filter)
72
74 """
75 method called at the beginning of the visit
76 """
77 pass
78
80 """
81 method called at the end of the visit
82 """
83 return result
84
85
87 """
88 Visited interface allow node visitors to use the node
89 """
91 """
92 return the visit name for the mixed class. When calling 'accept', the
93 method <'visit_' + name returned by this method> will be called on the
94 visitor
95 """
96 try:
97 return self.TYPE.replace('-', '_')
98 except:
99 return self.__class__.__name__.lower()
100
101 - def accept(self, visitor, *args, **kwargs):
104
105 - def leave(self, visitor, *args, **kwargs):
108