test templates complete

This commit is contained in:
ericvergnaud 2014-10-19 11:53:00 +08:00
parent fe0d1e43e2
commit 85388803c6
22 changed files with 151 additions and 0 deletions

View File

@ -117,9 +117,100 @@ public class Generator {
list.add(buildParseTrees()); list.add(buildParseTrees());
list.add(buildSemPredEvalLexer()); list.add(buildSemPredEvalLexer());
list.add(buildSemPredEvalParser()); list.add(buildSemPredEvalParser());
list.add(buildSets());
return list; return list;
} }
private TestFile buildSets() throws Exception {
TestFile file = new TestFile("Sets");
// this must return A not I to the parser; calling a nonfragment rule
// from a nonfragment rule does not set the overall token.
file.addParserTest(input, "SeqDoesNotBecomeSet", "T", "a",
"34",
"34\n",
null);
file.addParserTest(input, "ParserSet", "T", "a",
"x",
"x\n",
null);
file.addParserTest(input, "ParserNotSet", "T", "a",
"zz",
"z\n",
null);
file.addParserTest(input, "ParserNotToken", "T", "a",
"zz",
"zz\n",
null);
file.addParserTest(input, "ParserNotTokenWithLabel", "T", "a",
"zz",
"z\n",
null);
file.addParserTest(input, "RuleAsSet", "T", "a",
"b",
"b\n",
null);
file.addParserTest(input, "NotChar", "T", "a",
"x",
"x\n",
null);
file.addParserTest(input, "OptionalSingleElement", "T", "a",
"bc",
"bc\n",
null);
file.addParserTest(input, "OptionalLexerSingleElement", "T", "a",
"bc",
"bc\n",
null);
file.addParserTests(input, "StarLexerSingleElement", "T", "a",
"bbbbc", "bbbbc\n",
"c", "c\n");
file.addParserTest(input, "PlusLexerSingleElement", "T", "a",
"bbbbc",
"bbbbc\n",
null);
file.addParserTest(input, "OptionalSet", "T", "a",
"ac",
"ac\n",
null);
file.addParserTest(input, "StarSet", "T", "a",
"abaac",
"abaac\n",
null);
file.addParserTest(input, "PlusSet", "T", "a",
"abaac",
"abaac\n",
null);
file.addParserTest(input, "LexerOptionalSet", "T", "a",
"ac",
"ac\n",
null);
file.addParserTest(input, "LexerStarSet", "T", "a",
"abaac",
"abaac\n",
null);
file.addParserTest(input, "LexerPlusSet", "T", "a",
"abaac",
"abaac\n",
null);
file.addParserTest(input, "NotCharSet", "T", "a",
"x",
"x\n",
null);
file.addParserTest(input, "NotCharSetWithLabel", "T", "a",
"x",
"x\n",
null);
file.addParserTest(input, "NotCharSetWithRuleRef3", "T", "a",
"x",
"x\n",
null);
file.addParserTest(input, "CharSetLiteral", "T", "a",
"A a B b",
"A\n" + "a\n" + "B\n" + "b\n",
null);
return file;
}
private TestFile buildSemPredEvalParser() throws Exception { private TestFile buildSemPredEvalParser() throws Exception {
TestFile file = new TestFile("SemPredEvalParser"); TestFile file = new TestFile("SemPredEvalParser");
file.addParserTest(input, "SimpleValidate", "T", "s", file.addParserTest(input, "SimpleValidate", "T", "s",

View File

@ -0,0 +1,4 @@
grammar <grammarName>;
a : (A {<writeln("$A.text")>})+ ;
a : [AaBb] ;
WS : (' '|'\n')+ -> skip ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : ('a'|'b')? 'c' ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : ('a'|'b')+ 'c' ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : ('a'|'b')* 'c' ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<writeln("$A.text")>} ;
a : ~'b' ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<writeln("$A.text")>} ;
a : ~('b'|'c') ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<writeln("$A.text")>} ;
a : h=~('b'|'c') ;

View File

@ -0,0 +1,5 @@
grammar <grammarName>;
a : A {<writeln("$A.text")>} ;
a : ('a'|B) ; // this doesn't collapse to set but works
fragment
B : ~('a'|'c') ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : 'b'? 'c' ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : ('a'|'b')? 'c' {<InputText():writeln()>} ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A? 'c' {<InputText():writeln()>} ;
a : 'b' ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : t=~('x'|'y') 'z' {<writeln("$t.text")>} ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : ~'x' 'z' {<InputText():writeln()>} ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : t=~'x' 'z' {<writeln("$t.text")>} ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : t=('x'|'y') {<writeln("$t.text")>} ;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : 'b'+ 'c' ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : ('a'|'b')+ 'c' {<InputText():writeln()>} ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a @after {<InputText():writeln()>} : 'a' | 'b' |'c' ;

View File

@ -0,0 +1,5 @@
grammar <grammarName>;
a : C {<InputText():writeln()>} ;
fragment A : '1' | '2';
fragment B : '3' '4';
C : A | B;

View File

@ -0,0 +1,3 @@
grammar <grammarName>;
a : A {<InputText():writeln()>} ;
a : 'b'* 'c' ;

View File

@ -0,0 +1,2 @@
grammar <grammarName>;
a : ('a'|'b')* 'c' {<InputText():writeln()>} ;