mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
c8ed18a4e3
commit
9dca36432e
6 changed files with 218 additions and 20 deletions
|
@ -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 = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue