def compile(self): """ This method will compile and prepare everything to start evaluation the configuration specification. This method will: - load all namespaces - compile the __config__ namespace - start resolving it and importing unknown namespaces """ self.load() statements = [] for unit in self._units: if unit.unit is not None: statements.extend(unit.unit.compile()) # add the entity type (hack?) entity = DefineEntity("Entity", "The entity all other entities inherit from.") entity.namespace = Namespace("std", self.__root_ns) requires_rel = DefineRelation([Reference("Entity", ["std"]), "requires", [0, None], False], [Reference("Entity", ["std"]), "provides", [0, None], False]) requires_rel.namespace = Namespace("std", self.__root_ns) statements.append(entity) statements.append(requires_rel) return statements
def create_entity(self, node): """ Create an entity """ comment = None if len(node.children) == 4: comment = self._handle_node(node.children[3]) interf = DefineEntity(str(node.children[0].text), comment) parents = node.children[1].children interf.parents = [self._handle_node(x) for x in parents] attributes = node.children[2].children for attribute in attributes: type_ref = self._handle_node(attribute.children[0]) name = str(attribute.children[1].text) default_value = None if len(attribute.children) > 2: default_value = self._handle_node(attribute.children[2]) interf.add_attribute(type_ref, name, default_value) return interf