def instantiate(self, group, block, tree): for stmt in tree.stmts: if isinstance(stmt, parser.Node): node = DiagramNode.get(stmt.id) node.set_attributes(stmt.attrs) self.append_node(node, group) elif isinstance(stmt, parser.Edge): self.instantiate_edge(group, block, stmt) elif isinstance(stmt, parser.Group): node = NodeGroup.get(None) self.instantiate(node, block, stmt) self.diagram.groups.append(node) elif isinstance(stmt, parser.Attr): if block: block.set_attribute(stmt) else: group.set_attribute(stmt) elif isinstance(stmt, parser.Separator): sep = EdgeSeparator(stmt.type, unquote(stmt.value)) sep.group = group self.diagram.separators.append(sep) group.edges.append(sep) elif isinstance(stmt, parser.Fragment): subblock = AltBlock(stmt.type, stmt.id) if block: subblock.xlevel = block.xlevel + 1 self.diagram.altblocks.append(subblock) self.instantiate(group, subblock, stmt) if block: for edge in subblock.edges: block.edges.append(edge) elif isinstance(stmt, parser.Extension): if stmt.type == 'class': name = unquote(stmt.name) Diagram.classes[name] = stmt elif stmt.type == 'plugin': self.diagram.set_plugin(stmt.name, stmt.attrs) return group
def build(cls, tree): DiagramNode.clear() DiagramEdge.clear() NodeGroup.clear() return DiagramTreeBuilder().build(tree)