clean playground
This commit is contained in:
parent
675776267f
commit
8c4edb8fba
|
@ -14,7 +14,7 @@ a single rule.
|
||||||
|
|
||||||
weird though that this one works
|
weird though that this one works
|
||||||
|
|
||||||
STRING : '"' ( '\\' '"' | . )* '"' ;
|
STRING : '"' ( '\\' '"' | . )*? '"' ;
|
||||||
|
|
||||||
wouldn't it get to the end of the rule also by the wild-card route?
|
wouldn't it get to the end of the rule also by the wild-card route?
|
||||||
Maybe it's a simple order of operations or order in which i process the
|
Maybe it's a simple order of operations or order in which i process the
|
||||||
|
@ -23,5 +23,5 @@ wouldn't it get to the end of the rule also by the wild-card route?
|
||||||
*/
|
*/
|
||||||
//STRING : '"' ( 'x' | . )* '"' ;
|
//STRING : '"' ( 'x' | . )* '"' ;
|
||||||
|
|
||||||
ACTION : '{' ( ACTION | . )* '}' ;
|
ACTION : '{' ( ACTION | . )*? '}' ;
|
||||||
WS : [ \r\t\n]+ -> skip ;
|
WS : [ \r\t\n]+ -> skip ;
|
||||||
|
|
|
@ -156,9 +156,9 @@ ID : '.'? (LETTER|'_'|'.') (LETTER|DIGIT|'_'|'.')*
|
||||||
fragment
|
fragment
|
||||||
LETTER : 'a'..'z'|'A'..'Z'|'\u0080'..'\u00FF' ;
|
LETTER : 'a'..'z'|'A'..'Z'|'\u0080'..'\u00FF' ;
|
||||||
|
|
||||||
USER_OP : '%' .* '%' ;
|
USER_OP : '%' .*? '%' ;
|
||||||
|
|
||||||
COMMENT : '#' .* '\n' {skip();} ;
|
COMMENT : '#' .*? '\n' {skip();} ;
|
||||||
|
|
||||||
/** Doesn't handle '\n' correctly. it's context-sensitive */
|
/** Doesn't handle '\n' correctly. it's context-sensitive */
|
||||||
WS : (' '|'\t'|'\n'|'\r')+ {skip();} ;
|
WS : (' '|'\t'|'\n'|'\r')+ {skip();} ;
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
import org.antlr.runtime.debug.BlankDebugEventListener;
|
|
||||||
import org.antlr.v4.runtime.ANTLRFileStream;
|
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
|
||||||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|
||||||
import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/** Parse a java file or directory of java files using the generated parser
|
|
||||||
* ANTLR builds from java.g4
|
|
||||||
*/
|
|
||||||
class TestYang {
|
|
||||||
public static long lexerTime = 0;
|
|
||||||
public static boolean profile = false;
|
|
||||||
public static YangJavaLexer lexer;
|
|
||||||
public static YangJavaParser parser = null;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
if (args.length > 0 ) {
|
|
||||||
// for each directory/file specified on the command line
|
|
||||||
for(int i=0; i< args.length;i++) {
|
|
||||||
doFile(new File(args[i])); // parse it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.err.println("Usage: java Main <directory or file name>");
|
|
||||||
}
|
|
||||||
long stop = System.currentTimeMillis();
|
|
||||||
System.out.println("Lexer total time " + lexerTime + "ms.");
|
|
||||||
System.out.println("Total time " + (stop - start) + "ms.");
|
|
||||||
|
|
||||||
System.out.println("finished parsing OK");
|
|
||||||
System.out.println(LexerATNSimulator.match_calls+" lexer match calls");
|
|
||||||
System.out.println(ParserATNSimulator.ATN_failover+" parser failovers");
|
|
||||||
System.out.println(ParserATNSimulator.predict_calls +" parser predict calls");
|
|
||||||
if ( profile ) {
|
|
||||||
System.out.println("num decisions "+profiler.numDecisions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
System.err.println("exception: "+e);
|
|
||||||
e.printStackTrace(System.err); // so we can get stack trace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// This method decides what action to take based on the type of
|
|
||||||
// file we are looking at
|
|
||||||
public static void doFile(File f)
|
|
||||||
throws Exception {
|
|
||||||
// If this is a directory, walk each file/dir in that directory
|
|
||||||
if (f.isDirectory()) {
|
|
||||||
String files[] = f.list();
|
|
||||||
for(int i=0; i < files.length; i++)
|
|
||||||
doFile(new File(f, files[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise, if this is a java file, parse it!
|
|
||||||
else if ( ((f.getName().length()>5) &&
|
|
||||||
f.getName().substring(f.getName().length()-5).equals(".java"))
|
|
||||||
|| f.getName().equals("input") )
|
|
||||||
{
|
|
||||||
System.err.println("parsing "+f.getAbsolutePath());
|
|
||||||
parseFile(f.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountDecisions extends BlankDebugEventListener {
|
|
||||||
public int numDecisions = 0;
|
|
||||||
public void enterDecision(int decisionNumber) {
|
|
||||||
numDecisions++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static CountDecisions profiler = new CountDecisions();
|
|
||||||
|
|
||||||
// Here's where we do the real work...
|
|
||||||
public static void parseFile(String f)
|
|
||||||
throws Exception {
|
|
||||||
try {
|
|
||||||
// Create a scanner that reads from the input stream passed to us
|
|
||||||
if ( lexer==null ) {
|
|
||||||
lexer = new YangJavaLexer(null);
|
|
||||||
}
|
|
||||||
lexer.setInputStream(new ANTLRFileStream(f));
|
|
||||||
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
tokens.fill();
|
|
||||||
// System.out.println(tokens.getTokens());
|
|
||||||
long stop = System.currentTimeMillis();
|
|
||||||
lexerTime += stop-start;
|
|
||||||
for (Object t : tokens.getTokens()) {
|
|
||||||
System.out.println(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( true ) {
|
|
||||||
// Create a parser that reads from the scanner
|
|
||||||
if ( parser==null ) {
|
|
||||||
parser = new YangJavaParser(tokens);
|
|
||||||
}
|
|
||||||
parser.setTokenStream(tokens);
|
|
||||||
// start parsing at the compilationUnit rule
|
|
||||||
parser.compilationUnit();
|
|
||||||
//System.err.println("finished "+f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.err.println("parser exception: "+e);
|
|
||||||
e.printStackTrace(); // so we can get stack trace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue