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():
global use_minidom
noVersionTest = use_minidom
macros = 0
compile = 1
compile = 0
parse = 1
try:
opts, args = getopt.getopt(sys.argv[1:], "Mcmnv")
opts, args = getopt.getopt(sys.argv[1:], "Mcmnpv")
except getopt.error, 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("-c -- compiled mode (default)\n")
sys.stderr.write("-c -- compiled mode\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("-p -- parse XML file directly (fastest, default)\n")
sys.stderr.write("-v -- visiting mode (slower)\n")
sys.exit(2)
for o, a in opts:
......@@ -126,12 +129,20 @@ def main():
use_minidom = 1
if o == '-c':
compile = 1
parse = 0
if o == '-m':
macros = 1
if not compile and not parse:
parse = 1
if o == '-n':
noVersionTest = 1
if o == '-p':
parse = 1
compile = 0
if o == '-v':
compile = 0
parse = 0
macros = 0
if not noVersionTest:
if sys.version[:5] != "1.5.2":
sys.stderr.write(
......@@ -141,13 +152,17 @@ def main():
file = args[0]
else:
file = FILE
doc = parsefile(file)
if macros or compile:
it = compiletree(doc)
if parse:
it = compilefile(file)
interpretit(it, tal=(not macros))
else:
doc = talizetree(doc)
printtree(doc)
doc = parsefile(file)
if compile:
it = compiletree(doc)
interpretit(it, tal=(not macros))
else:
doc = talizetree(doc)
printtree(doc)
def parsefile(file):
if use_minidom:
......@@ -203,5 +218,11 @@ def interpretit(it, engine=None, stream=None, tal=1):
engine = DummyEngine(macros)
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__":
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