forked from jasder/antlr
generation of TestLexerExec for Java
This commit is contained in:
parent
85388803c6
commit
809bac2591
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class AbstractParserTestMethod extends TestMethod {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -11,6 +12,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.antlr.v4.test.rt.java.BaseTest;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupFile;
|
||||
|
@ -31,13 +33,22 @@ public class Generator {
|
|||
private static Map<String, File> readConfigs() throws Exception {
|
||||
Map<String, File> configs = new HashMap<String, File>();
|
||||
configs.put("Source", readGrammarDir()); // source of test templates
|
||||
configs.put("Java", readJavaDir()); // generated Java tests
|
||||
configs.put("Firefox", readFirefoxDir()); // generated Firefox tests
|
||||
return configs;
|
||||
}
|
||||
|
||||
private static File readJavaDir() throws Exception {
|
||||
String className = BaseTest.class.getName().replace(".", "/");
|
||||
className = className.substring(0, className.lastIndexOf("/") + 1);
|
||||
URL url = ClassLoader.getSystemResource(className);
|
||||
String uri = url.toURI().toString().replace("target/test-classes", "test");
|
||||
return new File(new URI(uri));
|
||||
}
|
||||
|
||||
private static File readFirefoxDir() {
|
||||
// TODO read from env variable
|
||||
return new File("/Users/ericvergnaud/Development/antlr4/antlr/antlr4-javascript/tool/test/org/antlr/v4/js/test/firefox");
|
||||
return new File("/Users/ericvergnaud/Development/antlr4/antlr/antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/firefox");
|
||||
}
|
||||
|
||||
private static File readGrammarDir() throws Exception {
|
||||
|
@ -53,7 +64,7 @@ public class Generator {
|
|||
}
|
||||
|
||||
public static String escape(String s) {
|
||||
return s==null ? null : s.replace("\\","\\\\").replace("\n", "\\n").replace("\"","\\\"");
|
||||
return s==null ? null : s.replace("\\","\\\\").replace("\r", "\\r").replace("\n", "\\n").replace("\"","\\\"");
|
||||
}
|
||||
|
||||
String target;
|
||||
|
@ -964,13 +975,13 @@ public class Generator {
|
|||
"[@0,0:4='-.-.-',<1>,1:0]\n" +
|
||||
"[@1,5:5='!',<3>,1:5]\n" +
|
||||
"[@2,6:5='<EOF>',<-1>,1:6]\n", null);
|
||||
file.addLexerTest(input, "NonGreedyTermination", "L", "\"hi\"\"mom\"",
|
||||
file.addLexerTest(input, "NonGreedyTermination1", "L", "\"hi\"\"mom\"",
|
||||
"[@0,0:3='\"hi\"',<1>,1:0]\n" +
|
||||
"[@1,4:8='\"mom\"',<1>,1:4]\n" +
|
||||
"[@2,9:8='<EOF>',<-1>,1:9]\n", null, 1);
|
||||
file.addLexerTest(input, "NonGreedyTermination", "L", "\"\"\"mom\"",
|
||||
"[@2,9:8='<EOF>',<-1>,1:9]\n", null);
|
||||
file.addLexerTest(input, "NonGreedyTermination2", "L", "\"\"\"mom\"",
|
||||
"[@0,0:6='\"\"\"mom\"',<1>,1:0]\n" +
|
||||
"[@1,7:6='<EOF>',<-1>,1:7]\n", null, 2);
|
||||
"[@1,7:6='<EOF>',<-1>,1:7]\n", null);
|
||||
file.addLexerTest(input, "GreedyOptional", "L", "//blah\n//blah\n",
|
||||
"[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
|
||||
"[@1,14:13='<EOF>',<-1>,3:14]\n", null);
|
||||
|
@ -1043,7 +1054,7 @@ public class Generator {
|
|||
"ab\n" +
|
||||
"[@0,0:1='ab',<1>,1:0]\n" +
|
||||
"[@1,2:1='<EOF>',<-1>,1:2]\n", null);
|
||||
file.addLexerTest(input, "NonGreedyConfigs", "L", "qb",
|
||||
file.addLexerTest(input, "NonGreedyConfigs", "L", "ab",
|
||||
"a\n" +
|
||||
"b\n" +
|
||||
"[@0,0:0='a',<1>,1:0]\n" +
|
||||
|
@ -1131,18 +1142,18 @@ public class Generator {
|
|||
"A\n" +
|
||||
"[@0,0:0='9',<1>,1:0]\n" +
|
||||
"[@1,1:0='<EOF>',<-1>,1:1]\n", null);
|
||||
file.addLexerTest(input, "CharSetWithQuote", "L", "b\"a",
|
||||
file.addLexerTest(input, "CharSetWithQuote1", "L", "b\"a",
|
||||
"A\n" +
|
||||
"[@0,0:2='b\"a',<1>,1:0]\n" +
|
||||
"[@1,3:2='<EOF>',<-1>,1:3]\n", null, 1);
|
||||
file.addLexerTest(input, "CharSetWithQuote", "L", "b\"\\a",
|
||||
"[@1,3:2='<EOF>',<-1>,1:3]\n", null);
|
||||
file.addLexerTest(input, "CharSetWithQuote2", "L", "b\"\\a",
|
||||
"A\n" +
|
||||
"[@0,0:3='b\"\\a',<1>,1:0]\n" +
|
||||
"[@1,4:3='<EOF>',<-1>,1:4]\n", null, 2);
|
||||
"[@1,4:3='<EOF>',<-1>,1:4]\n", null);
|
||||
final int TOKENS = 4;
|
||||
final int LABEL = 5;
|
||||
final int IDENTIFIER = 6;
|
||||
file.addLexerTest(input, "PositionAdjustingLexer", "L",
|
||||
file.addLexerTest(input, "PositionAdjustingLexer", "PositionAdjustingLexer",
|
||||
"tokens\n" +
|
||||
"tokens {\n" +
|
||||
"notLabel\n" +
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class LexerTestMethod extends TestMethod {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class ParserTestMethod extends TestMethod {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.testgen;
|
||||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : ({<PlusText("stuff fail: "):writeln()>} 'a'
|
||||
| {<PlusText("stuff0: "):writeln()>}
|
||||
'a' {<PlusText("stuff1: "):writeln()>}
|
||||
'b' {<PlusText("stuff2: "):writeln()>})
|
||||
{<Text():writeln()>} ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
J : .;
|
|
@ -0,0 +1,3 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : ["\\ab]+ {<writeln("\"A\"")>} ;
|
||||
WS : [ \n\t]+ -> skip ;
|
|
@ -1,4 +1,4 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : ('a' | 'ab') {<writeln("this.text")>} ;
|
||||
I : ('a' | 'ab') {<Text():writeln()>} ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
J : .;
|
|
@ -5,4 +5,4 @@ FloatingPointLiteral : ('0x' | '0X') HexDigit* ('.' HexDigit*)? ;
|
|||
DOT : '.' ;
|
||||
ID : 'a'..'z'+ ;
|
||||
fragment HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
WS : (' '|'\n')+;
|
|
@ -1,4 +1,4 @@
|
|||
lexer grammar <grammarName>;
|
||||
KEND : 'end' ; // has priority
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
WS : (' '|'\n')+;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue