def testLoop(self): from pymud.mob import Mob finish(interpret("""loop { say forever break } """,Mob(commands={'say':say,'break':breakCommand},variables={})))
def visitIfStatement(self,node,*args): yield finish(self.visit(node.condition)) if node.condition.value in self.conditions and\ self.conditions[node.condition.value]: call = self.visit(node.script) while step(call): yield
def visitHelpStatement(self,node,*args): yield finish(self.visit(node.command)) commandName = node.command.value if commandName in self.commands: self.instance.sendMessage("help",name=commandName,help=self.commands[commandName].__doc__) else: self.instance.sendMessage("invalidcommand",name=commandName)
def run(self,n=1): self.tick += n for queue in self.itemQueues.keys(): if self.tick % queue == 0: if queue in self.itemIterators and self.itemIterators[queue]: finish(self.itemIterators[queue]) self.itemIterators[queue] = None self.itemIterators[queue] = self.runItemQueue(queue) for queue,iterator in self.itemIterators.iteritems(): step(iterator)
def testStrings(self): from pymud.mob import Mob finish(interpret("""hello there\n""",Mob(commands={},variables={}))) finish(interpret("""hello there line 2 line 3 variable $var """,Mob(commands={},variables={'var':5}))) call = interpret("""hello there line 2 line 3 variable $var """,Mob(commands={},variables={'var':5})) for x in xrange(10): print "%s:" % x step(call)
def visitExpressionStatement(self,node,*args): """Handles the command statement case and the print statement case""" yield command = node.expressions[0] finish(self.visit(command)) if command.value in self.commands: for expression in node.expressions[1:]: finish(self.visit(expression)) func = self.commands[command.value] arguments = map(lambda x: x.value,node.expressions[1:]) if hasattr(func,'im_self') and func.im_self: call = func(*arguments) else: call =func(*[self.instance] + arguments) if isinstance(call,GeneratorType): while step(call): yield else: for expression in node.expressions[1:]: finish(self.visit(expression)) self.instance.default(map(lambda x: str(x.value),node.expressions))
def syncAll(self): if not self.writeBackIterator: self.writeBackIterator = self.partialSync() finish(self.writeBackIterator) self.db.dict.sync()
def visitAssign(self,node,*args): yield finish(self.visit(node.variable)) for symbol in node.expression: finish(self.visit(symbol)) self.instance.variables[str(node.variable.value)] = " ".join(map(lambda x:str(x.value),node.expression))
def testHelp(self): from pymud.mob import Mob finish(interpret("""? say """,Mob(commands={'say':say,'break':breakCommand},variables={})))
def testIf(self): from pymud.mob import Mob finish(interpret("""if alive { say i am alive } """,Mob(commands={'say':say},variables={})))
def testCommand(self): from pymud.mob import Mob finish(interpret("""say hello\n""",Mob(commands={'say':say},variables={})))
def test(self): def a(rule,o,result): return iter(xrange(5)) o = Struct() call = SteppableRule(Pass,a)(o) finish(call)