diff options
author | Marion <marion.zepf@gmail.com> | 2013-08-09 09:17:55 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-08-09 09:17:55 (GMT) |
commit | ceccfe5f3ff28e5d2c42fc1a56d80b43a680839a (patch) | |
tree | 81daf2a8040742483f1e3bdb5a4228da00b75dfa /TurtleArt/taprimitive.py | |
parent | 753be7616e141d656ebaeaf84651cb53e3fe7383 (diff) |
add Primitives for the 'if-then' and 'if-then-else' blocks
- Treat the list of all blocks attached to one 'flow' dock as one argument.
Diffstat (limited to 'TurtleArt/taprimitive.py')
-rw-r--r-- | TurtleArt/taprimitive.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 885b07b..4184d62 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -21,6 +21,8 @@ import ast from gettext import gettext as _ +#from ast_pprint import * # only used for debugging, safe to comment out + from tacanvas import TurtleGraphics from talogo import LogoCode from taturtle import (Turtle, Turtles) @@ -303,7 +305,7 @@ class Primitive(object): # TODO use new variable name in nested loops loop_ast = ast.For(target=ast.Name(id="i", ctx=ast.Store), iter=repeat_iter, - body=new_arg_asts[1:], + body=new_arg_asts[1], orelse=[]) return loop_ast else: @@ -318,10 +320,21 @@ class Primitive(object): raise ValueError("unknown loop controller: " + repr(controller)) loop_ast = ast.While(test=condition_ast, - body=new_arg_asts[1:], + body=new_arg_asts[1], orelse=[]) return loop_ast + # conditionals + elif self in (LogoCode.prim_if, LogoCode.prim_ifelse): + test = new_arg_asts[0] + body = new_arg_asts[1] + if len(new_arg_asts) > 2: + orelse = new_arg_asts[2] + else: + orelse = [] + if_ast = ast.If(test=test, body=body, orelse=orelse) + return if_ast + # standard operators elif self.func.__name__ in Primitive.STANDARD_OPERATORS: op = Primitive.STANDARD_OPERATORS[self.func.__name__] |