<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/emacs/flyparse/ADriver.java</filename>
    </added>
    <added>
      <filename>src/emacs/flyparse/FileWalker.java</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -33,7 +33,7 @@ end
 
 
 AS3_TARGET = &quot;../bin/.as3&quot;
-DRIVER_SOURCE = [&quot;src/emacs/flyparse/as3/FileWalker.java&quot;, &quot;src/emacs/flyparse/as3/AS3Driver.java&quot;]
+DRIVER_SOURCE = [&quot;../src/emacs/flyparse/FileWalker.java&quot;, &quot;src/emacs/flyparse/as3/AS3Driver.java&quot;]
 FLYPARSE_CORE_SOURCE = FileList[&quot;../src/**/*.java&quot;]
 file AS3_TARGET =&gt; PARSER_TARGETS + DRIVER_SOURCE + FLYPARSE_CORE_SOURCE do
   sh &quot;javac #{JAVAC_OPTIONS.join(&quot; &quot;)} #{(PARSER_TARGETS + DRIVER_SOURCE).join(&quot; &quot;)} -d ../bin&quot;</diff>
      <filename>as3/Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -25,21 +25,11 @@ import java.util.Collection;
 import java.util.Vector;
 import java.util.regex.*;
 
-public class AS3Driver{
-    
-    /* A helper for debugging. */	 
-    public static void printAllTokens(Lexer lex){
-	CommonToken t  = (CommonToken)lex.nextToken();
-	while(t.getType() != Token.EOF){
-	    System.out.println(t);
-	    t = (CommonToken)lex.nextToken();
-	}
-	lex.reset();
-    }
-
+public class AS3Driver extends ADriver{
 
     public static void main(String[] args) throws Exception {
 	BufferedWriter bout;
+	ADriver driver = new AS3Driver();
 	if(args[0].equals(&quot;-f&quot;)){ 
 	    if(args.length == 3){// -f input output
 		bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[2])), 512);
@@ -47,65 +37,34 @@ public class AS3Driver{
 	    else{ // -f input 
 		bout = new BufferedWriter(new OutputStreamWriter(System.out), 512);
 	    }
-	    processSingleFile(new File(args[1]), bout);
+	    driver.processSingle(new File(args[1]), bout);
 	}
 	else if(args[0].equals(&quot;-l&quot;) &amp;&amp; args.length &gt;= 3) { // -l output [dir dir dir....]
 	    bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[1])), 512);
 	    Vector&lt;File&gt; files = new Vector&lt;File&gt;();
 	    for(int i = 2; i &lt; args.length; i++){
-		files.addAll(FileWalker.listFiles(new File(args[i]), Pattern.compile(&quot;\\.as$&quot;), true));
+		files.addAll(FileWalker.listFiles(new File(args[i]), Pattern.compile(&quot;[\\\\/][A-Z][a-zA-Z0-9]+\\.as$&quot;), true));
 	    }
-	    System.out.println(&quot;Found &quot; + files.size() + &quot; files. Parsing..&quot;);
-	    processAll(files, bout);
+	    driver.processAll(files, bout);
 	}
     }
 
 
