more tests

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9103]
This commit is contained in:
parrt 2011-10-03 11:04:01 -08:00
parent 48e292dcdd
commit 473e56d59f
2 changed files with 27 additions and 2 deletions

View File

@ -1,6 +1,8 @@
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.RuleTransition;
import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.runtime.misc.IntervalSet;
/** This is the default error handling mechanism for ANTLR parsers /** This is the default error handling mechanism for ANTLR parsers
@ -97,7 +99,8 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
endErrorCondition(); endErrorCondition();
return; return;
} }
recoverInline(recognizer); reportUnwantedToken(recognizer);
consumeUntil(recognizer, expecting);
} }
public void reportNoViableAlternative(BaseRecognizer recognizer, public void reportNoViableAlternative(BaseRecognizer recognizer,

View File

@ -150,6 +150,16 @@ public class TestParseErrors extends BaseTest {
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@Test public void testMultiTokenDeletionBeforeLoop() throws Exception {
String grammar =
"grammar T;\n" +
"a : 'a' 'b'* 'c';";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aacabc", false);
String expecting = "line 1:1 extraneous input 'a' expecting {'b', 'c'}\n";
String result = stderrDuringParse;
assertEquals(expecting, result);
}
@Test public void testSingleTokenDeletionDuringLoop() throws Exception { @Test public void testSingleTokenDeletionDuringLoop() throws Exception {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +
@ -160,6 +170,18 @@ public class TestParseErrors extends BaseTest {
assertEquals(expecting, result); assertEquals(expecting, result);
} }
@Test public void testMultiTokenDeletionDuringLoop() throws Exception {
String grammar =
"grammar T;\n" +
"a : 'a' 'b'* 'c' ;";
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abaaababc", false);
String expecting =
"line 1:2 extraneous input 'a' expecting {'b', 'c'}\n" +
"line 1:6 extraneous input 'a' expecting {'b', 'c'}\n";
String result = stderrDuringParse;
assertEquals(expecting, result);
}
@Test public void testLL1ErrorInfo() throws Exception { @Test public void testLL1ErrorInfo() throws Exception {
String grammar = String grammar =
"grammar T;\n" + "grammar T;\n" +