

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;

import com.redhat.ceylon.compiler.parser.CeylonLexer;
import com.redhat.ceylon.compiler.parser.CeylonParser;

public class Main {

	public static void main(String[] args) throws Exception {
		fileOrDir( new File(args[0]) );
	}
	
	private static void file(File file) throws Exception {
		if ( file.getName().endsWith(".ceylon") ) {
		
		System.out.println("Parsing " + file.getName());
        InputStream is = new FileInputStream( file );
        ANTLRInputStream input = new ANTLRInputStream(is);
        CeylonLexer lexer = new CeylonLexer(input);

        CommonTokenStream tokens = new CommonTokenStream(lexer);

        CeylonParser parser = new CeylonParser(tokens);
        CeylonParser.compilationUnit_return r = parser.compilationUnit();

        //CommonTree t = (CommonTree)r.getTree();

        if (lexer.getNumberOfSyntaxErrors() != 0) {
            System.out.println("Lexer failed");
        }
        else if (parser.getNumberOfSyntaxErrors() != 0) {
        	System.out.println("Parser failed");
        }
        else {
        	System.out.println("Parser succeeded");
        }
        
		}
        

	}

	
	
	private static void fileOrDir(File file) throws Exception {
		if (file.isDirectory()) 
			dir(file);
		else
			file(file);
	}



	private static void dir(File dir) throws Exception {
		for (File file: dir.listFiles()) 
			fileOrDir(file);
	}

}

@@ -355,16 +355,113 @@
 ption %7B%0A
+%09%09String path;%0A%09%09if ( args.length==0 ) %7B%0A%09%09%09path = %22corpus%22;%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09path = args%5B0%5D;%0A%09%09%7D%0A
 %09%09fileOr
@@ -474,23 +474,20 @@
 ew File(
-args%5B0%5D
+path
 ) );%0A%09%7D%0A

make it easier to run against corpus