test for conjured token

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9097]
This commit is contained in:
parrt 2011-10-02 16:19:03 -08:00
parent 1556d076bd
commit bf48ca5b73
2 changed files with 19 additions and 1 deletions

View File

@ -199,7 +199,7 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
ATNState currentState = recognizer._interp.atn.states.get(recognizer._ctx.s);
ATNState next = currentState.transition(0).target;
IntervalSet expectingAtLL2 = recognizer._interp.atn.nextTokens(next, recognizer._ctx);
System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
// System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
if ( expectingAtLL2.contains(((Token)currentSymbol).getType()) ) {
reportMissingToken(recognizer);
return getMissingSymbol(recognizer);

View File

@ -72,6 +72,15 @@ public class TestParseErrors extends BaseTest {
assertEquals(expecting, result);
}
@Test public void testConjuringUpToken() throws Exception {
String grammar =
"grammar T;\n" +
"a : 'a' x='b' {System.out.println(\"conjured=\"+$x);} 'c' ;";
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ac", false);
String expecting = "conjured=[@-1,0:0='<missing 'b'>',<3>,1:1]\n";
assertEquals(expecting, result);
}
@Test public void testSingleSetInsertion() throws Exception {
String grammar =
"grammar T;\n" +
@ -82,6 +91,15 @@ public class TestParseErrors extends BaseTest {
assertEquals(expecting, result);
}
@Test public void testConjuringUpTokenFromSet() throws Exception {
String grammar =
"grammar T;\n" +
"a : 'a' x=('b'|'c') {System.out.println(\"conjured=\"+$x);} 'd' ;";
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ad", false);
String expecting = "conjured=[@-1,0:0='<missing 'b'>',<3>,1:1]\n";
assertEquals(expecting, result);
}
@Test public void testLL2() throws Exception {
String grammar =
"grammar T;\n" +