summaryrefslogtreecommitdiffstats
path: root/Lib/dos_8x3/ast.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-26 18:33:32 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-26 18:33:32 (GMT)
commita8763e54ff25a226e50b281671189382fd3c324c (patch)
treebea9ea9a9f5bb33cbdfef607b4a8ce5e6197e98b /Lib/dos_8x3/ast.py
parent52a42fe9e706fb51ec608571c2b60e7694a5d0a2 (diff)
downloadcpython-a8763e54ff25a226e50b281671189382fd3c324c.zip
cpython-a8763e54ff25a226e50b281671189382fd3c324c.tar.gz
cpython-a8763e54ff25a226e50b281671189382fd3c324c.tar.bz2
Another batch of updates...
Diffstat (limited to 'Lib/dos_8x3/ast.py')
-rwxr-xr-xLib/dos_8x3/ast.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/Lib/dos_8x3/ast.py b/Lib/dos_8x3/ast.py
index 6f92bee..370cfe4 100755
--- a/Lib/dos_8x3/ast.py
+++ b/Lib/dos_8x3/ast.py
@@ -1,13 +1,13 @@
"""Object-oriented interface to the parser module.
-This module exports three classes which together provide an interface
+This module exports four classes which together provide an interface
to the parser module. Together, the three classes represent two ways
to create parsed representations of Python source and the two starting
data types (source text and tuple representations). Each class
provides interfaces which are identical other than the constructors.
The constructors are described in detail in the documentation for each
class and the remaining, shared portion of the interface is documented
-below. Briefly, the three classes provided are:
+below. Briefly, the classes provided are:
AST
Defines the primary interface to the AST objects and supports creation
@@ -23,6 +23,9 @@ FileSuiteAST
Convenience subclass of the `SuiteAST' class; loads source text of the
suite from an external file.
+Common Methods
+--------------
+
Aside from the constructors, several methods are provided to allow
access to the various interpretations of the parse tree and to check
conditions of the construct represented by the parse tree.
@@ -68,8 +71,8 @@ class AST:
This base class provides all of the query methods for subclass
objects defined in this module.
"""
- _p = __import__('parser') # import internally to avoid
- # namespace pollution at the
+ import parser # import internally to avoid
+ _p = parser # namespace pollution at the
# top level
_text = None
_code = None
@@ -84,7 +87,8 @@ class AST:
The tuple tree to convert.
The tuple-tree may represent either an expression or a suite; the
- type will be determined automatically.
+ type will be determined automatically. Line number information may
+ optionally be present for any subset of the terminal tokens.
"""
if type(tuple) is not type(()):
raise TypeError, 'Base AST class requires tuple parameter.'
@@ -93,11 +97,24 @@ class AST:
self._ast = self._p.tuple2ast(tuple)
self._type = (self._p.isexpr(self._ast) and 'expression') or 'suite'
- def tuple(self):
+ def list(self, line_info = 0):
+ """Returns a fresh list representing the parse tree.
+
+ line_info
+ If true, includes line number information for terminal tokens in
+ the output data structure,
+ """
+ return self._p.ast2list(self._ast, line_info)
+
+ def tuple(self, line_info = 0):
"""Returns the tuple representing the parse tree.
+
+ line_info
+ If true, includes line number information for terminal tokens in
+ the output data structure,
"""
if self._tupl is None:
- self._tupl = self._p.ast2tuple(self._ast)
+ self._tupl = self._p.ast2tuple(self._ast, line_info)
return self._tupl
def code(self):