diff options
author | Marion <marion.zepf@gmail.com> | 2013-08-01 17:13:41 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-08-01 17:13:41 (GMT) |
commit | 9762cdd7b160ad3ac1a596114a7f0fc9e273837c (patch) | |
tree | 6787d8ff98e6a7956a403b92763e4ffa1584fe72 /TurtleArt/taexportpython.py | |
parent | 0942aecc5b6dcb4d4ba1e5de926a0943da25cc06 (diff) |
highlight faulty block if an error occurs during export
Diffstat (limited to 'TurtleArt/taexportpython.py')
-rw-r--r-- | TurtleArt/taexportpython.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 78a6592..b01e9c9 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -123,16 +123,23 @@ def _walk_action_stack(top_block, lc): value_ast = _value_to_ast(raw_value) return [value_ast] + def _get_prim(block): + prim = lc.get_prim_callable(block.primitive) + # fail gracefully if primitive is not a Primitive object + if not isinstance(prim, Primitive): + raise PyExportError(_("block is not exportable"), block=block) + return prim + + prim = _get_prim(block) + ast_list = [] arg_asts = [] - def _finish_off(block): + def _finish_off(block, prim=None): """ Convert block to an AST and add it to the ast_list. Raise a PyExportError on failure. """ - prim = lc.get_prim_callable(block.primitive) - # fail gracefully if primitive is not a Primitive object - if not isinstance(prim, Primitive): - raise PyExportError(_("block is not exportable"), block=block) + if prim is None: + prim = _get_prim(block) if prim.export_me: try: new_ast = prim.get_ast(*arg_asts) @@ -158,10 +165,11 @@ def _walk_action_stack(top_block, lc): continue elif not dock_queue and dock[0] == 'flow': # finish off this block - _finish_off(block) + _finish_off(block, prim) arg_asts = [] # next block block = conn + prim = _get_prim(block) dock_queue = block.docks[1:] conn_queue = block.connections[1:] else: @@ -177,7 +185,7 @@ def _walk_action_stack(top_block, lc): arg_asts.append(*new_arg_asts) # finish off last block - _finish_off(block) + _finish_off(block, prim) return ast_list |