[Python-checkins] CVS: /python/nondist/src/Compiler/compiler ast.py,1.7,1.8 transformer.py,1.7,1.8
Jeremy Hylton
jhylton@cnri.reston.va.us
Mon, 6 Mar 2000 13:50:51 -0500
Update of /projects/cvsroot//python/nondist/src/Compiler/compiler
In directory goon.cnri.reston.va.us:/home/jhylton/python/nondist/src/Compiler/compiler
Modified Files:
ast.py transformer.py
Log Message:
change node Classdef to Class
add doc string to transformer module
add two helper functions:
parse(buf) -> AST
parseFile(path) -> AST
Index: ast.py
===================================================================
RCS file: /projects/cvsroot//python/nondist/src/Compiler/compiler/ast.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** ast.py 2000/02/17 22:06:20 1.7
--- ast.py 2000/03/06 18:50:48 1.8
***************
*** 115,120 ****
return "Lambda(%s,%s,%s,%s)" % self._children[1:]
! class Classdef(Node):
! nodes['classdef'] = 'Classdef'
def __init__(self, name, bases, doc, code):
--- 115,120 ----
return "Lambda(%s,%s,%s,%s)" % self._children[1:]
! class Class(Node):
! nodes['class'] = 'Class'
def __init__(self, name, bases, doc, code):
***************
*** 123,130 ****
self.doc = doc
self.code = code
! self._children = ('classdef', name, bases, doc, code)
def __repr__(self):
! return "Classdef(%s,%s,%s,%s)" % self._children[1:]
class Pass(EmptyNode):
--- 123,130 ----
self.doc = doc
self.code = code
! self._children = ('class', name, bases, doc, code)
def __repr__(self):
! return "Class(%s,%s,%s,%s)" % self._children[1:]
class Pass(EmptyNode):
Index: transformer.py
===================================================================
RCS file: /projects/cvsroot//python/nondist/src/Compiler/compiler/transformer.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** transformer.py 2000/02/16 00:51:37 1.7
--- transformer.py 2000/03/06 18:50:48 1.8
***************
*** 1,15 ****
# Copyright 1997-1998 Greg Stein and Bill Tutt
#
- # transformer.py -- transforms Python parse trees
- #
- # Takes an input parse tree and transforms it into a higher-level parse
- # tree that is a bit more amenable to code generation. Essentially, it
- # simply introduces some additional semantics.
- #
# Written by Greg Stein (gstein@lyra.org)
# and Bill Tutt (rassilon@lima.mudlib.org)
# February 1997.
#
! # Support for Node subclasses written by
# Jeremy Hylton (jeremy@cnri.reston.va.us)
#
--- 1,19 ----
+ """Parse tree transformation module.
+
+ Transforms Python source code into an abstract syntax tree (AST)
+ defined in the ast module.
+
+ The simplest ways to invoke this module are via parse and parseFile.
+ parse(buf) -> AST
+ parseFile(path) -> AST
+ """
+
# Copyright 1997-1998 Greg Stein and Bill Tutt
#
# Written by Greg Stein (gstein@lyra.org)
# and Bill Tutt (rassilon@lima.mudlib.org)
# February 1997.
#
! # Support for Node subclasses written and other revisions by
# Jeremy Hylton (jeremy@cnri.reston.va.us)
#
***************
*** 84,93 ****
#
- """Parse tree transformation module.
-
- Exposes the Transformer class with a number of methods for returning a
- "cleansed AST" instead of the parse tree that the parser exposes.
- """
-
import ast
import parser
--- 88,91 ----
***************
*** 103,106 ****
--- 101,113 ----
from consts import OP_ASSIGN, OP_DELETE, OP_APPLY
+ def parseFile(path):
+ f = open(path)
+ src = f.read()
+ f.close()
+ return parse(src)
+
+ def parse(buf):
+ return Transformer().parsesuite(buf)
+
def asList(nodes):
l = []
***************
*** 263,267 ****
code = self.com_node(nodelist[-1])
! n = Node('classdef', name, bases, doc, code)
n.lineno = nodelist[1][2]
return n
--- 270,274 ----
code = self.com_node(nodelist[-1])
! n = Node('class', name, bases, doc, code)
n.lineno = nodelist[1][2]
return n
***************
*** 1192,1200 ****
]
- # Local Variables:
- # mode: python
- # indent-tabs-mode: nil
- # py-indent-offset: 2
- # py-smart-indentation: nil
- # End:
--- 1199,1201 ----