-    private static void processSingleFile(File file, BufferedWriter bout) throws Exception{
-	try{
-	    bout.write(&quot;(setq tree '&quot;);
-	    writeTreeForFile(file, bout);
-	    bout.write(&quot;)&quot;);
-	}
-	catch(IOException e){
-	}
-	bout.flush();
-    }
-
-
-    private static void processAll(Vector&lt;File&gt; files, BufferedWriter bout) throws Exception{
-	Pattern p = Pattern.compile(&quot;\\\\&quot;);
-	int count = 0;
-	for(File file : files){
-	    Matcher matcher = p.matcher(file.getCanonicalPath());
-	    String path = matcher.replaceAll(&quot;/&quot;);
-	    bout.write(&quot;(puthash \&quot;&quot;);
-	    bout.write(path);
-	    bout.write(&quot;\&quot; '&quot;);
-	    writeTreeForFile(file, bout);
-	    bout.write(&quot; flyparse-loading-tree-cache)\n&quot;);
-	    count++;
-	}
-	System.out.println(&quot;Parsed &quot; + count + &quot; files.&quot;);
-	bout.flush();
-    }
-
-
-    private static void writeTreeForFile(File file, BufferedWriter bout)  throws Exception {
+    protected void processFile(File file, BufferedWriter bout)  throws Exception{
 	SanitizedFileStream chars = new SanitizedFileStream(file.getPath());
 	AS3Lexer lex = new AS3Lexer(chars);
 	CommonTokenStream tokens = new CommonTokenStream(lex);
 	AS3Parser parser = new AS3Parser(tokens);
 	parser.setTreeAdaptor(new FlyparseTreeAdaptor());
-// 	try{
+ 	try{
 	    AS3Parser.compilationUnit_return ret = parser.compilationUnit();
 	    FlyparseTree tree = (FlyparseTree)ret.getTree();
 	    tree.prepareTree();	
 	    tree.writeTo(bout);
-// 	}
-// 	catch(Exception e){
-// 	    bout.write(&quot;()&quot;);
-// 	}
+ 	}
+ 	catch(Exception e){
+	    throw e;
+ 	}
     }
-    
+
 }
\ No newline at end of file</diff>
      <filename>as3/src/emacs/flyparse/as3/AS3Driver.java</filename>
    </modified>
    <modified>
      <diff>@@ -156,11 +156,23 @@
   &quot;Return command list of form '(cmd arg1 arg2 arg3)&quot;
   (append (flyparse-cmd-for-file-type file-name) '(&quot;-f&quot;)))
 
-(defun flyparse-make-recursive-cmd (directory-name result-file-name)
+(defun flyparse-make-recursive-cmd (directory-names result-file-name)
   &quot;Return command list of form '(cmd arg1 arg2 arg3)&quot;
   (error &quot;No default recursive parse command&quot;))
 
 
+(defun flyparse-cmd-for-file-type (file-name &amp;optional cmd-list)
+  &quot;Return a command list appropriate to the file-type.&quot;
+  (let* ((cmd-list (or cmd-list flyparse-file-type-commands))
+	 (regex (first (first cmd-list)))
+	 (cmd (rest (first cmd-list))))
+    (or
+     (if (string-match regex file-name) 
+	 cmd)
+     (if (not (null (rest cmd-list))) 
+	 (flyparse-cmd-for-file-type file-name (rest cmd-list))))))
+
+
 (defun flyparse-has-subtree-of-type-p (tree type)
   &quot;Does this 'tree' have a subtree of type 'type'?&quot;
   (flyparse-depth-first-find tree
@@ -373,27 +385,67 @@
 		     (null file-pattern))
 		 (funcall func path tree))) flyparse-tree-cache))
 
-(defun flyparse-cache-all (dir file-pattern cmd-maker)
-  &quot;Recursively iterate through files in 'dir' and cache the parse-tree 
-   for each file whose full name matches the 'file-pattern' regex.&quot;
-  (let ((counter 0))
-    (flyparse-walk-path
-     dir
-     (lambda (ea-dir ea-file)
-       (if (string-match file-pattern (concat ea-dir ea-file))
-	   (let* ((file-path (expand-file-name (concat ea-dir ea-file)))
-		  (tree (condition-case err
-			    (flyparse-block-and-load-tree-from-file file-path cmd-maker)
-			  (error (progn
-				   (message &quot;Failed to parse %s&quot; file-path)
-				   nil)
-				 ))))
-	     (if tree
-		 (progn
-		   (flyparse-cache-tree tree file-path)
-		   (message &quot;Cached tree for %s&quot; file-path)
-		   (incf counter)))))))
-    (message &quot;Finished caching %s files.&quot; counter)))
+(defun flyparse-cache-all (dirs)
+  &quot;Use the recursive parsing command to to parse all files, in any of dirs, and
+   cache their trees.&quot;
+  (let* ((output-file-name (make-temp-file &quot;flyparse-cache-all_&quot; nil &quot;.as&quot;))
+	 (parser-cmd (funcall flyparse-recursive-cmd-maker 
+			      dirs 
+			      output-file-name))
+	 (cmd (first parser-cmd))
+	 (args (rest parser-cmd)))
+    (condition-case err
+	(let ((proc (apply 'start-process &quot;*flyparse-proc*&quot; &quot;*flyparse-cache-all-progress*&quot; cmd args)))
+	  (flyparse-log 2 &quot;Created cache-all process %d, command=%s, dir=%s&quot; 
+			(process-id proc) 
+			(process-command proc)
+			default-directory)
+	  (process-put proc 'output-file-name output-file-name)
+	  (set-process-sentinel proc 'flyparse-cache-all-process-sentinel)
+	  (message &quot;Parse started...&quot;)
+	  )
+      (error
+       (let* ((err-str (format &quot;Failed to launch parser process '%s' with args %s: %s&quot;
+			       cmd args (error-message-string err))))
+	 (flyparse-log 0 err-str)
+	 (delete-file output-file-name)
+	 )))))
+
+(defun flyparse-cache-all-process-sentinel (process event)
+  &quot;Sentinel for flyparse buffers. Called automatically 
+   when external parser process finishes.&quot;
+  (when (memq (process-status process) '(signal exit))
+    (let* ((exit-status       (process-exit-status process))
+	   (command           (process-command process))
+	   (proc-buffer       (process-buffer process))
+	   (proc-id           (process-id process))
+	   (output-file-name  (process-get process 'output-file-name))
+	   (count  0))
+      (flyparse-log 3 &quot;Flyparse process %d exited with code %d&quot; proc-id exit-status)
+      (delete-process process)
+      (condition-case err
+	  (progn
+	    (if (eq exit-status 0)
+		(let ((flyparse-loading-tree-cache (make-hash-table :test 'equal)))
+		  ;; Load the parse tree...
+		  (load output-file-name nil t)
+		  (maphash (lambda (path tree)
+			     (if (and path tree)
+				 (progn
+				   (puthash path tree flyparse-tree-cache)
+				   (incf count))))
+			   flyparse-loading-tree-cache)
+		  (flyparse-log 2 &quot;Finished caching %d trees.&quot; count)
+		  (message &quot;Finished parsing %d files.&quot; count))
+	      (error &quot;Non-Zero exit status.&quot;))
+	    (delete-file output-file-name)
+	    )
+	(error
+	 (let ((err-str (format &quot;Flyparse cache-all failed: %s: %s&quot; output-file-name (error-message-string err))))
+	   (flyparse-report-status &quot;Failed&quot; &quot;&quot;)
+	   (flyparse-log 0 err-str)
+	   (delete-file output-file-name)
+	   ))))))
 
 
 (defun flyparse-write-cached-trees (dir-path)
@@ -498,7 +550,7 @@
 
 
 (defun flyparse-save-buffer-in-file (file-name)
-  &quot;Save buffer to temp file. Use unix file coding:
+  &quot;Save current buffer to file-name. Use unix file coding:
    (NO CARRIAGE RETURNS (they will screw up the 
    stream index information))&quot;
   (save-restriction
@@ -509,28 +561,18 @@
   (flyparse-log 3 &quot;Saved buffer %s in file %s.&quot; (buffer-name) file-name))
 
 
-(defun flyparse-temp-parser-output-name (source-file-name)
+(defun flyparse-make-temp-parser-output-file (source-file-name)
   &quot;For the given filename, return the name of the file to which the external parser process should
    write the parser tree.&quot;
-  (let* ((postfix &quot;flyparse_tree&quot;)
-	 (extension (file-name-extension source-file-name)))
-    (concat  (file-name-sans-extension source-file-name) &quot;_&quot; postfix &quot;.&quot; extension)))
+  (let* ((extension (file-name-extension source-file-name)))
+    (make-temp-file &quot;flyparse_parser_output&quot; nil &quot;.el&quot;)))
 
 
-(defun flyparse-temp-buffer-copy-file-name (source-file-name)
-  &quot;Return the name of the file to which the given filename should be written for the 
+(defun flyparse-make-temp-buffer-copy-file (source-file-name)
+  &quot;Return the name of the temporary file to which the given filename should be written for the 
    external parser-process to consume.&quot;
-  (let* ((postfix &quot;flyparse&quot;)
-	 (extension (file-name-extension source-file-name)))
-    (concat  (file-name-sans-extension source-file-name) &quot;_&quot; postfix &quot;.&quot; extension)))
-
-
-(defun flyparse-create-temp-buffer-copy ()
-  &quot;Make a temporary copy of the current buffer, 
-   save its name in buffer data and return the name.&quot;
-  (let*  ((temp-buffer-copy-name  (flyparse-temp-buffer-copy-file-name buffer-file-name)))
-    (flyparse-save-buffer-in-file temp-buffer-copy-name)
-    (flyparse-log 3 &quot;Create-temp-inplace: file=%s temp=%s.&quot; buffer-file-name temp-buffer-copy-name)))
+  (let* ((extension (file-name-extension source-file-name)))
+    (make-temp-file &quot;flyparse_buffer_copy&quot; nil (concat &quot;.&quot; extension))))
 
 
 (defun flyparse-safe-delete-file (file-name)
@@ -538,33 +580,18 @@
     (delete-file file-name)
     (flyparse-log 3 &quot;Deleted file %s&quot; file-name)))
 
-(defun flyparse-cleanup-temp-files (source-file-name)
-  &quot;Cleanup temporary files.&quot;
-  (flyparse-safe-delete-file (flyparse-temp-buffer-copy-file-name source-file-name))
-  (flyparse-safe-delete-file (flyparse-temp-parser-output-name source-file-name)))
-
-
-(defun flyparse-cmd-for-file-type (file-name &amp;optional cmd-list)
-  &quot;Return a command list appropriate to the file-type.&quot;
-  (let* ((cmd-list (or cmd-list flyparse-file-type-commands))
-	 (regex (first (first cmd-list)))
-	 (cmd (rest (first cmd-list))))
-    (or
-     (if (string-match regex file-name) 
-	 cmd)
-     (if (not (null (rest cmd-list))) 
-	 (flyparse-cmd-for-file-type file-name (rest cmd-list))))))
-
 
 (defun flyparse-start-parse ()
   &quot;Start a flyparse parse on current buffer.&quot;
   (interactive)
-  (let* ((parser-cmd (funcall flyparse-single-file-cmd-maker
-			      (flyparse-temp-buffer-copy-file-name buffer-file-name)
-			      (flyparse-temp-parser-output-name buffer-file-name)))
+  (let* ((temp-copy-file-name (flyparse-make-temp-buffer-copy-file buffer-file-name))
+	 (output-file-name (flyparse-make-temp-parser-output-file buffer-file-name))
+	 (parser-cmd (funcall flyparse-single-file-cmd-maker
+			      temp-copy-file-name
+			      output-file-name))
 	 (cmd (first parser-cmd))
 	 (args (rest parser-cmd)))
-    (flyparse-create-temp-buffer-copy)
+    (flyparse-save-buffer-in-file temp-copy-file-name)
     (condition-case err
 	(let ((proc (flyparse-create-parse-process cmd args)))
 	  (flyparse-log 2 &quot;Created process %d, command=%s, dir=%s&quot; 
@@ -573,6 +600,8 @@
 			default-directory)
 	  (set-process-sentinel proc 'flyparse-process-sentinel)
 	  (set-process-filter proc 'flyparse-process-filter)
+	  (process-put proc 'output-file-name output-file-name)
+	  (process-put proc 'temp-copy-file-name temp-copy-file-name)
 	  (process-put proc 'parser-output &quot;&quot;)
 	  (setq flyparse-is-running t)
 	  (flyparse-clear-pending-patches)
@@ -582,7 +611,8 @@
        (let* ((err-str (format &quot;Failed to launch parser process '%s' with args %s: %s&quot;
 			       cmd args (error-message-string err))))
 	 (flyparse-log 0 err-str)
-	 (flyparse-cleanup-temp-files buffer-file-name)
+	 (flyparse-safe-delete-file temp-copy-file-name)
+	 (flyparse-safe-delete-file output-file-name)
 	 )))))
 
 (defun flyparse-create-parse-process (program-name args)
@@ -605,7 +635,9 @@
 	   (source-buffer     (process-buffer process))
 	   (source-file-name  (buffer-file-name source-buffer))
 	   (proc-id           (process-id process))
-	   (stderr (process-get process 'parser-output)))
+	   (stderr (process-get process 'parser-output))
+	   (output-file-name (process-get process 'output-file-name))
+	   (temp-copy-file-name (process-get process 'temp-copy-file-name)))
       (flyparse-log 3 &quot;Flyparse process %d exited with code %d&quot; proc-id exit-status)
       (delete-process process)
       (if (buffer-live-p source-buffer)
@@ -617,7 +649,7 @@
 		  (if (eq exit-status 0)
 		      (let ((tree '())) ;; 'tree' will be set by the 'load'ed list..
 			;; Load the parse tree...
-			(load (flyparse-temp-parser-output-name source-file-name) nil t)
+			(load output-file-name nil t)
 			(if (flyparse-tree-acceptable-p tree)
 			    (flyparse-update-newest-parse-tree tree)
 			  (error &quot;Invalid parse tree.&quot;)))
@@ -625,19 +657,22 @@
 		  ;; Log stderr
 		  (if (&gt; (length stderr) 0) (flyparse-log 1 stderr))
 		  (setq flyparse-error-in-last-parse nil)
-		  (flyparse-cleanup-temp-files source-file-name)
+		  (flyparse-safe-delete-file temp-copy-file-name)
+		  (flyparse-safe-delete-file output-file-name)
 		  )
 	      (error
 	       (let ((err-str (format &quot;Flyparse Failed: %s: %s: %s&quot; source-buffer (error-message-string err) stderr)))
 		 (flyparse-report-status &quot;Failed&quot; &quot;&quot;)
 		 (flyparse-log 0 err-str)
-		 (flyparse-cleanup-temp-files source-file-name)
+		 (flyparse-safe-delete-file temp-copy-file-name)
+		 (flyparse-safe-delete-file output-file-name)
 		 (setq flyparse-error-in-last-parse t)
 		 ))))
 
 	;; Else, if source-buffer no longer exists
 	(progn 
-	  (flyparse-cleanup-temp-files source-file-name)
+	  (flyparse-safe-delete-file temp-copy-file-name)
+	  (flyparse-safe-delete-file output-file-name)
 	  (flyparse-log 3 &quot;Flyparse sentinel called back to dead buffer %d with code %d&quot; proc-id exit-status))
 	))))
 
@@ -717,7 +752,6 @@
   (when flyparse-timer
     (cancel-timer flyparse-timer)
     (setq flyparse-timer nil)
-    (flyparse-cleanup-temp-files buffer-file-name)
     ))
 
 (defun flyparse-after-change-function (start stop len)</diff>
      <filename>flyparse-mode.el</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>as3/src/emacs/flyparse/as3/FileWalker.java</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>7d6eea9b304eaa20819b4a51680c7a07f36474b5</id>
    </parent>
  </parents>
  <author>
    <name>Aemon Cannon</name>
    <email>aemoncannon@gmail.com</email>
  </author>
  <url>http://github.com/aemoncannon/flyparse-mode/commit/455f469754ed82ec9b095dcd51677e9b71f42250</url>
  <id>455f469754ed82ec9b095dcd51677e9b71f42250</id>
  <committed-date>2009-01-25T12:46:32-08:00</committed-date>
  <authored-date>2009-01-25T12:46:32-08:00</authored-date>
  <message>Factor common driver behaviour into ADriver.
All temporary files now created with make-temp-file (no more polluting source directories).
Add generic flyparse-cache-all function for recursively parsing/caching a list of directories.</message>
  <tree>3874b603675237f243aefaf26b1991f961e4f8d8</tree>
  <committer>
    <name>Aemon Cannon</name>
    <email>aemoncannon@gmail.com</email>
  </committer>
</commit>
