class Node:
- def subnodes(self, match=None):
+ def walk(self, match=None):
return ()
class Dataclass(metaclass=DataclassMeta):
- def subnodes(self, match=None):
+ def walk(self, match=None):
if match is None:
match = lambda subnode: True
nodes = _collections.deque([root])
while nodes:
node = nodes.popleft()
- nodes.extend(node.subnodes(match=match))
+ nodes.extend(node.walk(match=match))
yield node
def visit(visitor, node):
with visitor(node=node):
- if hasattr(node, "subnodes"):
- for subnode in node.subnodes():
+ if hasattr(node, "walk"):
+ for subnode in node.walk():
visit(visitor=visitor, node=subnode)
def __new__(cls, records):
return super().__new__(cls, sorted(records))
- def subnodes(self, match=None):
+ def walk(self, match=None):
if match is None:
match = lambda subnode: True
return super().__init__()
- def subnodes(self, match=None):
+ def walk(self, match=None):
if match is None:
match = lambda subnode: True
visitor = commands[command][0]()
db = Database(find_wiki_dir())
- records = next(db.subnodes(match=lambda node: isinstance(node, Records)))
+ records = next(db.walk(match=lambda node: isinstance(node, Records)))
if command in ("list",):
match = None
else:
def match(record):
return (isinstance(record, Record) and (record.name == insn))
- for node in records.subnodes(match=match):
+ for node in records.walk(match=match):
visit(visitor=visitor, node=node)