]> granicus.if.org Git - python/commitdiff
Small fixes in Parser/asdl.py - no change in functionality.
authorEli Bendersky <eliben@gmail.com>
Thu, 26 Sep 2013 13:31:32 +0000 (06:31 -0700)
committerEli Bendersky <eliben@gmail.com>
Thu, 26 Sep 2013 13:31:32 +0000 (06:31 -0700)
1. Make it work when invoked directly from the command-line. It was failing
   due to a couple of stale function/class usages in the __main__ section.
2. Close the parsed file in the parse() function after opening it.

Parser/asdl.py

index 7df76c0e38f61a3ae9c0c2cf9cd78e3a3686b889..25987b8659847639992b1f96a8ed2a60e45325cd 100644 (file)
@@ -16,8 +16,9 @@ import traceback
 
 import spark
 
-def output(string):
-    sys.stdout.write(string + "\n")
+def output(*strings):
+    for s in strings:
+        sys.stdout.write(str(s) + "\n")
 
 
 class Token(object):
@@ -397,7 +398,8 @@ def parse(file):
     scanner = ASDLScanner()
     parser = ASDLParser()
 
-    buf = open(file).read()
+    with open(file) as f:
+       buf = f.read()
     tokens = scanner.tokenize(buf)
     try:
         return parser.parse(tokens)
@@ -428,4 +430,4 @@ if __name__ == "__main__":
             output("Check failed")
         else:
             for dfn in mod.dfns:
-                output(dfn.type)
+                output(dfn.name, dfn.value)