return None
+class Records(tuple):
+ def __new__(cls, records):
+ return super().__new__(cls, sorted(records))
+
+ def subnodes(self, match=None):
+ if match is None:
+ match = lambda subnode: True
+
+ for record in self:
+ if match(record):
+ yield record
+
+
class Database(Node):
def __init__(self, root):
root = _pathlib.Path(root)
names[record.name] = record
opcodes[section][record.PO].add(record)
- self.__db = sorted(db)
+ self.__db = Records(db)
self.__names = dict(sorted(names.items()))
self.__opcodes = dict(sorted(opcodes.items()))
if match is None:
match = lambda subnode: True
- yield from filter(match, self)
+ if match(self.__db):
+ yield self.__db
def __repr__(self):
return repr(self.__db)
Database,
Extra,
Record,
+ Records,
Visitor,
visit,
)
visitor = commands[command][0]()
db = Database(find_wiki_dir())
+ records = next(db.subnodes(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 db.subnodes(match=match):
+ for node in records.subnodes(match=match):
visit(visitor=visitor, node=node)