PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.
diff --git a/Tools/compiler/astgen.py b/Tools/compiler/astgen.py
index 08d501b..4fe4bbe 100644
--- a/Tools/compiler/astgen.py
+++ b/Tools/compiler/astgen.py
@@ -154,19 +154,19 @@
else:
print >> buf, " return %s" % COMMA.join(clist)
else:
- print >> buf, " nodes = []"
- template = " nodes.%s(%sself.%s%s)"
+ print >> buf, " nodelist = []"
+ template = " nodelist.%s(%sself.%s%s)"
for name in self.argnames:
if self.argprops[name] == P_NONE:
tmp = (" if self.%s is not None:"
- " nodes.append(self.%s)")
+ " nodelist.append(self.%s)")
print >> buf, tmp % (name, name)
elif self.argprops[name] == P_NESTED:
print >> buf, template % ("extend", "flatten_nodes(",
name, ")")
elif self.argprops[name] == P_NODE:
print >> buf, template % ("append", "", name, "")
- print >> buf, " return tuple(nodes)"
+ print >> buf, " return tuple(nodelist)"
def _gen_repr(self, buf):
print >> buf, " def __repr__(self):"
@@ -208,7 +208,7 @@
# some extra code for a Node's __init__ method
name = mo.group(1)
cur = classes[name]
- return classes.values()
+ return sorted(classes.values(), key=lambda n: n.name)
def main():
prologue, epilogue = load_boilerplate(sys.argv[-1])
@@ -245,9 +245,9 @@
def flatten_nodes(list):
return [n for n in flatten(list) if isinstance(n, Node)]
-def asList(nodes):
+def asList(nodearg):
l = []
- for item in nodes:
+ for item in nodearg:
if hasattr(item, "asList"):
l.append(item.asList())
else:
@@ -274,6 +274,21 @@
class EmptyNode(Node):
pass
+class Expression(Node):
+ # Expression is an artificial node class to support "eval"
+ nodes["expression"] = "Expression"
+ def __init__(self, node):
+ self.node = node
+
+ def getChildren(self):
+ return self.node,
+
+ def getChildNodes(self):
+ return self.node,
+
+ def __repr__(self):
+ return "Expression(%s)" % (repr(self.node))
+
### EPILOGUE
klasses = globals()
for k in nodes.keys():