[ZPT] CVS: Packages/TAL - driver.py:1.18

guido@digicool.com guido@digicool.com
Sat, 17 Mar 2001 07:25:15 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv4773

Modified Files:
	driver.py 
Log Message:
Add -s option to show the intermediate code, rather than executing it.



--- Updated File driver.py in package Packages/TAL --
--- driver.py	2001/03/17 03:38:21	1.17
+++ driver.py	2001/03/17 12:25:14	1.18
@@ -108,15 +108,17 @@
     versionTest = 1
     macros = 0
     mode = None
+    showcode = 0
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "hmnx")
+        opts, args = getopt.getopt(sys.argv[1:], "hxmns")
     except getopt.error, msg:
         sys.stderr.write("\n%s\n" % str(msg))
         sys.stderr.write(
-            "usage: driver.py [-h|-x] [-m] [-n] [file]\n")
+            "usage: driver.py [-h|-x] [-m] [-n] [s] [file]\n")
         sys.stderr.write("-h/-x -- HTML/XML input (default auto)\n")
         sys.stderr.write("-m -- macro expansion only\n")
         sys.stderr.write("-n -- turn off the Python 1.5.2 test\n")
+        sys.stderr.write("-s -- print intermediate code\n")
         sys.exit(2)
     for o, a in opts:
         if o == '-h':
@@ -127,6 +129,8 @@
             versionTest = 0
         if o == '-x':
             mode = "xml"
+        if o == '-s':
+            showcode = 1
     if not versionTest:
         if sys.version[:5] != "1.5.2":
             sys.stderr.write(
@@ -137,7 +141,8 @@
     else:
         file = FILE
     it = compilefile(file, mode)
-    interpretit(it, tal=(not macros))
+    if showcode: showit(it)
+    else: interpretit(it, tal=(not macros))
 
 def interpretit(it, engine=None, stream=None, tal=1):
     from TALInterpreter import TALInterpreter
@@ -162,6 +167,10 @@
         p = TALParser()
     p.parseFile(file)
     return p.getCode()
+
+def showit(it):
+    from pprint import pprint
+    pprint(it)
 
 if __name__ == "__main__":
     main()