Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cbe1f4d1
Commit
cbe1f4d1
authored
Jul 25, 2000
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
This script demonstrates use of the visitor interface of the compiler
package.
parent
849d5b99
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
Tools/compiler/demo.py
Tools/compiler/demo.py
+38
-0
No files found.
Tools/compiler/demo.py
0 → 100755
View file @
cbe1f4d1
#! /usr/bin/env python
"""Print names of all methods defined in module
This script demonstrates use of the visitor interface of the compiler
package.
"""
import
compiler
class
MethodFinder
:
"""Print the names of all the methods
Each visit method takes two arguments, the node and its current
scope. The scope is the name of the current class or None.
"""
def
visitClass
(
self
,
node
,
scope
=
None
):
self
.
visit
(
node
.
code
,
node
.
name
)
def
visitFunction
(
self
,
node
,
scope
=
None
):
if
scope
is
not
None
:
print
"%s.%s"
%
(
scope
,
node
.
name
)
self
.
visit
(
node
.
code
,
None
)
def
main
(
files
):
mf
=
MethodFinder
()
for
file
in
files
:
f
=
open
(
file
)
buf
=
f
.
read
()
f
.
close
()
ast
=
compiler
.
parse
(
buf
)
compiler
.
walk
(
ast
,
mf
)
if
__name__
==
"__main__"
:
import
sys
main
(
sys
.
argv
[
1
:])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment