Action.Child: Handle calling the definition.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 21 Apr 2010 08:24:21 +0000 (01:24 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 21 Apr 2010 08:24:21 +0000 (01:24 -0700)
If; Add __repr__.

bulletml/impl.py
bulletml/parser.py

index f0e8964d806351cd9a2e876db194730da44bc4f9..d6753e3aafb78a3c778868fe1fecd72156138970 100644 (file)
@@ -48,7 +48,8 @@ class Action(object):
         return "%s(pc=%r, actions=%r)" % (
             type(self).__name__, self.pc, self.actions)
 
-    def Child(self, actions, params, rank, repeat=1):
+    def Child(self, action, params, rank, repeat=1):
+        actions, params = action(params, rank)
         return type(self)(self, actions, params, rank, repeat)
 
     def vanish(self):
index c8bc990b105bfab652326be334a7db4b0be6a820..aee4f90024b034de12ee656895b10fbb7aef6aa6 100644 (file)
@@ -367,8 +367,7 @@ class Repeat(object):
 
     def __call__(self, owner, action, params, rank, created):
         repeat = self.times(params, rank)
-        actions, params = self.action(params, rank)
-        child = action.Child(actions, params, rank, repeat)
+        child = action.Child(self.action, params, rank, repeat)
         owner.replace(action, child)
         child.step(owner, created)
         return True
@@ -422,11 +421,18 @@ class If(object):
             branch = self.else_
 
         if branch:
-            actions, params = branch(params, rank)
-            child = action.Child(actions, params, rank)
+            child = action.Child(branch, params, rank)
             owner.replace(action, child)
             child.step(owner, created)
             return True
+
+    def __repr__(self):
+        if self.else_:
+            return "%s(%r, then=%r, else_=%r)" % (
+                type(self).__name__, self.cond, self.then, self.else_)
+        else:
+            return "%s(%r, then=%r)" % (
+                type(self).__name__, self.cond, self.then)
         
 class Accel(object):
     """Accelerate over some time."""