From bf48ca5b7309608ed84faf13996b1a4d8b97fc0c Mon Sep 17 00:00:00 2001 From: parrt Date: Sun, 2 Oct 2011 16:19:03 -0800 Subject: [PATCH] test for conjured token [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9097] --- .../v4/runtime/DefaultANTLRErrorStrategy.java | 2 +- .../org/antlr/v4/test/TestParseErrors.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/DefaultANTLRErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/DefaultANTLRErrorStrategy.java index d4d447051..d1f5bf65c 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/DefaultANTLRErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/DefaultANTLRErrorStrategy.java @@ -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); diff --git a/tool/test/org/antlr/v4/test/TestParseErrors.java b/tool/test/org/antlr/v4/test/TestParseErrors.java index a727e2bd6..5f4d3062f 100644 --- a/tool/test/org/antlr/v4/test/TestParseErrors.java +++ b/tool/test/org/antlr/v4/test/TestParseErrors.java @@ -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='',<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='',<3>,1:1]\n"; + assertEquals(expecting, result); + } + @Test public void testLL2() throws Exception { String grammar = "grammar T;\n" +