def commit(self): if self.mode == 'ns': #ns = namespace.current().find_namespace(self.sym) ns = namespace.resolve(self.sym) namespace.current().namespaces.update(ns.namespaces) namespace.current().symbols.update(ns.symbols) for ftoks, fdic in ns.functions.iteritems(): for fpar, fsta in fdic.iteritems(): namespace.current().add_func(ftoks, fpar, fsta) else: x = namespace.resolve(self.sym) if x is None: print "COULDN'T RESOLVE", self.sym raise InvalidStatement(self.text) #print self.sym name = self.sym[-1][1] if x[0] == namespace.VAR: namespace.current().add_var(name, **x[1]) elif x[0] == namespace.TYPE: namespace.current().add_type(name, **x[1])
def resolve(self, x): return namespace.resolve(x)
def hook_CHECK_EXISTS(self, ast): x = namespace.resolve(ast.tokens) if x is None: #print "COULDN'T RESOLVE", ast.tokens raise InvalidStatement(self.text)
def hook_WRITE(self, ast): x = namespace.resolve(ast.tokens) if x is None or x[0] != 'var': #print "CAN'T WRITE", x, ast raise InvalidStatement(self.text)
def hook_READ(self, ast): x = namespace.resolve(ast.tokens) if x is not None and x[0] not in ('var', 'func'): # probably a type print "CAN'T READ", x, ast raise InvalidStatement(self.text)
def resolve(self, ast): return namespace.resolve(ast.tokens)