diff options
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/compiler/ast.txt | 3 | ||||
-rw-r--r-- | Tools/compiler/astgen.py | 29 | ||||
-rw-r--r-- | Tools/compiler/regrtest.py | 2 |
3 files changed, 26 insertions, 8 deletions
diff --git a/Tools/compiler/ast.txt b/Tools/compiler/ast.txt index 6a990d4..a235b99 100644 --- a/Tools/compiler/ast.txt +++ b/Tools/compiler/ast.txt @@ -8,7 +8,8 @@ # = ... a default value for the node constructor (optional args) Module: doc*, node Stmt: nodes! -Function: name*, argnames*, defaults!, flags*, doc*, code +Decorators: nodes! +Function: decorators&, name*, argnames*, defaults!, flags*, doc*, code Lambda: argnames*, defaults!, flags*, code Class: name*, bases!, doc*, code Pass: 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 @@ class NodeInfo: 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 @@ def parse_spec(file): # 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(list): 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 Node: # an abstract base class 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(): diff --git a/Tools/compiler/regrtest.py b/Tools/compiler/regrtest.py index def07c2..50d06e7 100644 --- a/Tools/compiler/regrtest.py +++ b/Tools/compiler/regrtest.py @@ -47,6 +47,8 @@ def compile_files(dir): continue # make sure the .pyc file is not over-written os.chmod(source + "c", 444) + elif file == 'CVS': + pass else: path = os.path.join(dir, file) if os.path.isdir(path): |