Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ast_extensions.py17
-rw-r--r--util/codegen.py6
2 files changed, 22 insertions, 1 deletions
diff --git a/util/ast_extensions.py b/util/ast_extensions.py
index 3335afb..d46bdb0 100644
--- a/util/ast_extensions.py
+++ b/util/ast_extensions.py
@@ -24,6 +24,23 @@
import ast
+class ExtraCode(ast.stmt):
+ """Adds extra content to a primitive needed in Python code, e.g.,
+ changes to the turtle (e.g., prim_turtle) require the addition of
+ turtle = turtles.get_active_turtle()
+ Extends the Python abstract grammar by the following: stmt
+ = ExtraContent(string text) | ... """
+
+ _fields = ('text')
+
+ def __init__(self, text="", lineno=1, col_offset=0):
+ """ text -- the textual content of the comment, i.e. everything
+ directly following the hashtag until the next newline """
+ self.text = text
+ self.lineno = lineno
+ self.col_offset = col_offset
+
+
class Comment(ast.stmt):
""" An inline comment, starting with a hashtag (#).
Extends the Python abstract grammar by the following:
diff --git a/util/codegen.py b/util/codegen.py
index 3785085..46184e7 100644
--- a/util/codegen.py
+++ b/util/codegen.py
@@ -35,7 +35,7 @@
Modified by Marion Zepf.
"""
from ast import *
-from ast_extensions import Comment
+from ast_extensions import Comment, ExtraCode
def to_source(node, indent_with=' ' * 4, add_line_information=False):
@@ -362,6 +362,10 @@ class SourceGenerator(NodeVisitor):
self.newline(node)
self.write('#' + str(node.text))
+ def visit_ExtraCode(self, node):
+ self.newline(node)
+ self.write(str(node.text))
+
# Expressions
def visit_Attribute(self, node):