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 21:56:47 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-11 21:56:47 (GMT)
commit8913f29678d54cc3cbf6cbcb612712c805dd9f35 (patch)
tree6503356f3cc0e8241a235c2988749ef19e72268b
parent7ab3e228be2762ec9fe594931f8448e1d8b16344 (diff)
avoid adding a type prefix to the value of value blocks when exporting them
-rw-r--r--TurtleArt/tablock.py24
-rw-r--r--TurtleArt/taexportpython.py2
2 files changed, 18 insertions, 8 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index f44e3dc..4c0f207 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -286,9 +286,12 @@ class Block:
media, etc.) """
return self.primitive is None and self.values
- def get_value(self):
- """ Return the value stored in this value block """
+ def get_value(self, add_type_prefix=True):
+ """ Return the value stored in this value block
+ add_type_prefix -- prepend a prefix to indicate the type of the
+ 'raw' value """
# TODO what error to raise if this is not a value block?
+ result = ''
if self.name == 'number':
try:
return float(self.values[0])
@@ -296,21 +299,28 @@ class Block:
return float(ord(self.values[0][0]))
elif (self.name == 'string' or
self.name == 'title'): # deprecated block
+ if add_type_prefix:
+ result = '#s'
if isinstance(self.values[0], (float, int)):
if int(self.values[0]) == self.values[0]:
self.values[0] = int(self.values[0])
- return '#s' + str(self.values[0])
+ result += str(self.values[0])
else:
- return '#s' + self.values[0]
+ result += self.values[0]
elif self.name in PREFIX_DICTIONARY:
+ if add_type_prefix:
+ result = PREFIX_DICTIONARY[self.name]
if self.values[0] is not None:
- return PREFIX_DICTIONARY[self.name] + str(self.values[0])
+ result += str(self.values[0])
else:
- return PREFIX_DICTIONARY[self.name] + 'None'
+ result += 'None'
elif self.name in media_blocks_dictionary:
- return '#smedia_' + self.name.upper()
+ if add_type_prefix:
+ result = '#smedia_'
+ result += self.name.upper()
else:
return None
+ return result
def highlight(self):
""" We may want to highlight a block... """
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index 8be59bf..0816d9f 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -128,7 +128,7 @@ def _walk_action_stack(top_block, lc):
# value blocks don't have a primitive
if block.is_value_block():
- raw_value = block.get_value()
+ raw_value = block.get_value(add_type_prefix=False)
value_ast = value_to_ast(raw_value)
if value_ast is not None:
return [value_ast]