This commit is contained in:
ericvergnaud 2014-10-16 23:19:59 +08:00
parent f22acf701e
commit 4f657e3e52
9 changed files with 138 additions and 0 deletions

View File

@ -114,9 +114,48 @@ public class Generator {
list.add(buildListeners());
list.add(buildParserErrors());
list.add(buildParserExec());
list.add(buildParseTrees());
return list;
}
private TestFile buildParseTrees() throws Exception {
TestFile file = new TestFile("ParseTrees");
file.addParserTest(input, "TokenAndRuleContextString", "T", "s",
"x",
"[a, s]\n(a x)\n",
null);
file.addParserTest(input, "Token2", "T", "s",
"xy",
"(a x y)\n",
null);
file.addParserTest(input, "test2Alts", "T", "s",
"y",
"(a y)\n",
null);
file.addParserTest(input, "2AltLoop", "T", "s",
"xyyxyxz",
"(a x y y x y x z)\n",
null);
file.addParserTest(input, "RuleRef", "T", "s",
"yx",
"(a (b y) x)\n",
null);
// ERRORs not shown. z is colored red in tree view
file.addParserTest(input, "ExtraToken", "T", "s",
"xzy",
"(a x z y)\n",
null);
file.addParserTest(input, "NoViableAlt", "T", "s",
"z",
"(a z)\n",
null);
file.addParserTest(input, "Sync", "T", "s",
"xzyy!",
"(a x z y y !)\n",
null);
return file;
}
private TestFile buildParserErrors() throws Exception {
TestFile file = new TestFile("ParserErrors");
file.addParserTest(input, "TokenMismatch", "T", "a",

View File

@ -0,0 +1,11 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : ('x' | 'y')* 'z'
;

View File

@ -0,0 +1,14 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' 'y'
;
Z : 'z'
;

View File

@ -0,0 +1,14 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' | 'y'
;
Z : 'z'
;

View File

@ -0,0 +1,13 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : b 'x'
;
b : 'y'
;

View File

@ -0,0 +1,13 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' 'y'* '!'
;
Z : 'z'
;

View File

@ -0,0 +1,11 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' 'y'
;

View File

@ -0,0 +1,12 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' {
<writeRuleInvocationStack()>
} ;

View File

@ -0,0 +1,11 @@
grammar <grammarName>;
s
@init {
<buildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
}
: r=a ;
a : 'x' | 'y'
;