Merge pull request #928 from antlr/delete-legacy-tests
delete legacy test generator and generated tests
This commit is contained in:
commit
6439b40d09
|
@ -1,12 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class AbstractParserTestMethod extends JUnitTestMethod {
|
||||
|
||||
public String startRule;
|
||||
|
||||
public AbstractParserTestMethod(String name, String grammarName, String startRule) {
|
||||
super(name, grammarName, null, null, null, null);
|
||||
this.startRule = startRule;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CompositeLexerTestMethod extends LexerTestMethod {
|
||||
|
||||
public Grammar[] slaveGrammars;
|
||||
|
||||
public CompositeLexerTestMethod(String name, String grammarName,
|
||||
String input, String expectedOutput,
|
||||
String expectedErrors, String ... slaves) {
|
||||
super(name, grammarName, input, expectedOutput, expectedErrors, null);
|
||||
this.slaveGrammars = new Grammar[slaves.length];
|
||||
for(int i=0;i<slaves.length;i++)
|
||||
this.slaveGrammars[i] = new Grammar(name + "_" + slaves[i], slaves[i]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGrammars(File grammarDir, String testFileName) throws Exception {
|
||||
for(Grammar slave : slaveGrammars)
|
||||
slave.load(new File(grammarDir, testFileName));
|
||||
super.loadGrammars(grammarDir, testFileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGrammars(STGroup group) {
|
||||
for(Grammar slave : slaveGrammars)
|
||||
slave.generate(group);
|
||||
super.generateGrammars(group);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CompositeParserTestMethod extends ParserTestMethod {
|
||||
|
||||
public Grammar[] slaveGrammars;
|
||||
public boolean slaveIsLexer = false;
|
||||
|
||||
public CompositeParserTestMethod(String name, String grammarName,
|
||||
String startRule, String input, String expectedOutput,
|
||||
String expectedErrors, String ... slaves) {
|
||||
super(name, grammarName, startRule, input, expectedOutput, expectedErrors);
|
||||
this.slaveGrammars = new Grammar[slaves.length];
|
||||
for(int i=0;i<slaves.length;i++)
|
||||
this.slaveGrammars[i] = new Grammar(name + "_" + slaves[i], slaves[i]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGrammars(File grammarDir, String testFileName) throws Exception {
|
||||
for(Grammar slave : slaveGrammars)
|
||||
slave.load(new File(grammarDir, testFileName));
|
||||
super.loadGrammars(grammarDir, testFileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGrammars(STGroup group) {
|
||||
for(Grammar slave : slaveGrammars)
|
||||
slave.generate(group);
|
||||
super.generateGrammars(group);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ConcreteParserTestMethod extends JUnitTestMethod {
|
||||
|
||||
public String baseName;
|
||||
|
||||
public ConcreteParserTestMethod(String name, String input, String expectedOutput,
|
||||
String expectedErrors, Integer index) {
|
||||
super(name, null, input, expectedOutput, expectedErrors, index);
|
||||
this.baseName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGrammars(File grammarDir, String testFileName) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGrammars(STGroup group) {
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,51 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Grammar {
|
||||
|
||||
public String fileName;
|
||||
public String grammarName;
|
||||
public String[] lines;
|
||||
public ST template;
|
||||
|
||||
public Grammar(String fileName, String grammarName) {
|
||||
this.fileName = fileName;
|
||||
this.grammarName = grammarName;
|
||||
}
|
||||
|
||||
public void load(File grammarDir) throws Exception {
|
||||
template = loadGrammar(grammarDir, fileName);
|
||||
}
|
||||
|
||||
protected ST loadGrammar(File grammarDir, String grammarFileName) throws Exception {
|
||||
File file = new File(grammarDir, grammarFileName + ".st");
|
||||
InputStream input = new FileInputStream(file);
|
||||
try {
|
||||
byte[] data = new byte[(int)file.length()];
|
||||
int next = 0;
|
||||
while(input.available()>0) {
|
||||
int read = input.read(data, next, data.length - next);
|
||||
next += read;
|
||||
}
|
||||
String s = new String(data);
|
||||
return new ST(s);
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void generate(STGroup group) {
|
||||
template.add("grammarName", grammarName);
|
||||
template.groupThatCreatedThisInstance = group; // so templates get interpreted
|
||||
lines = template.render().split("\n");
|
||||
for(int i=0;i<lines.length;i++)
|
||||
lines[i] = Generator.escape(lines[i]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JUnitTestFile {
|
||||
|
||||
List<JUnitTestMethod> unitTests = new ArrayList<JUnitTestMethod>();
|
||||
public String name;
|
||||
public List<String> tests = new ArrayList<String>();
|
||||
public boolean importErrorQueue = false;
|
||||
public boolean importGrammar = false;
|
||||
|
||||
public JUnitTestFile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ParserTestMethod addParserTest(File grammarDir, String name, String grammarName, String methodName,
|
||||
String input, String expectedOutput, String expectedErrors) throws Exception {
|
||||
ParserTestMethod tm = new ParserTestMethod(name, grammarName, methodName, input, expectedOutput, expectedErrors);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
return tm;
|
||||
}
|
||||
|
||||
public AbstractParserTestMethod addParserTests(File grammarDir, String name, String grammarName, String methodName,
|
||||
String ... inputsAndOuputs) throws Exception {
|
||||
AbstractParserTestMethod tm = new AbstractParserTestMethod(name, grammarName, methodName);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
for(int i=0; i<inputsAndOuputs.length; i+=2) {
|
||||
ConcreteParserTestMethod cm = new ConcreteParserTestMethod(name,
|
||||
inputsAndOuputs[i], inputsAndOuputs[i+1], null,
|
||||
1 + (i/2));
|
||||
unitTests.add(cm);
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
public AbstractParserTestMethod addParserTestsWithErrors(File grammarDir, String name, String grammarName, String methodName,
|
||||
String ... inputsOuputsAndErrors) throws Exception {
|
||||
AbstractParserTestMethod tm = new AbstractParserTestMethod(name, grammarName, methodName);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
for(int i=0; i<inputsOuputsAndErrors.length; i+=3) {
|
||||
ConcreteParserTestMethod cm = new ConcreteParserTestMethod(name,
|
||||
inputsOuputsAndErrors[i], inputsOuputsAndErrors[i+1], inputsOuputsAndErrors[i+2],
|
||||
1 + (i/3));
|
||||
unitTests.add(cm);
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
public CompositeParserTestMethod addCompositeParserTest(File grammarDir, String name, String grammarName, String methodName,
|
||||
String input, String expectedOutput, String expectedErrors, String ... slaves) throws Exception {
|
||||
CompositeParserTestMethod tm = new CompositeParserTestMethod(name, grammarName, methodName, input, expectedOutput, expectedErrors, slaves);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
return tm;
|
||||
}
|
||||
|
||||
public LexerTestMethod addLexerTest(File grammarDir, String name, String grammarName,
|
||||
String input, String expectedOutput, String expectedErrors) throws Exception {
|
||||
return addLexerTest(grammarDir, name, grammarName, input, expectedOutput, expectedErrors, null);
|
||||
}
|
||||
|
||||
public LexerTestMethod addLexerTest(File grammarDir, String name, String grammarName,
|
||||
String input, String expectedOutput, String expectedErrors, Integer index) throws Exception {
|
||||
LexerTestMethod tm = new LexerTestMethod(name, grammarName, input, expectedOutput, expectedErrors, index);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
return tm;
|
||||
}
|
||||
|
||||
public CompositeLexerTestMethod addCompositeLexerTest(File grammarDir, String name, String grammarName,
|
||||
String input, String expectedOutput, String expectedErrors, String ... slaves) throws Exception {
|
||||
CompositeLexerTestMethod tm = new CompositeLexerTestMethod(name, grammarName, input, expectedOutput, expectedErrors, slaves);
|
||||
tm.loadGrammars(grammarDir, this.name);
|
||||
unitTests.add(tm);
|
||||
return tm;
|
||||
}
|
||||
|
||||
public void generateUnitTests(STGroup group) {
|
||||
for(JUnitTestMethod tm : unitTests) {
|
||||
tm.generateGrammars(group);
|
||||
String name = tm.getClass().getSimpleName();
|
||||
ST template = group.getInstanceOf(name);
|
||||
template.add("test", tm);
|
||||
tests.add(template.render());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class JUnitTestMethod {
|
||||
|
||||
public String name;
|
||||
public Grammar grammar;
|
||||
public String afterGrammar;
|
||||
public String input;
|
||||
public String expectedOutput;
|
||||
public String expectedErrors;
|
||||
public boolean debug = false;
|
||||
|
||||
protected JUnitTestMethod(String name, String grammarName, String input,
|
||||
String expectedOutput, String expectedErrors, Integer index) {
|
||||
this.name = name + (index==null ? "" : "_" + index);
|
||||
this.grammar = new Grammar(name, grammarName);
|
||||
this.input = Generator.escape(input);
|
||||
this.expectedOutput = Generator.escape(expectedOutput);
|
||||
this.expectedErrors = Generator.escape(expectedErrors);
|
||||
}
|
||||
|
||||
public void loadGrammars(File grammarDir, String testFileName) throws Exception {
|
||||
grammar.load(new File(grammarDir, testFileName));
|
||||
}
|
||||
|
||||
public void generateGrammars(STGroup group) {
|
||||
grammar.generate(group);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class LexerTestMethod extends JUnitTestMethod {
|
||||
|
||||
public String[] outputLines;
|
||||
public boolean lexerOnly = true;
|
||||
public boolean showDFA = false;
|
||||
|
||||
public LexerTestMethod(String name, String grammarName, String input,
|
||||
String expectedOutput, String expectedErrors, Integer index) {
|
||||
super(name, grammarName, input, expectedOutput, expectedErrors, index);
|
||||
outputLines = expectedOutput.split("\n");
|
||||
for(int i=0;i<outputLines.length;i++)
|
||||
outputLines[i] = Generator.escape(outputLines[i]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.antlr.v4.test.rt.gen;
|
||||
|
||||
public class ParserTestMethod extends JUnitTestMethod {
|
||||
|
||||
public String startRule;
|
||||
|
||||
public ParserTestMethod(String name, String grammarName, String startRule,
|
||||
String input, String expectedOutput, String expectedErrors) {
|
||||
super(name, grammarName, input, expectedOutput, expectedErrors, null);
|
||||
this.startRule = startRule;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar M;
|
||||
import S;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar S;
|
||||
A : 'a' {<writeln("\"S.A\"")>};
|
||||
C : 'c' ;
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar M;
|
||||
import S;
|
||||
A : 'a' B {<writeln("\"M.A\"")>};
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar S;
|
||||
A : 'a' {<writeln("\"S.A\"")>};
|
||||
B : 'b' {<writeln("\"S.B\"")>};
|
|
@ -1,4 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : a ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar S;
|
||||
a : '=' 'a' {<write("\"S.a\"")>};
|
|
@ -1,3 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : x INT;
|
|
@ -1,5 +0,0 @@
|
|||
parser grammar S;
|
||||
tokens { A, B, C }
|
||||
x : 'x' INT {<writeln("\"S.x\"")>};
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,17 +0,0 @@
|
|||
// The lexer will create rules to match letters a, b, c.
|
||||
// The associated token types A, B, C must have the same value
|
||||
// and all import'd parsers. Since ANTLR regenerates all imports
|
||||
// for use with the delegator M, it can generate the same token type
|
||||
// mapping in each parser:
|
||||
// public static final int C=6;
|
||||
// public static final int EOF=-1;
|
||||
// public static final int B=5;
|
||||
// public static final int WS=7;
|
||||
// public static final int A=4;
|
||||
grammar M;
|
||||
import S,T;
|
||||
s : x y ; // matches AA, which should be 'aa'
|
||||
B : 'b' ; // another order: B, A, C
|
||||
A : 'a' ;
|
||||
C : 'c' ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
tokens { A, B, C }
|
||||
x : A {<writeln("\"S.x\"")>};
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
tokens { C, B, A } // reverse order
|
||||
y : A {<writeln("\"T.y\"")>};
|
|
@ -1,4 +0,0 @@
|
|||
grammar M; // uses no rules from the import
|
||||
import S;
|
||||
s : 'b'{<Invoke_foo()>}; // gS is import pointer
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,5 +0,0 @@
|
|||
parser grammar S;
|
||||
@members {
|
||||
<Declare_foo()>
|
||||
}
|
||||
a : B;
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : a ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : label=a[3] {<writeln("$label.y")>} ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar S;
|
||||
a[int x] returns [int y] : B {<write("\"S.a\"")>;$y=1000;};
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : a {<write("$a.text")>} ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar S;
|
||||
a : B {<write("\"S.a\"")>};
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar S;
|
||||
a : B {<writeln("\"S.a\"")>};
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S,T;
|
||||
s : a ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
a : B {<writeln("\"S.a\"")>};
|
||||
b : B;
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar T;
|
||||
a : B {<writeln("\"T.a\"")>};
|
|
@ -1,4 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
b : 'b'|'c';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
a : b {<write("\"S.a\"")>};
|
||||
b : B ;
|
|
@ -1,4 +0,0 @@
|
|||
grammar M;
|
||||
import S, T;
|
||||
b : 'b'|'c' {<writeln("\"M.b\"")>}|B|A;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,4 +0,0 @@
|
|||
parser grammar S;
|
||||
a : b {<writeln("\"S.a\"")>};
|
||||
b : 'b' ;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
tokens { A }
|
||||
b : 'b' {<writeln("\"T.b\"")>};
|
|
@ -1,7 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
prog : decl ;
|
||||
type_ : 'int' | 'float' ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,5 +0,0 @@
|
|||
parser grammar S;
|
||||
type_ : 'int' ;
|
||||
decl : type_ ID ';'
|
||||
| type_ ID init ';' {<write("\"Decl: \" + $text")>};
|
||||
init : '=' INT;
|
|
@ -1,4 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
program : 'test' 'test';
|
||||
WS : (UNICODE_CLASS_Zs)+ -> skip;
|
|
@ -1,6 +0,0 @@
|
|||
lexer grammar S;
|
||||
fragment
|
||||
UNICODE_CLASS_Zs : '\u0020' | '\u00A0' | '\u1680' | '\u180E'
|
||||
| '\u2000'..'\u200A'
|
||||
| '\u202F' | '\u205F' | '\u3000'
|
||||
;
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : a;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
parser grammar S;
|
||||
options {}
|
||||
a : B;
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
s : a;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
parser grammar S;
|
||||
a @after {} : B;
|
|
@ -1,5 +0,0 @@
|
|||
grammar M;
|
||||
import S;
|
||||
a : A {<Append("\"M.a: \"","$A"):writeln()>};
|
||||
A : 'abc' {<writeln("\"M.A\"")>};
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar S;
|
||||
ID : 'a'..'z'+;
|
|
@ -1,5 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: ID | ID {} ;
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
|
@ -1,12 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr expr {<writeln("\"alt 1\"")>}
|
||||
| expr
|
||||
;
|
||||
expr: '@'
|
||||
| ID '@'
|
||||
| ID
|
||||
;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \r\n\t]+ -> skip ;
|
|
@ -1,9 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: '$' a | '@' b ;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
|
@ -1,9 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: ('$' a | '@' b)+ ;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
|
@ -1,13 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr[0] {<ToStringTree("$expr.ctx"):writeln()>};
|
||||
expr[int _p]
|
||||
: ID
|
||||
(
|
||||
{5 >= $_p}? '*' expr[6]
|
||||
| {4 >= $_p}? '+' expr[5]
|
||||
)*
|
||||
;
|
||||
ID : [a-zA-Z]+ ;
|
||||
WS : [ \r\n\t]+ -> skip ;
|
|
@ -1,10 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
@after {<DumpDFA()>}
|
||||
: '{' stat* '}' ;
|
||||
stat: 'if' ID 'then' stat ('else' ID)?
|
||||
| 'return'
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
|
@ -1,15 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr_or_assign*;
|
||||
expr_or_assign
|
||||
: expr '++' {<writeln("\"fail.\"")>}
|
||||
| expr {<writeln("\"pass: \"+$expr.text")>}
|
||||
;
|
||||
expr: expr_primary ('\<-' ID)?;
|
||||
expr_primary
|
||||
: '(' ID ')'
|
||||
| ID '(' ID ')'
|
||||
| ID
|
||||
;
|
||||
ID : [a-z]+ ;
|
|
@ -1,9 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: a;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
|
@ -1,21 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog: stat ;
|
||||
stat: expr NEWLINE # printExpr
|
||||
| ID '=' expr NEWLINE # assign
|
||||
| NEWLINE # blank
|
||||
;
|
||||
expr: expr ('*'|'/') expr # MulDiv
|
||||
| expr ('+'|'-') expr # AddSub
|
||||
| INT # int
|
||||
| ID # id
|
||||
| '(' expr ')' # parens
|
||||
;
|
||||
|
||||
MUL : '*' ; // assigns token name to '*' used above in grammar
|
||||
DIV : '/' ;
|
||||
ADD : '+' ;
|
||||
SUB : '-' ;
|
||||
ID : [a-zA-Z]+ ; // match identifiers
|
||||
INT : [0-9]+ ; // match integers
|
||||
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
|
||||
WS : [ \t]+ -> skip ; // toss out whitespace
|
|
@ -1,14 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : declarator EOF ; // must indicate EOF can follow
|
||||
declarator
|
||||
: declarator '[' e ']'
|
||||
| declarator '[' ']'
|
||||
| declarator '(' ')'
|
||||
| '*' declarator // binds less tight than suffixes
|
||||
| '(' declarator ')'
|
||||
| ID
|
||||
;
|
||||
e : INT ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a @after {<ToStringTree("$ctx"):writeln()>} : a ID
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,13 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
|
||||
e : e '.' ID
|
||||
| e '.' 'this'
|
||||
| '-' e
|
||||
| e '*' e
|
||||
| e ('+'|'-') e
|
||||
| INT
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,56 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
|
||||
expressionList
|
||||
: e (',' e)*
|
||||
;
|
||||
e : '(' e ')'
|
||||
| 'this'
|
||||
| 'super'
|
||||
| INT
|
||||
| ID
|
||||
| type_ '.' 'class'
|
||||
| e '.' ID
|
||||
| e '.' 'this'
|
||||
| e '.' 'super' '(' expressionList? ')'
|
||||
| e '.' 'new' ID '(' expressionList? ')'
|
||||
| 'new' type_ ( '(' expressionList? ')' | ('[' e ']')+)
|
||||
| e '[' e ']'
|
||||
| '(' type_ ')' e
|
||||
| e ('++' | '--')
|
||||
| e '(' expressionList? ')'
|
||||
| ('+'|'-'|'++'|'--') e
|
||||
| ('~'|'!') e
|
||||
| e ('*'|'/'|'%') e
|
||||
| e ('+'|'-') e
|
||||
| e ('\<\<' | '>>>' | '>>') e
|
||||
| e ('\<=' | '>=' | '>' | '\<') e
|
||||
| e 'instanceof' e
|
||||
| e ('==' | '!=') e
|
||||
| e '&' e
|
||||
|\<assoc=right> e '^' e
|
||||
| e '|' e
|
||||
| e '&&' e
|
||||
| e '||' e
|
||||
| e '?' e ':' e
|
||||
|\<assoc=right>
|
||||
e ('='
|
||||
|'+='
|
||||
|'-='
|
||||
|'*='
|
||||
|'/='
|
||||
|'&='
|
||||
|'|='
|
||||
|'^='
|
||||
|'>>='
|
||||
|'>>>='
|
||||
|'\<\<='
|
||||
|'%=') e
|
||||
;
|
||||
type_: ID
|
||||
| ID '[' ']'
|
||||
| 'int'
|
||||
| 'int' '[' ']'
|
||||
;
|
||||
ID : ('a'..'z'|'A'..'Z'|'_'|'$')+;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e;
|
||||
e : a=e op=('*'|'/') b=e {}
|
||||
| INT {}
|
||||
| '(' x=e ')' {}
|
||||
;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e ;
|
||||
e : a=e op=('*'|'/') b=e {}{}
|
||||
| INT {}{}
|
||||
| '(' x=e ')' {}{}
|
||||
;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,9 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e ;
|
||||
e : a=e op=('*'|'/') b=e {}{<True()>}?
|
||||
| a=e op=('+'|'-') b=e {}\<p=3>{<True()>}?\<fail='Message'>
|
||||
| INT {}{}
|
||||
| '(' x=e ')' {}{}
|
||||
;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,16 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s : e {<writeln("$e.v")>};
|
||||
e returns [int v]
|
||||
: e '*' e {$v = <Cast("BinaryContext","$ctx")>.e(0).v * <Cast("BinaryContext","$ctx")>.e(1).v;} # binary
|
||||
| e '+' e {$v = <Cast("BinaryContext","$ctx")>.e(0).v + <Cast("BinaryContext","$ctx")>.e(1).v;} # binary
|
||||
| INT {$v = $INT.int;} # anInt
|
||||
| '(' e ')' {$v = $e.v;} # parens
|
||||
| left=e INC {<Cast("UnaryContext","$ctx"):Concat(".INC() != null"):Assert()>$v = $left.v + 1;} # unary
|
||||
| left=e DEC {<Cast("UnaryContext","$ctx"):Concat(".DEC() != null"):Assert()>$v = $left.v - 1;} # unary
|
||||
| ID {<AssignLocal("$v","3")>} # anID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
INC : '++' ;
|
||||
DEC : '--' ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog
|
||||
@after {<ToStringTree("$ctx"):writeln()>}
|
||||
: statement* EOF {};
|
||||
statement: letterA | statement letterA 'b' ;
|
||||
letterA: 'a';
|
|
@ -1,11 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s : e {<writeln("$e.result")>} ;
|
||||
e returns [String result]
|
||||
: ID '=' e1=e {$result = "(" + $ID.text + "=" + $e1.result + ")";}
|
||||
| ID {$result = $ID.text;}
|
||||
| e1=e '+' e2=e {$result = "(" + $e1.result + "+" + $e2.result + ")";}
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s : e {<writeln("$e.v")>};
|
||||
e returns [int v, <StringList()> ignored]
|
||||
: a=e '*' b=e {$v = $a.v * $b.v;}
|
||||
| a=e '+' b=e {$v = $a.v + $b.v;}
|
||||
| INT {$v = $INT.int;}
|
||||
| '(' x=e ')' {$v = $x.v;}
|
||||
;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s : q=e {<writeln("$e.v")>};
|
||||
e returns [int v]
|
||||
: a=e op='*' b=e {$v = $a.v * $b.v;} # mult
|
||||
| a=e '+' b=e {$v = $a.v + $b.v;} # add
|
||||
| INT {$v = $INT.int;} # anInt
|
||||
| '(' x=e ')' {$v = $x.v;} # parens
|
||||
| x=e '++' {$v = $x.v+1;} # inc
|
||||
| e '--' # dec
|
||||
| ID {$v = 3;} # anID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,13 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : expr EOF;
|
||||
expr:
|
||||
a=expr '*' a=expr #Factor
|
||||
| b+=expr (',' b+=expr)* '>>' c=expr #Send
|
||||
| ID #JustId //semantic check on modifiers
|
||||
;
|
||||
|
||||
ID : ('a'..'z'|'A'..'Z'|'_')
|
||||
('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
|
||||
;
|
||||
|
||||
WS : [ \t\n]+ -> skip ;
|
|
@ -1,12 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : expr EOF;
|
||||
expr:
|
||||
a=expr '*' a=expr #Factor
|
||||
| b+=expr ',' b+=expr #Comma
|
||||
| b+=expr '>>' c=expr #Send
|
||||
| ID #JustId //semantic check on modifiers
|
||||
;
|
||||
ID : ('a'..'z'|'A'..'Z'|'_')
|
||||
('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
|
||||
;
|
||||
WS : [ \t\n]+ -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
|
||||
a : a {<True()>}? ID
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
|
||||
a : a ID {<False()>}?\<fail='custom message'>
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
|
||||
a : a ID
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,10 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow or 'a\<EOF>' won't match
|
||||
e : e '*' e
|
||||
| e '+' e
|
||||
|\<assoc=right> e '?' e ':' e
|
||||
|\<assoc=right> e '=' e
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,10 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF; // must indicate EOF can follow or 'a\<EOF>' won't match
|
||||
e :\<assoc=right> e '*' e
|
||||
|\<assoc=right> e '+' e
|
||||
|\<assoc=right> e '?' e ':' e
|
||||
|\<assoc=right> e '=' e
|
||||
| ID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,49 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog : expression EOF;
|
||||
expression
|
||||
: ID '(' expression (',' expression)* ')' # doFunction
|
||||
| '(' expression ')' # doParenthesis
|
||||
| '!' expression # doNot
|
||||
| '-' expression # doNegate
|
||||
| '+' expression # doPositiv
|
||||
| expression '^' expression # doPower
|
||||
| expression '*' expression # doMultipy
|
||||
| expression '/' expression # doDivide
|
||||
| expression '%' expression # doModulo
|
||||
| expression '-' expression # doMinus
|
||||
| expression '+' expression # doPlus
|
||||
| expression '=' expression # doEqual
|
||||
| expression '!=' expression # doNotEqual
|
||||
| expression '>' expression # doGreather
|
||||
| expression '>=' expression # doGreatherEqual
|
||||
| expression '\<' expression # doLesser
|
||||
| expression '\<=' expression # doLesserEqual
|
||||
| expression K_IN '(' expression (',' expression)* ')' # doIn
|
||||
| expression ( '&' | K_AND) expression # doAnd
|
||||
| expression ( '|' | K_OR) expression # doOr
|
||||
| '[' expression (',' expression)* ']' # newArray
|
||||
| K_TRUE # newTrueBoolean
|
||||
| K_FALSE # newFalseBoolean
|
||||
| NUMBER # newNumber
|
||||
| DATE # newDateTime
|
||||
| ID # newIdentifier
|
||||
| SQ_STRING # newString
|
||||
| K_NULL # newNull
|
||||
;
|
||||
|
||||
// Fragments
|
||||
fragment DIGIT : '0' .. '9';
|
||||
fragment UPPER : 'A' .. 'Z';
|
||||
fragment LOWER : 'a' .. 'z';
|
||||
fragment LETTER : LOWER | UPPER;
|
||||
fragment WORD : LETTER | '_' | '$' | '#' | '.';
|
||||
fragment ALPHANUM : WORD | DIGIT;
|
||||
|
||||
// Tokens
|
||||
ID : LETTER ALPHANUM*;
|
||||
NUMBER : DIGIT+ ('.' DIGIT+)? (('e'|'E')('+'|'-')? DIGIT+)?;
|
||||
DATE : '\'' DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT (' ' DIGIT DIGIT ':' DIGIT DIGIT ':' DIGIT DIGIT ('.' DIGIT+)?)? '\'';
|
||||
SQ_STRING : '\'' ('\'\'' | ~'\'')* '\'';
|
||||
DQ_STRING : '\"' ('\\\"' | ~'\"')* '\"';
|
||||
WS : [ \t\n\r]+ -> skip ;
|
||||
COMMENTS : ('/*' .*? '*/' | '//' ~'\n'* '\n' ) -> skip;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'ab' ;
|
||||
B : 'abc' ;
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'ab' ;
|
||||
B : 'abc' ;
|
||||
C : 'abcd' ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
ACTION : '{' (ACTION | ~[{}])* '}';
|
||||
WS : [ \r\n\t]+ -> skip;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'abc' ;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'a' 'b' ;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'a' 'b' ;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'a' 'b' ;
|
|
@ -1,2 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'a' 'b' ;
|
|
@ -1,5 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : ID ':' expr;
|
||||
expr : primary expr? {} | expr '->' ID;
|
||||
primary : ID;
|
||||
ID : [a-z]+;
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
ACTION2 : '[' (STRING | ~'"')*? ']';
|
||||
STRING : '"' ('\\"' | .)*? '"';
|
||||
WS : [ \t\r\n]+ -> skip;
|
|
@ -1,8 +0,0 @@
|
|||
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 : .;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : '0'..'9'+ {<writeln("\"I\"")>} ;
|
||||
WS : [ \n\u000D] -> skip ;
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : (~[ab \\n]|'a') {<writeln("\"I\"")>} ;
|
||||
WS : [ \n\u000D]+ -> skip ;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : ~[ab \n] ~[ \ncd]* {<writeln("\"I\"")>} ;
|
||||
WS : [ \n\u000D]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : '0'..'9'+ {<writeln("\"I\"")>} ;
|
||||
WS : [ \n\u000D]+ -> skip ;
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : [0-9]+ {<writeln("\"I\"")>} ;
|
||||
ID : [a-zA-Z] [a-zA-Z0-9]* {<writeln("\"ID\"")>} ;
|
||||
WS : [ \n\u0009\r]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
DASHBRACK : [\\-\]]+ {<writeln("\"DASHBRACK\"")>} ;
|
||||
WS : [ \u]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : [0-]+ {<writeln("\"I\"")>} ;
|
||||
WS : [ \n\u000D]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
I : [0-9]+ {<writeln("\"I\"")>} ;
|
||||
WS : [ \u]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : ["a-z]+ {<writeln("\"A\"")>} ;
|
||||
WS : [ \n\t]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : ["\\ab]+ {<writeln("\"A\"")>} ;
|
||||
WS : [ \n\t]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : [z-a9]+ {<writeln("\"A\"")>} ;
|
||||
WS : [ \u]+ -> skip ;
|
|
@ -1,3 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
DONE : EOF ;
|
||||
A : 'a';
|
|
@ -1,4 +0,0 @@
|
|||
lexer grammar <grammarName>;
|
||||
A : 'a' EOF ;
|
||||
B : 'a';
|
||||
C : 'c';
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue