diff options
author | Marion <marion.zepf@gmail.com> | 2013-08-03 11:20:01 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-08-03 11:20:01 (GMT) |
commit | e9db4dfee7b8faec0728593229dc73be7c692c2f (patch) | |
tree | 843d3135b8ef7d3decf2906602026d3a8e78976e /TurtleArt/taexportpython.py | |
parent | 86693c65ae0d70471131c6cdfbefbcbf87411c55 (diff) |
add Primitives for the 'pen up' and 'pen down' commands
- when converting a Primitive to an AST, convert all its constant arguments
Diffstat (limited to 'TurtleArt/taexportpython.py')
-rw-r--r-- | TurtleArt/taexportpython.py | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 809679d..ad94a90 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -24,12 +24,13 @@ import ast from gettext import gettext as _ from os import linesep import re +import traceback import util.codegen as codegen #from ast_pprint import * # only used for debugging, safe to comment out from talogo import LogoCode -from taprimitive import (Primitive, PyExportError) +from taprimitive import (Primitive, PyExportError, value_to_ast) from tautils import (debug_output, find_group, find_top_block) @@ -128,7 +129,7 @@ def _walk_action_stack(top_block, lc): # value blocks are don't have a primitive if block.is_value_block(): raw_value = block.get_value() - value_ast = _value_to_ast(raw_value) + value_ast = value_to_ast(raw_value) return [value_ast] def _get_prim(block): @@ -152,6 +153,7 @@ def _walk_action_stack(top_block, lc): try: new_ast = prim.get_ast(*arg_asts) except ValueError: + traceback.print_exc() raise PyExportError(_("error while exporting block"), block=block) if isinstance(new_ast, (list, tuple)): @@ -198,16 +200,6 @@ def _walk_action_stack(top_block, lc): return ast_list -def _value_to_ast(value): - """ Turn a value (integer, float, string, media, etc.) into an AST """ - # TODO media - if isinstance(value, (int, float)): - return ast.Num(value) - elif isinstance(value, basestring): - return ast.Str(value) - else: - raise ValueError("unknown type of raw value: " + repr(type(value))) - def _make_identifier(name): """ Turn name into a Python identifier name by replacing illegal characters """ |