summaryrefslogtreecommitdiffstats
path: root/Demo/parser
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>1999-11-19 21:57:56 (GMT)
committerFred Drake <fdrake@acm.org>1999-11-19 21:57:56 (GMT)
commit995285e39211523e91f3582b3c8adca77164a873 (patch)
tree77df465c86cdbde28e97b9dff154c81fa32b5cc3 /Demo/parser
parentd81b1b0ffa741402ff92f23e6c452dc69534ad16 (diff)
downloadcpython-995285e39211523e91f3582b3c8adca77164a873.zip
cpython-995285e39211523e91f3582b3c8adca77164a873.tar.gz
cpython-995285e39211523e91f3582b3c8adca77164a873.tar.bz2
Moved all the imports to the top.
Use the methods on the AST object instead of module-level functions; these have been implemented for a couple of versions now, and are already used in the module documentation in preference to the functions.
Diffstat (limited to 'Demo/parser')
-rw-r--r--Demo/parser/example.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/Demo/parser/example.py b/Demo/parser/example.py
index 821cef0..2aa9ec2 100644
--- a/Demo/parser/example.py
+++ b/Demo/parser/example.py
@@ -5,10 +5,14 @@ section on using the parser module. Refer to the manual for a thorough
discussion of the operation of this code.
"""
+import os
+import parser
import symbol
import token
import types
+from types import ListType, TupleType
+
def get_docs(fileName):
"""Retrieve information from the parse tree of a source file.
@@ -17,12 +21,9 @@ def get_docs(fileName):
Name of the file to read Python source code from.
"""
source = open(fileName).read()
- import os
basename = os.path.basename(os.path.splitext(fileName)[0])
- import parser
ast = parser.suite(source)
- tup = parser.ast2tuple(ast)
- return ModuleInfo(tup, basename)
+ return ModuleInfo(ast.totuple(), basename)
class SuiteInfoBase:
@@ -112,8 +113,6 @@ class ModuleInfo(SuiteInfoBase, SuiteFuncInfo):
self._docstring = vars["docstring"]
-from types import ListType, TupleType
-
def match(pattern, data, vars=None):
"""Match `data' to `pattern', with variable extraction.
@@ -189,6 +188,3 @@ DOCSTRING_STMT_PATTERN = (
)))))))))))))))),
(token.NEWLINE, '')
))
-
-#
-# end of file