diff --git a/tool/test/org/antlr/v4/test/TestATNInterpreter.java b/tool/test/org/antlr/v4/test/TestATNInterpreter.java index 5a557ea50..f7c120430 100644 --- a/tool/test/org/antlr/v4/test/TestATNInterpreter.java +++ b/tool/test/org/antlr/v4/test/TestATNInterpreter.java @@ -198,7 +198,7 @@ public class TestATNInterpreter extends BaseTest { errorTokenType = re.getOffendingToken().getType(); } assertEquals(2, errorIndex); - assertEquals(6, errorTokenType); + assertEquals(4, errorTokenType); checkMatchedAlt(lg, g, "abcd", 3); // ignores d on end } diff --git a/tool/test/org/antlr/v4/test/TestATNSerialization.java b/tool/test/org/antlr/v4/test/TestATNSerialization.java index c3d2558e1..ffc73af0e 100644 --- a/tool/test/org/antlr/v4/test/TestATNSerialization.java +++ b/tool/test/org/antlr/v4/test/TestATNSerialization.java @@ -42,7 +42,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : A B ;"); String expecting = - "max type 4\n" + + "max type 2\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -52,8 +52,8 @@ public class TestATNSerialization extends BaseTest { "rule 0:0\n" + "0->2 EPSILON 0,0,0\n" + "1->6 ATOM -1,0,0\n" + - "2->4 ATOM 3,0,0\n" + - "4->5 ATOM 4,0,0\n" + + "2->4 ATOM 1,0,0\n" + + "4->5 ATOM 2,0,0\n" + "5->1 EPSILON 0,0,0\n"; ATN atn = createATN(g); String result = ATNSerializer.getDecoded(g, atn); @@ -65,7 +65,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : A EOF ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -75,7 +75,7 @@ public class TestATNSerialization extends BaseTest { "rule 0:0\n" + "0->2 EPSILON 0,0,0\n" + "1->6 ATOM -1,0,0\n" + - "2->4 ATOM 3,0,0\n" + + "2->4 ATOM 1,0,0\n" + "4->5 ATOM -1,0,0\n" + "5->1 EPSILON 0,0,0\n"; ATN atn = createATN(g); @@ -88,7 +88,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : (A|EOF) ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -111,7 +111,7 @@ public class TestATNSerialization extends BaseTest { "tokens {A; B; C;}\n" + "a : ~A ;"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -136,7 +136,7 @@ public class TestATNSerialization extends BaseTest { "tokens {A; B; C;}\n" + "a : . ;"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -157,7 +157,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : A | A B ;"); String expecting = - "max type 4\n" + + "max type 2\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -169,9 +169,9 @@ public class TestATNSerialization extends BaseTest { "rule 0:0\n" + "0->8 EPSILON 0,0,0\n" + "1->10 ATOM -1,0,0\n" + - "2->9 ATOM 3,0,0\n" + - "4->6 ATOM 3,0,0\n" + - "6->9 ATOM 4,0,0\n" + + "2->9 ATOM 1,0,0\n" + + "4->6 ATOM 1,0,0\n" + + "6->9 ATOM 2,0,0\n" + "8->2 EPSILON 0,0,0\n" + "8->4 EPSILON 0,0,0\n" + "9->1 EPSILON 0,0,0\n" + @@ -186,7 +186,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : A | A B | A B C ;"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -201,12 +201,12 @@ public class TestATNSerialization extends BaseTest { "rule 0:0\n" + "0->14 EPSILON 0,0,0\n" + "1->16 ATOM -1,0,0\n" + - "2->15 ATOM 3,0,0\n" + - "4->6 ATOM 3,0,0\n" + - "6->15 ATOM 4,0,0\n" + - "8->10 ATOM 3,0,0\n" + - "10->12 ATOM 4,0,0\n" + - "12->15 ATOM 5,0,0\n" + + "2->15 ATOM 1,0,0\n" + + "4->6 ATOM 1,0,0\n" + + "6->15 ATOM 2,0,0\n" + + "8->10 ATOM 1,0,0\n" + + "10->12 ATOM 2,0,0\n" + + "12->15 ATOM 3,0,0\n" + "14->2 EPSILON 0,0,0\n" + "14->4 EPSILON 0,0,0\n" + "14->8 EPSILON 0,0,0\n" + @@ -222,7 +222,7 @@ public class TestATNSerialization extends BaseTest { "parser grammar T;\n"+ "a : A+ B ;"); String expecting = - "max type 4\n" + + "max type 2\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + @@ -236,13 +236,13 @@ public class TestATNSerialization extends BaseTest { "rule 0:0\n" + "0->4 EPSILON 0,0,0\n" + "1->10 ATOM -1,0,0\n" + - "2->5 ATOM 3,0,0\n" + + "2->5 ATOM 1,0,0\n" + "4->2 EPSILON 0,0,0\n" + "5->6 EPSILON 0,0,0\n" + "6->4 EPSILON 0,0,0\n" + "6->7 EPSILON 0,0,0\n" + "7->8 EPSILON 0,0,0\n" + - "8->9 ATOM 4,0,0\n" + + "8->9 ATOM 2,0,0\n" + "9->1 EPSILON 0,0,0\n" + "0:6 1\n"; ATN atn = createATN(g); @@ -256,7 +256,7 @@ public class TestATNSerialization extends BaseTest { "a : e ;\n" + "e : E ;\n"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:RULE_START 1\n" + @@ -274,7 +274,7 @@ public class TestATNSerialization extends BaseTest { "3->5 EPSILON 0,0,0\n" + "4->5 RULE 2,1,0\n" + "5->1 EPSILON 0,0,0\n" + - "6->7 ATOM 3,0,0\n" + + "6->7 ATOM 1,0,0\n" + "7->3 EPSILON 0,0,0\n"; ATN atn = createATN(g); String result = ATNSerializer.getDecoded(g, atn); @@ -287,7 +287,7 @@ public class TestATNSerialization extends BaseTest { "A : 'a' ;\n" + "B : 'b' ;\n"); String expecting = - "max type 4\n" + + "max type 2\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + @@ -297,8 +297,8 @@ public class TestATNSerialization extends BaseTest { "6:BASIC 0\n" + "7:BASIC 1\n" + "8:BASIC 1\n" + - "rule 0:1 3,-1\n" + - "rule 1:3 4,-1\n" + + "rule 0:1 1,-1\n" + + "rule 1:3 2,-1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "0->3 EPSILON 0,0,0\n" + @@ -319,13 +319,13 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "INT : '0'..'9' ;\n"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + @@ -342,14 +342,14 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "INT : 'a' EOF ;\n"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "5:BASIC 0\n" + "6:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + @@ -367,7 +367,7 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "INT : 'a' (EOF|'\n') ;\n"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + @@ -376,7 +376,7 @@ public class TestATNSerialization extends BaseTest { "7:BASIC 0\n" + "9:BLOCK_START 0\n" + "10:BLOCK_END 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->3 EPSILON 0,0,0\n" + @@ -398,7 +398,7 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "INT : '0'..'9'+ ;\n"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + @@ -407,7 +407,7 @@ public class TestATNSerialization extends BaseTest { "6:BLOCK_END 0\n" + "7:PLUS_LOOP_BACK 0\n" + "8:LOOP_END 0 7\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "1->5 EPSILON 0,0,0\n" + @@ -431,7 +431,7 @@ public class TestATNSerialization extends BaseTest { "B : 'b' ;\n" + "C : 'c' {c} ;\n"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + @@ -447,9 +447,9 @@ public class TestATNSerialization extends BaseTest { "13:BASIC 2\n" + "15:BASIC 2\n" + "16:BASIC 2\n" + - "rule 0:1 3,0\n" + - "rule 1:3 4,-1\n" + - "rule 2:5 5,1\n" + + "rule 0:1 1,0\n" + + "rule 1:3 2,-1\n" + + "rule 2:5 3,1\n" + "mode 0:0\n" + "0->1 EPSILON 0,0,0\n" + "0->3 EPSILON 0,0,0\n" + @@ -476,13 +476,13 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "ID : ~('a'|'b')\n ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0:'a'..'b'\n" + "0->1 EPSILON 0,0,0\n" + @@ -500,13 +500,13 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "ID : ('a'|'b'|'e'|'p'..'t')\n ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0:'a'..'b', 'e'..'e', 'p'..'t'\n" + "0->1 EPSILON 0,0,0\n" + @@ -524,13 +524,13 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "ID : ~('a'|'b'|'e'|'p'..'t')\n ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0:'a'..'b', 'e'..'e', 'p'..'t'\n" + "0->1 EPSILON 0,0,0\n" + @@ -551,7 +551,7 @@ public class TestATNSerialization extends BaseTest { "COMMENT : '*/' {skip(); popMode();} ;\n" + "JUNK : . {more();} ;\n"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:TOKEN_START -1\n" + "1:TOKEN_START -1\n" + "2:RULE_START 0\n" + @@ -573,9 +573,9 @@ public class TestATNSerialization extends BaseTest { "19:BASIC 2\n" + "21:BASIC 2\n" + "22:BASIC 2\n" + - "rule 0:2 3,-1\n" + - "rule 1:4 4,0\n" + - "rule 2:6 5,1\n" + + "rule 0:2 1,-1\n" + + "rule 1:4 2,0\n" + + "rule 2:6 3,1\n" + "mode 0:0\n" + "mode 1:1\n" + "0->2 EPSILON 0,0,0\n" + @@ -611,14 +611,14 @@ public class TestATNSerialization extends BaseTest { "lexer grammar L;\n"+ "ID : ~('a'|'b') ~('e'|'p'..'t')\n ;"); String expecting = - "max type 3\n" + + "max type 1\n" + "0:TOKEN_START -1\n" + "1:RULE_START 0\n" + "2:RULE_STOP 0\n" + "3:BASIC 0\n" + "5:BASIC 0\n" + "6:BASIC 0\n" + - "rule 0:1 3,-1\n" + + "rule 0:1 1,-1\n" + "mode 0:0\n" + "0:'a'..'b'\n" + "1:'e'..'e', 'p'..'t'\n" + @@ -642,7 +642,7 @@ public class TestATNSerialization extends BaseTest { "C : 'c';\n"+ "D : 'd';\n"); String expecting = - "max type 6\n" + + "max type 4\n" + "0:TOKEN_START -1\n" + "1:TOKEN_START -1\n" + "2:RULE_START 0\n" + @@ -661,10 +661,10 @@ public class TestATNSerialization extends BaseTest { "15:BASIC 2\n" + "16:BASIC 3\n" + "17:BASIC 3\n" + - "rule 0:2 3,-1\n" + - "rule 1:4 4,-1\n" + - "rule 2:6 5,-1\n" + - "rule 3:8 6,-1\n" + + "rule 0:2 1,-1\n" + + "rule 1:4 2,-1\n" + + "rule 2:6 3,-1\n" + + "rule 3:8 4,-1\n" + "mode 0:0\n" + "mode 1:1\n" + "0->2 EPSILON 0,0,0\n" + @@ -699,7 +699,7 @@ public class TestATNSerialization extends BaseTest { "mode M2;\n" + "C : 'c';\n"); String expecting = - "max type 5\n" + + "max type 3\n" + "0:TOKEN_START -1\n" + "1:TOKEN_START -1\n" + "2:TOKEN_START -1\n" + @@ -715,9 +715,9 @@ public class TestATNSerialization extends BaseTest { "12:BASIC 1\n" + "13:BASIC 2\n" + "14:BASIC 2\n" + - "rule 0:3 3,-1\n" + - "rule 1:5 4,-1\n" + - "rule 2:7 5,-1\n" + + "rule 0:3 1,-1\n" + + "rule 1:5 2,-1\n" + + "rule 2:7 3,-1\n" + "mode 0:0\n" + "mode 1:1\n" + "mode 2:2\n" + diff --git a/tool/test/org/antlr/v4/test/TestActionTranslation.java b/tool/test/org/antlr/v4/test/TestActionTranslation.java index 150fc72eb..ce1c79669 100644 --- a/tool/test/org/antlr/v4/test/TestActionTranslation.java +++ b/tool/test/org/antlr/v4/test/TestActionTranslation.java @@ -125,8 +125,7 @@ public class TestActionTranslation extends BaseTest { @Test public void testRefToTextAttributeForCurrentRule() throws Exception { String action = "$a.text; $text"; String expected = - "(_localctx.a!=null?_input.getText(_localctx.a.start,_localctx.a.stop):" + - "null); _input.getText(_localctx.start, _input.LT(-1))"; + "_input.getText(_localctx.start, _input.LT(-1)); _input.getText(_localctx.start, _input.LT(-1))"; testActions(attributeTemplate, "init", action, expected); expected = "_input.getText(_localctx.start, _input.LT(-1)); _input.getText(_localctx.start, _input.LT(-1))"; diff --git a/tool/test/org/antlr/v4/test/TestCompositeGrammars.java b/tool/test/org/antlr/v4/test/TestCompositeGrammars.java index 5336e19c7..2468efd2a 100644 --- a/tool/test/org/antlr/v4/test/TestCompositeGrammars.java +++ b/tool/test/org/antlr/v4/test/TestCompositeGrammars.java @@ -234,8 +234,8 @@ public class TestCompositeGrammars extends BaseTest { writeFile(tmpdir, "M.g4", master); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue); - String expectedTokenIDToTypeMap = "{EOF=-1, B=3, A=4, C=5, WS=6}"; - String expectedStringLiteralToTypeMap = "{'c'=5, 'a'=4, 'b'=3}"; + String expectedTokenIDToTypeMap = "{EOF=-1, B=1, A=2, C=3, WS=4}"; + String expectedStringLiteralToTypeMap = "{'c'=3, 'a'=2, 'b'=1}"; String expectedTypeToTokenList = "[B, A, C, WS]"; assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString()); @@ -369,14 +369,14 @@ public class TestCompositeGrammars extends BaseTest { String slave = "parser grammar S;\n" + "a : b {System.out.println(\"S.a\");} ;\n" + - "b : B ;\n" ; + "b : 'b' ;\n" ; mkdir(tmpdir); writeFile(tmpdir, "S.g4", slave); String slave2 = "parser grammar T;\n" + "tokens { A='x'; }\n" + - "b : B {System.out.println(\"T.b\");} ;\n"; + "b : 'b' {System.out.println(\"T.b\");} ;\n"; writeFile(tmpdir, "T.g4", slave2); String master = @@ -405,9 +405,9 @@ public class TestCompositeGrammars extends BaseTest { "WS : (' '|'\\n') {skip();} ;\n" ; String expecting = "S.A\n" + - "[@0,0:0='a',<5>,1:0]\n" + - "[@1,1:1='b',<3>,1:1]\n" + - "[@2,2:2='c',<6>,1:2]\n" + + "[@0,0:0='a',<3>,1:0]\n" + + "[@1,1:1='b',<1>,1:1]\n" + + "[@2,2:2='c',<4>,1:2]\n" + "[@3,3:2='',<-1>,1:3]\n"; String found = execLexer("M.g4", master, "M", "abc", debug); assertEquals(expecting, found); @@ -427,7 +427,7 @@ public class TestCompositeGrammars extends BaseTest { "WS : (' '|'\\n') {skip();} ;\n" ; String found = execLexer("M.g4", master, "M", "ab", debug); assertEquals("M.A\n" + - "[@0,0:1='ab',<3>,1:0]\n" + + "[@0,0:1='ab',<1>,1:0]\n" + "[@1,2:1='',<-1>,1:2]\n", found); } @@ -454,7 +454,7 @@ public class TestCompositeGrammars extends BaseTest { assertEquals("unexpected warnings: "+equeue, 0, equeue.warnings.size()); assertEquals("M.A\n" + - "M.a: [@0,0:2='abc',<3>,1:0]\n", found); + "M.a: [@0,0:2='abc',<1>,1:0]\n", found); } // Make sure that M can import S that imports T. @@ -479,7 +479,7 @@ public class TestCompositeGrammars extends BaseTest { writeFile(tmpdir, "M.g4", master); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue); - String expectedTokenIDToTypeMap = "{EOF=-1, M=3}"; // S and T aren't imported; overridden + String expectedTokenIDToTypeMap = "{EOF=-1, M=1}"; // S and T aren't imported; overridden String expectedStringLiteralToTypeMap = "{}"; String expectedTypeToTokenList = "[M]"; @@ -543,7 +543,7 @@ public class TestCompositeGrammars extends BaseTest { assertEquals("[]", equeue.errors.toString()); assertEquals("[]", equeue.warnings.toString()); - String expectedTokenIDToTypeMap = "{EOF=-1, M=3, S=4, T=5, A=6, B=7, C=8}"; + String expectedTokenIDToTypeMap = "{EOF=-1, M=1, S=2, T=3, A=4, B=5, C=6}"; String expectedStringLiteralToTypeMap = "{}"; String expectedTypeToTokenList = "[M, S, T, A, B, C]"; @@ -580,7 +580,7 @@ public class TestCompositeGrammars extends BaseTest { writeFile(tmpdir, "M.g4", master); Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue); - String expectedTokenIDToTypeMap = "{EOF=-1, M=3, T=4}"; + String expectedTokenIDToTypeMap = "{EOF=-1, M=1, T=2}"; String expectedStringLiteralToTypeMap = "{}"; String expectedTypeToTokenList = "[M, T]"; @@ -627,7 +627,7 @@ public class TestCompositeGrammars extends BaseTest { Grammar g = new Grammar(tmpdir+"/G3.g4", G3str, equeue); - String expectedTokenIDToTypeMap = "{EOF=-1, T4=3, T3=4}"; + String expectedTokenIDToTypeMap = "{EOF=-1, T4=1, T3=2}"; String expectedStringLiteralToTypeMap = "{}"; String expectedTypeToTokenList = "[T4, T3]"; @@ -655,7 +655,6 @@ public class TestCompositeGrammars extends BaseTest { "grammar M;\n" + "import S;\n" + "@header{package mypackage;}\n" + - "@lexer::header{package mypackage;}\n" + "s : a ;\n" + "B : 'b' ;" + // defines B from inherited token space "WS : (' '|'\\n') {skip();} ;\n" ; diff --git a/tool/test/org/antlr/v4/test/TestLexerErrors.java b/tool/test/org/antlr/v4/test/TestLexerErrors.java index 452d13dba..b3902240e 100644 --- a/tool/test/org/antlr/v4/test/TestLexerErrors.java +++ b/tool/test/org/antlr/v4/test/TestLexerErrors.java @@ -52,7 +52,7 @@ public class TestLexerErrors extends BaseTest { "A : 'a' 'b' ;\n"; String tokens = execLexer("L.g4", grammar, "L", "abx"); String expectingTokens = - "[@0,0:1='ab',<3>,1:0]\n" + + "[@0,0:1='ab',<1>,1:0]\n" + "[@1,3:2='',<-1>,1:3]\n"; assertEquals(expectingTokens, tokens); String expectingError = "line 1:2 token recognition error at: 'x'\n"; @@ -79,7 +79,7 @@ public class TestLexerErrors extends BaseTest { "A : 'a' 'b' ;\n"; String tokens = execLexer("L.g4", grammar, "L", "abax"); String expectingTokens = - "[@0,0:1='ab',<3>,1:0]\n" + + "[@0,0:1='ab',<1>,1:0]\n" + "[@1,4:3='',<-1>,1:4]\n"; assertEquals(expectingTokens, tokens); String expectingError = "line 1:2 token recognition error at: 'ax'\n"; @@ -97,8 +97,8 @@ public class TestLexerErrors extends BaseTest { // and return to previous dfa accept state String tokens = execLexer("L.g4", grammar, "L", "ababx"); String expectingTokens = - "[@0,0:1='ab',<3>,1:0]\n" + - "[@1,2:3='ab',<3>,1:2]\n" + + "[@0,0:1='ab',<1>,1:0]\n" + + "[@1,2:3='ab',<1>,1:2]\n" + "[@2,5:4='',<-1>,1:5]\n"; assertEquals(expectingTokens, tokens); String expectingError = "line 1:4 token recognition error at: 'x'\n"; @@ -118,8 +118,8 @@ public class TestLexerErrors extends BaseTest { // uses the previous accepted in the ATN not DFA String tokens = execLexer("L.g4", grammar, "L", "ababcx"); String expectingTokens = - "[@0,0:1='ab',<3>,1:0]\n" + - "[@1,2:4='abc',<4>,1:2]\n" + + "[@0,0:1='ab',<1>,1:0]\n" + + "[@1,2:4='abc',<2>,1:2]\n" + "[@2,6:5='',<-1>,1:6]\n"; assertEquals(expectingTokens, tokens); String expectingError = "line 1:5 token recognition error at: 'x'\n"; @@ -157,9 +157,9 @@ public class TestLexerErrors extends BaseTest { "\n"; String result = execLexer("T.g4", grammar, "TLexer", "x : x", false); String expecting = - "[@0,0:0='x',<5>,1:0]\n" + - "[@1,2:2=':',<4>,1:2]\n" + - "[@2,4:4='x',<5>,1:4]\n" + + "[@0,0:0='x',<3>,1:0]\n" + + "[@1,2:2=':',<2>,1:2]\n" + + "[@2,4:4='x',<3>,1:4]\n" + "[@3,5:4='',<-1>,1:5]\n"; assertEquals(expecting, result); assertEquals("line 1:1 token recognition error at: ' '\n" + diff --git a/tool/test/org/antlr/v4/test/TestLexerExec.java b/tool/test/org/antlr/v4/test/TestLexerExec.java index 2fc4ca2e0..0d8d36de7 100644 --- a/tool/test/org/antlr/v4/test/TestLexerExec.java +++ b/tool/test/org/antlr/v4/test/TestLexerExec.java @@ -9,7 +9,7 @@ public class TestLexerExec extends BaseTest { "QUOTE : '\"' ;\n"; // make sure this compiles String found = execLexer("L.g4", grammar, "L", "\""); String expecting = - "[@0,0:0='\"',<3>,1:0]\n" + + "[@0,0:0='\"',<1>,1:0]\n" + "[@1,1:0='',<-1>,1:1]\n"; assertEquals(expecting, found); } @@ -22,9 +22,9 @@ public class TestLexerExec extends BaseTest { "WS : (' '|'\\n') {skip();} ;"; String found = execLexer("L.g4", grammar, "L", "34 -21 3"); String expecting = - "[@0,0:1='34',<4>,1:0]\n" + - "[@1,3:5='-21',<3>,1:3]\n" + - "[@2,7:7='3',<4>,1:7]\n" + + "[@0,0:1='34',<2>,1:0]\n" + + "[@1,3:5='-21',<1>,1:3]\n" + + "[@2,7:7='3',<2>,1:7]\n" + "[@3,8:7='',<-1>,1:8]\n"; // EOF has no length so range is 8:7 not 8:8 assertEquals(expecting, found); } @@ -38,8 +38,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,3:4='34',<3>,1:3]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,3:4='34',<1>,1:3]\n" + "[@2,5:4='',<-1>,1:5]\n"; assertEquals(expecting, found); } @@ -53,8 +53,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,3:4='34',<3>,1:3]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,3:4='34',<1>,1:3]\n" + "[@2,5:4='',<-1>,1:5]\n"; assertEquals(expecting, found); } @@ -68,8 +68,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,2:4='#10',<3>,1:2]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,2:4='#10',<1>,1:2]\n" + "[@2,5:4='',<-1>,1:5]\n"; assertEquals(expecting, found); } @@ -82,8 +82,8 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "34#"); String expecting = "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,2:2='#',<4>,1:2]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,2:2='#',<2>,1:2]\n" + "[@2,3:2='',<-1>,1:3]\n"; assertEquals(expecting, found); } @@ -97,8 +97,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,2:4='#11',<3>,1:2]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,2:4='#11',<1>,1:2]\n" + "[@2,5:4='',<-1>,1:5]\n"; assertEquals(expecting, found); } @@ -113,8 +113,8 @@ public class TestLexerExec extends BaseTest { "ANY : . {more();} ;\n"; String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\""); String expecting = - "[@0,0:4='\"abc\"',<5>,1:0]\n" + - "[@1,6:9='\"ab\"',<5>,1:6]\n" + + "[@0,0:4='\"abc\"',<3>,1:0]\n" + + "[@1,6:9='\"ab\"',<3>,1:6]\n" + "[@2,10:9='',<-1>,1:10]\n"; assertEquals(expecting, found); } @@ -129,8 +129,8 @@ public class TestLexerExec extends BaseTest { "ANY : . -> more ;\n"; String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\""); String expecting = - "[@0,0:4='\"abc\"',<5>,1:0]\n" + - "[@1,6:9='\"ab\"',<5>,1:6]\n" + + "[@0,0:4='\"abc\"',<3>,1:0]\n" + + "[@1,6:9='\"ab\"',<3>,1:6]\n" + "[@2,10:9='',<-1>,1:10]\n"; assertEquals(expecting, found); } @@ -145,8 +145,8 @@ public class TestLexerExec extends BaseTest { "ANY : . -> more ;\n"; String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\""); String expecting = - "[@0,0:4='\"abc\"',<5>,1:0]\n" + - "[@1,6:9='\"ab\"',<5>,1:6]\n" + + "[@0,0:4='\"abc\"',<3>,1:0]\n" + + "[@1,6:9='\"ab\"',<3>,1:6]\n" + "[@2,10:9='',<-1>,1:10]\n"; assertEquals(expecting, found); } @@ -159,13 +159,13 @@ public class TestLexerExec extends BaseTest { "WS : (' '|'\n')+ ;"; String found = execLexer("L.g4", grammar, "L", "end eend ending a"); String expecting = - "[@0,0:2='end',<3>,1:0]\n" + - "[@1,3:3=' ',<5>,1:3]\n" + - "[@2,4:7='eend',<4>,1:4]\n" + - "[@3,8:8=' ',<5>,1:8]\n" + - "[@4,9:14='ending',<4>,1:9]\n" + - "[@5,15:15=' ',<5>,1:15]\n" + - "[@6,16:16='a',<4>,1:16]\n" + + "[@0,0:2='end',<1>,1:0]\n" + + "[@1,3:3=' ',<3>,1:3]\n" + + "[@2,4:7='eend',<2>,1:4]\n" + + "[@3,8:8=' ',<3>,1:8]\n" + + "[@4,9:14='ending',<2>,1:9]\n" + + "[@5,15:15=' ',<3>,1:15]\n" + + "[@6,16:16='a',<2>,1:16]\n" + "[@7,17:16='',<-1>,1:17]\n"; assertEquals(expecting, found); } @@ -182,19 +182,19 @@ public class TestLexerExec extends BaseTest { "WS : (' '|'\n')+ ;"; String found = execLexer("L.g4", grammar, "L", "x 0 1 a.b a.l"); String expecting = - "[@0,0:0='x',<7>,1:0]\n" + - "[@1,1:1=' ',<8>,1:1]\n" + - "[@2,2:2='0',<4>,1:2]\n" + - "[@3,3:3=' ',<8>,1:3]\n" + - "[@4,4:4='1',<4>,1:4]\n" + - "[@5,5:5=' ',<8>,1:5]\n" + - "[@6,6:6='a',<7>,1:6]\n" + - "[@7,7:7='.',<6>,1:7]\n" + - "[@8,8:8='b',<7>,1:8]\n" + - "[@9,9:9=' ',<8>,1:9]\n" + - "[@10,10:10='a',<7>,1:10]\n" + - "[@11,11:11='.',<6>,1:11]\n" + - "[@12,12:12='l',<7>,1:12]\n" + + "[@0,0:0='x',<5>,1:0]\n" + + "[@1,1:1=' ',<6>,1:1]\n" + + "[@2,2:2='0',<2>,1:2]\n" + + "[@3,3:3=' ',<6>,1:3]\n" + + "[@4,4:4='1',<2>,1:4]\n" + + "[@5,5:5=' ',<6>,1:5]\n" + + "[@6,6:6='a',<5>,1:6]\n" + + "[@7,7:7='.',<4>,1:7]\n" + + "[@8,8:8='b',<5>,1:8]\n" + + "[@9,9:9=' ',<6>,1:9]\n" + + "[@10,10:10='a',<5>,1:10]\n" + + "[@11,11:11='.',<4>,1:11]\n" + + "[@12,12:12='l',<5>,1:12]\n" + "[@13,13:12='',<-1>,1:13]\n"; assertEquals(expecting, found); } @@ -207,7 +207,7 @@ public class TestLexerExec extends BaseTest { "A : 'a';\n"; String found = execLexer("L.g4", grammar, "L", ""); String expecting = - "[@0,0:-1='',<3>,1:0]\n" + + "[@0,0:-1='',<1>,1:0]\n" + "[@1,0:-1='',<-1>,1:0]\n"; assertEquals(expecting, found); } @@ -225,7 +225,7 @@ public class TestLexerExec extends BaseTest { found = execLexer("L.g4", grammar, "L", "a"); expecting = - "[@0,0:0='a',<3>,1:0]\n" + + "[@0,0:0='a',<1>,1:0]\n" + "[@1,1:0='',<-1>,1:1]\n"; assertEquals(expecting, found); } @@ -239,8 +239,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,5:6='34',<3>,2:1]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,5:6='34',<1>,2:1]\n" + "[@2,7:6='',<-1>,2:3]\n"; assertEquals(expecting, found); } @@ -254,8 +254,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,5:6='34',<3>,2:1]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,5:6='34',<1>,2:1]\n" + "[@2,7:6='',<-1>,2:3]\n"; assertEquals(expecting, found); } @@ -268,7 +268,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "xaf"); String expecting = "I\n" + - "[@0,0:2='xaf',<3>,1:0]\n" + + "[@0,0:2='xaf',<1>,1:0]\n" + "[@1,3:2='',<-1>,1:3]\n"; assertEquals(expecting, found); } @@ -282,8 +282,8 @@ public class TestLexerExec extends BaseTest { String expecting = "I\n" + "I\n" + - "[@0,0:0='a',<3>,1:0]\n" + - "[@1,2:2='x',<3>,1:2]\n" + + "[@0,0:0='a',<1>,1:0]\n" + + "[@1,2:2='x',<1>,1:2]\n" + "[@2,3:2='',<-1>,1:3]\n"; assertEquals(expecting, found); } @@ -300,10 +300,10 @@ public class TestLexerExec extends BaseTest { "I\n" + "ID\n" + "ID\n" + - "[@0,0:1='34',<3>,1:0]\n" + - "[@1,4:5='34',<3>,1:4]\n" + - "[@2,7:8='a2',<4>,1:7]\n" + - "[@3,10:12='abc',<4>,1:10]\n" + + "[@0,0:1='34',<1>,1:0]\n" + + "[@1,4:5='34',<1>,1:4]\n" + + "[@2,7:8='a2',<2>,1:7]\n" + + "[@3,10:12='abc',<2>,1:10]\n" + "[@4,18:17='',<-1>,2:3]\n"; assertEquals(expecting, found); } @@ -316,7 +316,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "00\r\n"); String expecting = "I\n" + - "[@0,0:1='00',<3>,1:0]\n" + + "[@0,0:1='00',<1>,1:0]\n" + "[@1,4:3='',<-1>,2:0]\n"; assertEquals(expecting, found); } @@ -329,7 +329,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "34 "); String expecting = "I\n" + - "[@0,0:1='34',<3>,1:0]\n" + + "[@0,0:1='34',<1>,1:0]\n" + "[@1,3:2='',<-1>,1:3]\n"; assertEquals(expecting, found); } @@ -343,8 +343,8 @@ public class TestLexerExec extends BaseTest { String expecting = "DASHBRACK\n" + "DASHBRACK\n" + - "[@0,0:0='-',<3>,1:0]\n" + - "[@1,2:2=']',<3>,1:2]\n" + + "[@0,0:0='-',<1>,1:0]\n" + + "[@1,2:2=']',<1>,1:2]\n" + "[@2,4:3='',<-1>,1:4]\n"; assertEquals(expecting, found); } @@ -357,7 +357,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "9"); String expecting = "A\n" + - "[@0,0:0='9',<3>,1:0]\n" + + "[@0,0:0='9',<1>,1:0]\n" + "[@1,1:0='',<-1>,1:1]\n"; assertEquals(expecting, found); } @@ -370,7 +370,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "b\"a"); String expecting = "A\n" + - "[@0,0:2='b\"a',<3>,1:0]\n" + + "[@0,0:2='b\"a',<1>,1:0]\n" + "[@1,3:2='',<-1>,1:3]\n"; assertEquals(expecting, found); } @@ -383,7 +383,7 @@ public class TestLexerExec extends BaseTest { String found = execLexer("L.g4", grammar, "L", "b\"\\a"); String expecting = "A\n" + - "[@0,0:3='b\"\\a',<3>,1:0]\n" + + "[@0,0:3='b\"\\a',<1>,1:0]\n" + "[@1,4:3='',<-1>,1:4]\n"; assertEquals(expecting, found); } diff --git a/tool/test/org/antlr/v4/test/TestListeners.java b/tool/test/org/antlr/v4/test/TestListeners.java index a683d4aed..3bd1cd5ad 100644 --- a/tool/test/org/antlr/v4/test/TestListeners.java +++ b/tool/test/org/antlr/v4/test/TestListeners.java @@ -6,6 +6,7 @@ public class TestListeners extends BaseTest { @Test public void testBasic() throws Exception { String grammar = "grammar T;\n" + + "@header {import org.antlr.v4.runtime.tree.ParseTree;}\n"+ "@members {\n" + "public static class LeafListener extends TBaseListener {\n" + " public void visitTerminal(ParseTree.TerminalNode node) {\n" + @@ -69,7 +70,7 @@ public class TestListeners extends BaseTest { result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "abc", false); expecting = "(a abc)\n" + - "[@0,0:2='abc',<6>,1:0]\n"; + "[@0,0:2='abc',<4>,1:0]\n"; assertEquals(expecting, result); } diff --git a/tool/test/org/antlr/v4/test/TestParseErrors.java b/tool/test/org/antlr/v4/test/TestParseErrors.java index 62c8cf67f..9a004e0d3 100644 --- a/tool/test/org/antlr/v4/test/TestParseErrors.java +++ b/tool/test/org/antlr/v4/test/TestParseErrors.java @@ -78,7 +78,7 @@ public class TestParseErrors extends BaseTest { "grammar T;\n" + "a : 'a' x='b' {System.out.println(\"conjured=\"+$x);} 'c' ;"; String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", false); - String expecting = "conjured=[@-1,-1:-1='',<3>,1:1]\n"; + String expecting = "conjured=[@-1,-1:-1='',<1>,1:1]\n"; assertEquals(expecting, result); } @@ -97,7 +97,7 @@ public class TestParseErrors extends BaseTest { "grammar T;\n" + "a : 'a' x=('b'|'c') {System.out.println(\"conjured=\"+$x);} 'd' ;"; String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false); - String expecting = "conjured=[@-1,-1:-1='',<3>,1:1]\n"; + String expecting = "conjured=[@-1,-1:-1='',<1>,1:1]\n"; assertEquals(expecting, result); } diff --git a/tool/test/org/antlr/v4/test/TestSemPredEvalLexer.java b/tool/test/org/antlr/v4/test/TestSemPredEvalLexer.java index 0606462b2..9f7ae053d 100644 --- a/tool/test/org/antlr/v4/test/TestSemPredEvalLexer.java +++ b/tool/test/org/antlr/v4/test/TestSemPredEvalLexer.java @@ -1,6 +1,7 @@ package org.antlr.v4.test; -import org.junit.*; +import org.junit.Ignore; +import org.junit.Test; public class TestSemPredEvalLexer extends BaseTest { @@ -13,8 +14,8 @@ public class TestSemPredEvalLexer extends BaseTest { "WS : (' '|'\\n') {skip();} ;"; String found = execLexer("L.g4", grammar, "L", "enum abc", true); String expecting = - "[@0,0:3='enum',<4>,1:0]\n" + - "[@1,5:7='abc',<5>,1:5]\n" + + "[@0,0:3='enum',<2>,1:0]\n" + + "[@1,5:7='abc',<3>,1:5]\n" + "[@2,8:7='',<-1>,1:8]\n"; // no dfa since preds on left edge assertEquals(expecting, found); } @@ -28,17 +29,17 @@ public class TestSemPredEvalLexer extends BaseTest { "WS : (' '|'\\n') {skip();} ;"; String found = execLexer("L.g4", grammar, "L", "enum abc enum", true); String expecting = - "[@0,0:3='enum',<4>,1:0]\n" + - "[@1,5:7='abc',<5>,1:5]\n" + - "[@2,9:12='enum',<4>,1:9]\n" + + "[@0,0:3='enum',<2>,1:0]\n" + + "[@1,5:7='abc',<3>,1:5]\n" + + "[@2,9:12='enum',<2>,1:9]\n" + "[@3,13:12='',<-1>,1:13]\n" + - "s0-' '->:s4=>6\n" + - "s0-'a'->:s5=>5\n" + - "s0-'e'->:s1=>5\n" + - ":s1=>5-'n'->:s2=>5\n" + - ":s2=>5-'u'->:s3=>5\n" + - ":s5=>5-'b'->:s5=>5\n" + - ":s5=>5-'c'->:s5=>5\n"; + "s0-' '->:s4=>4\n" + + "s0-'a'->:s5=>3\n" + + "s0-'e'->:s1=>3\n" + + ":s1=>3-'n'->:s2=>3\n" + + ":s2=>3-'u'->:s3=>3\n" + + ":s5=>3-'b'->:s5=>3\n" + + ":s5=>3-'c'->:s5=>3\n"; // didn't even created DFA 2nd time; old target of 'u' has "pred" flag set assertEquals(expecting, found); } diff --git a/tool/test/org/antlr/v4/test/TestSets.java b/tool/test/org/antlr/v4/test/TestSets.java index 412ca3e3c..f99114840 100644 --- a/tool/test/org/antlr/v4/test/TestSets.java +++ b/tool/test/org/antlr/v4/test/TestSets.java @@ -42,7 +42,7 @@ public class TestSets extends BaseTest { // from a nonfragment rule does not set the overall token. String grammar = "grammar P;\n" + - "a : C {System.out.println(_input);} ;\n" + + "a : C {System.out.println(_input.getText());} ;\n" + "fragment A : '1' | '2';\n" + "fragment B : '3' '4';\n" + "C : A | B;\n"; @@ -72,7 +72,7 @@ public class TestSets extends BaseTest { @Test public void testParserNotToken() throws Exception { String grammar = "grammar T;\n" + - "a : ~'x' 'z' {System.out.println(_input);} ;\n"; + "a : ~'x' 'z' {System.out.println(_input.getText());} ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "zz", debug); assertEquals("zz\n", found); @@ -90,7 +90,7 @@ public class TestSets extends BaseTest { @Test public void testRuleAsSet() throws Exception { String grammar = "grammar T;\n" + - "a @after {System.out.println(_input);} : 'a' | 'b' |'c' ;\n"; + "a @after {System.out.println(_input.getText());} : 'a' | 'b' |'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "b", debug); assertEquals("b\n", found); @@ -109,7 +109,7 @@ public class TestSets extends BaseTest { @Test public void testOptionalSingleElement() throws Exception { String grammar = "grammar T;\n" + - "a : A? 'c' {System.out.println(_input);} ;\n" + + "a : A? 'c' {System.out.println(_input.getText());} ;\n" + "A : 'b' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "bc", debug); @@ -119,7 +119,7 @@ public class TestSets extends BaseTest { @Test public void testOptionalLexerSingleElement() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : 'b'? 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "bc", debug); @@ -129,7 +129,7 @@ public class TestSets extends BaseTest { @Test public void testStarLexerSingleElement() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : 'b'* 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "bbbbc", debug); @@ -142,7 +142,7 @@ public class TestSets extends BaseTest { @Test public void testPlusLexerSingleElement() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : 'b'+ 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "bbbbc", debug); @@ -152,7 +152,7 @@ public class TestSets extends BaseTest { @Test public void testOptionalSet() throws Exception { String grammar = "grammar T;\n" + - "a : ('a'|'b')? 'c' {System.out.println(_input);} ;\n"; + "a : ('a'|'b')? 'c' {System.out.println(_input.getText());} ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", debug); assertEquals("ac\n", found); @@ -161,7 +161,7 @@ public class TestSets extends BaseTest { @Test public void testStarSet() throws Exception { String grammar = "grammar T;\n" + - "a : ('a'|'b')* 'c' {System.out.println(_input);} ;\n"; + "a : ('a'|'b')* 'c' {System.out.println(_input.getText());} ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaac", debug); assertEquals("abaac\n", found); @@ -170,7 +170,7 @@ public class TestSets extends BaseTest { @Test public void testPlusSet() throws Exception { String grammar = "grammar T;\n" + - "a : ('a'|'b')+ 'c' {System.out.println(_input);} ;\n"; + "a : ('a'|'b')+ 'c' {System.out.println(_input.getText());} ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaac", debug); assertEquals("abaac\n", found); @@ -179,7 +179,7 @@ public class TestSets extends BaseTest { @Test public void testLexerOptionalSet() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : ('a'|'b')? 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", debug); @@ -189,7 +189,7 @@ public class TestSets extends BaseTest { @Test public void testLexerStarSet() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : ('a'|'b')* 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaac", debug); @@ -199,7 +199,7 @@ public class TestSets extends BaseTest { @Test public void testLexerPlusSet() throws Exception { String grammar = "grammar T;\n" + - "a : A {System.out.println(_input);} ;\n" + + "a : A {System.out.println(_input.getText());} ;\n" + "A : ('a'|'b')+ 'c' ;\n"; String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaac", debug); diff --git a/tool/test/org/antlr/v4/test/TestTokenStreamRewriter.java b/tool/test/org/antlr/v4/test/TestTokenStreamRewriter.java index 9b8248c05..372c18d6c 100644 --- a/tool/test/org/antlr/v4/test/TestTokenStreamRewriter.java +++ b/tool/test/org/antlr/v4/test/TestTokenStreamRewriter.java @@ -313,7 +313,7 @@ public class TestTokenStreamRewriter extends BaseTest { catch (IllegalArgumentException iae) { exc = iae; } - String expecting = "insert op ,1:1]:\"0\"> within boundaries of previous ,1:0]..[@2,2:2='c',<5>,1:2]:\"x\">"; + String expecting = "insert op ,1:1]:\"0\"> within boundaries of previous ,1:0]..[@2,2:2='c',<3>,1:2]:\"x\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); } @@ -468,7 +468,7 @@ public class TestTokenStreamRewriter extends BaseTest { catch (IllegalArgumentException iae) { exc = iae; } - String expecting = "insert op ,1:4]:\"y\"> within boundaries of previous ,1:2]..[@4,4:4='c',<5>,1:4]:\"x\">"; + String expecting = "insert op ,1:4]:\"y\"> within boundaries of previous ,1:2]..[@4,4:4='c',<3>,1:4]:\"x\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); } @@ -547,7 +547,7 @@ public class TestTokenStreamRewriter extends BaseTest { catch (IllegalArgumentException iae) { exc = iae; } - String expecting = "replace op boundaries of ,1:3]..[@5,5:5='b',<4>,1:5]:\"foo\"> overlap with previous ,1:2]..[@4,4:4='c',<5>,1:4]:\"xyz\">"; + String expecting = "replace op boundaries of ,1:3]..[@5,5:5='b',<2>,1:5]:\"foo\"> overlap with previous ,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); } @@ -574,7 +574,7 @@ public class TestTokenStreamRewriter extends BaseTest { catch (IllegalArgumentException iae) { exc = iae; } - String expecting = "replace op boundaries of ,1:1]..[@3,3:3='c',<5>,1:3]:\"foo\"> overlap with previous ,1:2]..[@4,4:4='c',<5>,1:4]:\"xyz\">"; + String expecting = "replace op boundaries of ,1:1]..[@3,3:3='c',<3>,1:3]:\"foo\"> overlap with previous ,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); } @@ -737,7 +737,7 @@ public class TestTokenStreamRewriter extends BaseTest { catch (IllegalArgumentException iae) { exc = iae; } - String expecting = "replace op boundaries of ,1:1]..[@2,2:2='c',<5>,1:2]:\"foo\"> overlap with previous ,1:0]..[@3,3:3='c',<5>,1:3]:\"bar\">"; + String expecting = "replace op boundaries of ,1:1]..[@2,2:2='c',<3>,1:2]:\"foo\"> overlap with previous ,1:0]..[@3,3:3='c',<3>,1:3]:\"bar\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); } diff --git a/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java b/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java index 6c4a431c1..b3add4d38 100644 --- a/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java +++ b/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java @@ -1,10 +1,14 @@ package org.antlr.v4.test; import org.antlr.v4.runtime.Token; -import org.antlr.v4.tool.*; +import org.antlr.v4.tool.Grammar; +import org.antlr.v4.tool.LexerGrammar; import org.junit.Test; -import java.util.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.StringTokenizer; public class TestTokenTypeAssignment extends BaseTest { @@ -132,7 +136,7 @@ public class TestTokenTypeAssignment extends BaseTest { String grammar = "grammar P;\n" + "tokens { B='}'; }\n"+ - "a : A B {System.out.println(_input);} ;\n"+ + "a : A B {System.out.println(_input.getText());} ;\n"+ "A : 'a' ;\n" + "B : '}' ;\n"+ "WS : (' '|'\\n') {skip();} ;"; @@ -147,7 +151,7 @@ public class TestTokenTypeAssignment extends BaseTest { String grammar = "grammar P;\n" + "tokens { B='}'; }\n"+ - "a : A '}' {System.out.println(_input);} ;\n"+ + "a : A '}' {System.out.println(_input.getText());} ;\n"+ "A : 'a' ;\n" + "B : '}' ;\n"+ "WS : (' '|'\\n') {skip();} ;";