def get_object(self, object_name, namespace_parts=None): """ Return the object identified by ``object_name``, which is under the namespace whose names are ``namespace_parts``. :param object_name: The name of the object to be returned. :type object_name: basestring :param namespace_parts: The sub-namespace that contains the object identified by ``object_name``, represented by a list of names; or, ``None`` if the object is in the current namespace. :type namespace_parts: list :return: The requested object. :rtype: Operand :raises ScopeError: If the requested object doesn't exist in the namespace, or if the sub-namespace in ``namespace_parts`` doesn't exist. """ ns = self._get_subnamespace(namespace_parts) if ns is None or object_name not in ns.objects: msg = u'No such object "%s"' % object_name if namespace_parts: msg = u'%s in %s' % (msg, u":".join(namespace_parts)) raise ScopeError(msg) return ns.objects[object_name]
def get_object(self, object_name, namespace_parts=None): """ Return the object identified by ``object_name``, which is under the namespace whose names are ``namespace_parts``. :param object_name: The name of the object to be returned. :type object_name: basestring :param namespace_parts: The sub-namespace that contains the object identified by ``object_name``, represented by a list of names; or, ``None`` if the object is in the current namespace. :type namespace_parts: list :return: The requested object. :rtype: Operand :raises ScopeError: If the requested object doesn't exist in the namespace, or if the sub-namespace in ``namespace_parts`` doesn't exist. """ object_name = object_name.lower() ns = self._get_subnamespace(namespace_parts) if ns is None: msg = u'No such object "%s"' % object_name if namespace_parts: msg = u'%s in %s' % (msg, u":".join(namespace_parts)) raise ScopeError(msg) if namespace_parts is not None: ns2 = self._get_subnamespace(namespace_parts[0:-1]) from booleano.operations import ArrayVariable if (object_name not in ns.objects and namespace_parts is not None and namespace_parts[-1].lower() in ns2.objects and isinstance(ns2.objects[namespace_parts[-1].lower()], ArrayVariable)): var = ns2.objects[namespace_parts[-1].lower()] var.set_index(object_name) return var if ns is None or object_name not in ns.objects: msg = u'No such object "%s"' % object_name if namespace_parts: msg = u'%s in %s' % (msg, u":".join(namespace_parts)) raise ScopeError(msg) return ns.objects[object_name]
def add_object(self, obj): """ Add the ``obj`` object to this symbol table. :param obj: The bound operand to be added. :type obj: :class:`Bind` :raises booleano.exc.ScopeError: If ``obj`` is already included or it already belongs to another symbol table. """ # Checking if it's safe to include the object: if obj.symbol_table: raise ScopeError(u"%s already belongs to %s" % (obj.global_name, obj.symbol_table)) if obj in self.objects or obj.symbol_table: raise ScopeError(u"An equivalent of %s is already defined in %s" % (obj, self)) # It's safe to include it! obj.symbol_table = self self.objects.add(obj)
def add_subtable(self, table): """ Include ``table`` in the child tables of this symbol table. :param table: The symbol table to be added. :type table: :class:`SymbolTable` :raises booleano.exc.ScopeError: If ``table`` is already included or it already belongs to another symbol table. """ # Checking if it's safe to include the sub-table: if table.symbol_table: raise ScopeError(u"%s already belongs to %s" % (table, table.symbol_table)) if table in self.subtables: raise ScopeError( u"An equivalent of %s is already available in %s" % (table, self)) # It's safe to include it! table.symbol_table = self self.subtables.add(table)