Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-08-11 22:25:20 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-11 22:25:20 (GMT)
commit41e58dde24b5a93496edf30b35ff963fc53d48b9 (patch)
tree51c40cc5707222d0c37752fe8f29090102b90caa
parent52cef114510a08b3fc89a974ad6ee8bfb39e5dae (diff)
construct proper ASTs for type conversion
-rw-r--r--TurtleArt/taprimitive.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 8171c43..baaa9e0 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -361,15 +361,9 @@ class Primitive(object):
% (str(self.func.__func__.__name__),
len(new_arg_asts)))
+ # type conversion
elif self == Primitive.convert_for_cmp:
- # remove the 'convert_to_ast' keyword argument
- my_kwarg_asts = {}
- for (key, value) in new_kwarg_asts.iteritems():
- if key != 'convert_to_ast':
- my_kwarg_asts[key] = value
- return Primitive.convert_for_cmp(*new_arg_asts,
- convert_to_ast=True,
- **my_kwarg_asts)
+ return Primitive.convert_for_cmp(*new_arg_asts, **new_kwarg_asts)
# identity
elif self == Primitive.identity:
@@ -630,15 +624,25 @@ class Primitive(object):
return not arg
@staticmethod
- def convert_for_cmp(value, decimal_point='.', convert_to_ast=False):
- """ Convert value such that it can be compared to something else.
+ def convert_for_cmp(value, decimal_point='.'):
+ """ Convert value such that it can be compared to something else. If
+ value is an AST, another AST is wrapped around it to represent the
+ conversion, e.g.,
+ Str(s='a') -> Call(func=Name('ord'), args=[Str(s='a')])
1. Convert a string containing a number into a float.
2. Convert a single character to its ASCII integer value.
3. Return all other values unchanged. """
converted = None
conversion_ast = None
- if convert_to_ast:
- value_ast = value_to_ast(value)
+ convert_to_ast = False
+ if isinstance(value, ast.AST):
+ convert_to_ast = True
+ value_ast = value
+ value = None
+ if isinstance(value_ast, ast.Str):
+ value = value_ast.s
+ if isinstance(decimal_point, ast.Str):
+ decimal_point = decimal_point.s
if isinstance(value, basestring):
# 1. string containing a number