From 3ff08dcad6a5b25c170631646bef42da9aef2010 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 15 Jun 2012 21:16:26 +0000 Subject: fix problem with nested forever/while/until --- diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index e935ea3..3037bb5 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -194,9 +194,15 @@ class LogoCode: for b in blocks: b.unhighlight() + # Hidden macro expansions for b in blocks: - # Hidden macro expansions - if b.name in ['while', 'until', 'forever']: + if b.name in ['while', 'until']: + action_blk, new_blocks = self._expand_forever(b, blk, blocks) + blocks = new_blocks[:] + if b == blk: + blk = action_blk + for b in blocks: + if b.name in ['forever']: action_blk, new_blocks = self._expand_forever(b, blk, blocks) blocks = new_blocks[:] if b == blk: @@ -255,11 +261,10 @@ class LogoCode: if len(dock) > 4: # There could be a '(', ')', '[' or ']'. code.append(dock[4]) if blk.primitive is not None: # make a tuple (prim, blk) - # special case: expand 'while' and 'until' primitives - try: + if blk in self.tw.block_list.list: code.append((blk.primitive, self.tw.block_list.list.index(blk))) - except ValueError: + else: code.append(blk.primitive) # Hidden block elif len(blk.values) > 0: # Extract the value from content blocks. if blk.name == 'number': @@ -850,11 +855,11 @@ class LogoCode: inflow.connections[i] = action_blk else: i = None + j = None if outflow is not None: - j = outflow.connections.index(b) - outflow.connections[j] = action_blk - else: - j = None + if b in outflow.connections: + j = outflow.connections.index(b) + outflow.connections[j] = action_blk if until_blk and whileflow is not None: action_first.connections.append(inflow) -- cgit v0.9.1