|
From: <fwi...@us...> - 2011-03-24 01:02:03
|
Revision: 7263
http://jython.svn.sourceforge.net/jython/?rev=7263&view=rev
Author: fwierzbicki
Date: 2011-03-24 01:01:57 +0000 (Thu, 24 Mar 2011)
Log Message:
-----------
Glob in Java to speed up grammar regression tests.
Modified Paths:
--------------
trunk/sandbox/wierzbicki/antlr/run
trunk/sandbox/wierzbicki/antlr/src/Main.java
Modified: trunk/sandbox/wierzbicki/antlr/run
===================================================================
--- trunk/sandbox/wierzbicki/antlr/run 2011-03-23 05:03:29 UTC (rev 7262)
+++ trunk/sandbox/wierzbicki/antlr/run 2011-03-24 01:01:57 UTC (rev 7263)
@@ -1 +1 @@
-java -classpath lib/antlr-3.1.jar:build Main $*
+java -classpath lib/antlr-3.1.jar:build Main /home/frank/svn/python/release26-maint
Modified: trunk/sandbox/wierzbicki/antlr/src/Main.java
===================================================================
--- trunk/sandbox/wierzbicki/antlr/src/Main.java 2011-03-23 05:03:29 UTC (rev 7262)
+++ trunk/sandbox/wierzbicki/antlr/src/Main.java 2011-03-24 01:01:57 UTC (rev 7263)
@@ -6,24 +6,46 @@
public class Main {
// override nextToken to set startPos (this seems too hard)
public static class MyLexer extends PythonLexer {
- public MyLexer(CharStream lexer) {
- super(lexer);
- }
- public Token nextToken() {
- startPos = getCharPositionInLine();
- return super.nextToken();
- }
+ public MyLexer(CharStream lexer) {
+ super(lexer);
+ }
+ public Token nextToken() {
+ startPos = getCharPositionInLine();
+ return super.nextToken();
+ }
}
public static void main(String[] args) throws Exception {
- CharStream input = new ANTLRFileStream(args[0]);
- PythonLexer lexer = new MyLexer(input);
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- tokens.discardOffChannelTokens(true);
- PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>");
- tokens = new CommonTokenStream(indentedSource);
- //System.out.println("tokens="+tokens.getTokens());
- PythonParser parser = new PythonParser(tokens);
- parser.file_input();
+ walk(new File(args[0]));
}
+
+ public static void walk(File dir) throws Exception {
+ String pattern = ".py";
+
+ File pyfiles[] = dir.listFiles();
+ if(pyfiles != null) {
+ for(int i=0; i<pyfiles.length; i++) {
+ if(pyfiles[i].isDirectory()) {
+ walk(pyfiles[i]);
+ } else {
+ if(pyfiles[i].getName().endsWith(pattern)) {
+ run(pyfiles[i].getPath());
+ }
+ }
+ }
+ }
+ }
+
+
+ public static void run(String path) throws Exception {
+ System.out.println("parsing " + path);
+ CharStream input = new ANTLRFileStream(path);
+ PythonLexer lexer = new MyLexer(input);
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ tokens.discardOffChannelTokens(true);
+ PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>");
+ tokens = new CommonTokenStream(indentedSource);
+ PythonParser parser = new PythonParser(tokens);
+ parser.file_input();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|