Commit 985669cd authored by Guido van Rossum's avatar Guido van Rossum

Add direct-parse mode (-p), and make it the default.

parent 1b062a5e
...@@ -109,16 +109,19 @@ def main(): ...@@ -109,16 +109,19 @@ def main():
global use_minidom global use_minidom
noVersionTest = use_minidom noVersionTest = use_minidom
macros = 0 macros = 0
compile = 1 compile = 0
parse = 1
try: try:
opts, args = getopt.getopt(sys.argv[1:], "Mcmnv") opts, args = getopt.getopt(sys.argv[1:], "Mcmnpv")
except getopt.error, msg: except getopt.error, msg:
sys.stderr.write("%s\n" % str(msg)) sys.stderr.write("%s\n" % str(msg))
sys.stderr.write("usage: driver.py [-M] [-c] [-m] [-n] [-v] [file]\n") sys.stderr.write(
"usage: driver.py [-M] [-c] [-m] [-n] [-p] [-v] [file]\n")
sys.stderr.write("-M -- force using minidom\n") sys.stderr.write("-M -- force using minidom\n")
sys.stderr.write("-c -- compiled mode (default)\n") sys.stderr.write("-c -- compiled mode\n")
sys.stderr.write("-m -- macro expansion only\n") sys.stderr.write("-m -- macro expansion only\n")
sys.stderr.write("-n -- turn of the Python 1.5.2 test\n") sys.stderr.write("-n -- turn of the Python 1.5.2 test\n")
sys.stderr.write("-p -- parse XML file directly (fastest, default)\n")
sys.stderr.write("-v -- visiting mode (slower)\n") sys.stderr.write("-v -- visiting mode (slower)\n")
sys.exit(2) sys.exit(2)
for o, a in opts: for o, a in opts:
...@@ -126,12 +129,20 @@ def main(): ...@@ -126,12 +129,20 @@ def main():
use_minidom = 1 use_minidom = 1
if o == '-c': if o == '-c':
compile = 1 compile = 1
parse = 0
if o == '-m': if o == '-m':
macros = 1 macros = 1
if not compile and not parse:
parse = 1
if o == '-n': if o == '-n':
noVersionTest = 1 noVersionTest = 1
if o == '-p':
parse = 1
compile = 0
if o == '-v': if o == '-v':
compile = 0 compile = 0
parse = 0
macros = 0
if not noVersionTest: if not noVersionTest:
if sys.version[:5] != "1.5.2": if sys.version[:5] != "1.5.2":
sys.stderr.write( sys.stderr.write(
...@@ -141,13 +152,17 @@ def main(): ...@@ -141,13 +152,17 @@ def main():
file = args[0] file = args[0]
else: else:
file = FILE file = FILE
doc = parsefile(file) if parse:
if macros or compile: it = compilefile(file)
it = compiletree(doc)
interpretit(it, tal=(not macros)) interpretit(it, tal=(not macros))
else: else:
doc = talizetree(doc) doc = parsefile(file)
printtree(doc) if compile:
it = compiletree(doc)
interpretit(it, tal=(not macros))
else:
doc = talizetree(doc)
printtree(doc)
def parsefile(file): def parsefile(file):
if use_minidom: if use_minidom:
...@@ -203,5 +218,11 @@ def interpretit(it, engine=None, stream=None, tal=1): ...@@ -203,5 +218,11 @@ def interpretit(it, engine=None, stream=None, tal=1):
engine = DummyEngine(macros) engine = DummyEngine(macros)
TALInterpreter(program, macros, engine, stream, wrap=0, tal=tal)() TALInterpreter(program, macros, engine, stream, wrap=0, tal=tal)()
def compilefile(file):
from TALParser import TALParser
p = TALParser()
p.parseFile(file)
return p.getCode()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment