forked from jasder/antlr
Oops, removed some unwanted changes
This commit is contained in:
parent
00eb4f89ca
commit
bf83ee42bc
|
@ -62,7 +62,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
this.stderrDuringParse);
|
||||
}
|
||||
|
||||
public String testCtxSensitiveDFA(String input) {
|
||||
@Test public void testCtxSensitiveDFA() {
|
||||
String grammar =
|
||||
"grammar T;\n"+
|
||||
"s @after {dumpDFA();}\n" +
|
||||
|
@ -73,12 +73,8 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n"+
|
||||
"INT : '0'..'9'+ ;\n"+
|
||||
"WS : (' '|'\\t'|'\\n')+ -> skip ;\n";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "s", input, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtxSensitiveDFA1() {
|
||||
String result = testCtxSensitiveDFA("$ 34 abc");
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"$ 34 abc", true);
|
||||
String expecting =
|
||||
"Decision 1:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
|
@ -87,12 +83,10 @@ public class TestFullContextParsing extends BaseTest {
|
|||
assertEquals("line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'\n" +
|
||||
"line 1:2 reportContextSensitivity d=1 (e), input='34'\n",
|
||||
this.stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtxSensitiveDFA2() {
|
||||
String result = testCtxSensitiveDFA("@ 34 abc");
|
||||
String expecting =
|
||||
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"@ 34 abc", true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
"s0-INT->s1\n" +
|
||||
"s1-ID->:s2^=>1\n";
|
||||
|
|
|
@ -224,8 +224,7 @@ public class TestLexerExec extends BaseTest {
|
|||
assertNull(stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLexerRuleRefWithWildcardStar1() throws Exception {
|
||||
@Test public void testRecursiveLexerRuleRefWithWildcardStar() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"CMT : '/*' (CMT | .)*? '*/' ;\n" +
|
||||
|
@ -246,24 +245,14 @@ public class TestLexerExec extends BaseTest {
|
|||
"/* /*nested*/ */\n");
|
||||
assertEquals(expecting, found);
|
||||
assertNull(stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLexerRuleRefWithWildcardStar2() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"CMT : '/*' (CMT | .)*? '*/' ;\n" +
|
||||
"WS : (' '|'\\n')+ ;\n"
|
||||
/*+ "ANY : .;"*/;
|
||||
|
||||
// stuff on end of comment doesn't match another rule
|
||||
String expecting =
|
||||
expecting =
|
||||
"[@0,0:8='/* ick */',<1>,1:0]\n" +
|
||||
"[@1,10:10='\\n',<2>,1:10]\n" +
|
||||
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
|
||||
"[@3,38:38='\\n',<2>,3:17]\n" +
|
||||
"[@4,39:38='<EOF>',<-1>,4:18]\n";
|
||||
String found = execLexer("L.g4", grammar, "L",
|
||||
found = execLexer("L.g4", grammar, "L",
|
||||
"/* ick */x\n" +
|
||||
"/* /* */x\n" +
|
||||
"/* /*nested*/ */x\n");
|
||||
|
@ -273,8 +262,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"line 3:16 token recognition error at: 'x'\n", stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLexerRuleRefWithWildcardPlus1() throws Exception {
|
||||
@Test public void testRecursiveLexerRuleRefWithWildcardPlus() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"CMT : '/*' (CMT | .)+? '*/' ;\n" +
|
||||
|
@ -295,24 +283,14 @@ public class TestLexerExec extends BaseTest {
|
|||
"/* /*nested*/ */\n");
|
||||
assertEquals(expecting, found);
|
||||
assertNull(stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLexerRuleRefWithWildcardPlus2() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"CMT : '/*' (CMT | .)+? '*/' ;\n" +
|
||||
"WS : (' '|'\\n')+ ;\n"
|
||||
/*+ "ANY : .;"*/;
|
||||
|
||||
// stuff on end of comment doesn't match another rule
|
||||
String expecting =
|
||||
expecting =
|
||||
"[@0,0:8='/* ick */',<1>,1:0]\n" +
|
||||
"[@1,10:10='\\n',<2>,1:10]\n" +
|
||||
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
|
||||
"[@3,38:38='\\n',<2>,3:17]\n" +
|
||||
"[@4,39:38='<EOF>',<-1>,4:18]\n";
|
||||
String found = execLexer("L.g4", grammar, "L",
|
||||
found = execLexer("L.g4", grammar, "L",
|
||||
"/* ick */x\n" +
|
||||
"/* /* */x\n" +
|
||||
"/* /*nested*/ */x\n");
|
||||
|
|
|
@ -165,7 +165,7 @@ public class TestParserExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> channel(HIDDEN);\n";
|
||||
|
||||
@Test public void testIfIfElseGreedyBinding1() throws Exception {
|
||||
@Test public void testIfIfElseGreedyBinding() throws Exception {
|
||||
final String input = "if y if y x else x";
|
||||
final String expectedInnerBound = "if y x else x\nif y if y x else x\n";
|
||||
|
||||
|
@ -173,14 +173,8 @@ public class TestParserExec extends BaseTest {
|
|||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", input, false);
|
||||
assertEquals(expectedInnerBound, found);
|
||||
|
||||
}
|
||||
|
||||
@Test public void testIfIfElseGreedyBinding2() throws Exception {
|
||||
final String input = "if y if y x else x";
|
||||
final String expectedInnerBound = "if y x else x\nif y if y x else x\n";
|
||||
|
||||
String grammar = String.format(ifIfElseGrammarFormat, "('else' statement|)");
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", input, false);
|
||||
grammar = String.format(ifIfElseGrammarFormat, "('else' statement|)");
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "start", input, false);
|
||||
assertEquals(expectedInnerBound, found);
|
||||
}
|
||||
|
||||
|
@ -197,20 +191,20 @@ public class TestParserExec extends BaseTest {
|
|||
assertEquals(expectedOuterBound, found);
|
||||
}
|
||||
|
||||
@Test public void testAStar() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ID* {System.out.println($text);} ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;\n";
|
||||
@Test public void testAStar() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ID* {System.out.println($text);} ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;\n";
|
||||
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"", false);
|
||||
assertEquals("\n", found);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"", false);
|
||||
assertEquals("\n", found);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
|
||||
@Test public void testLL1OptionalBlock() throws Exception {
|
||||
String grammar =
|
||||
|
@ -279,7 +273,7 @@ public class TestParserExec extends BaseTest {
|
|||
* https://github.com/antlr/antlr4/issues/41
|
||||
*/
|
||||
@Test
|
||||
public void testOptional1() throws Exception {
|
||||
public void testOptional() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"stat : ifstat | 'x';\n" +
|
||||
|
@ -290,46 +284,16 @@ public class TestParserExec extends BaseTest {
|
|||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptional2() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"stat : ifstat | 'x';\n" +
|
||||
"ifstat : 'if' stat ('else' stat)?;\n" +
|
||||
"WS : [ \\n\\t]+ -> skip ;"
|
||||
;
|
||||
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x else x", false);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x else x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptional3() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"stat : ifstat | 'x';\n" +
|
||||
"ifstat : 'if' stat ('else' stat)?;\n" +
|
||||
"WS : [ \\n\\t]+ -> skip ;"
|
||||
;
|
||||
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x", false);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptional4() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"stat : ifstat | 'x';\n" +
|
||||
"ifstat : 'if' stat ('else' stat)?;\n" +
|
||||
"WS : [ \\n\\t]+ -> skip ;"
|
||||
;
|
||||
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if if x else x", false);
|
||||
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "stat", "if if x else x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue