summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/transformer.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-09-17 21:02:51 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-09-17 21:02:51 (GMT)
commit9dca36432e4526da9c5885e86782e7dfa5432c42 (patch)
treea30bc1744590e05b731eb077d1d261b544270ccf /Lib/compiler/transformer.py
parentc8ed18a4e3756f0cccbcddd10323ef536ad003ec (diff)
downloadcpython-9dca36432e4526da9c5885e86782e7dfa5432c42.zip
cpython-9dca36432e4526da9c5885e86782e7dfa5432c42.tar.gz
cpython-9dca36432e4526da9c5885e86782e7dfa5432c42.tar.bz2
API change:
compile() becomes replacement for builtin compile() compileFile() generates a .pyc from a .py both are exported in __init__ compiler.parse() gets optional second argument to specify compilation mode, e.g. single, eval, exec Add AbstractCompileMode as parent class and Module, Expression, and Interactive as concrete subclasses. Each corresponds to a compilation mode. THe AbstractCompileMode instances in turn delegate to CodeGeneration subclasses specialized for their particular functions -- ModuleCodeGenerator, ExpressionCodeGeneration, InteractiveCodeGenerator.
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r--Lib/compiler/transformer.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 3607af1..c2a3b96 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -42,8 +42,14 @@ def parseFile(path):
f.close()
return parse(src)
-def parse(buf):
- return Transformer().parsesuite(buf)
+def parse(buf, mode="exec"):
+ if mode == "exec" or mode == "single":
+ return Transformer().parsesuite(buf)
+ elif mode == "eval":
+ return Transformer().parseexpr(buf)
+ else:
+ raise ValueError("compile() arg 3 must be"
+ " 'exec' or 'eval' or 'single'")
def asList(nodes):
l = []