use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestATNInterpreter method testAmbigAltChooseFirstWithFollowingToken.
@Test
public void testAmbigAltChooseFirstWithFollowingToken() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n" + "C : 'c' ;\n" + "D : 'd' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + // first alt
"a : (A B | A B) C ;");
checkMatchedAlt(lg, g, "abc", 1);
checkMatchedAlt(lg, g, "abcd", 1);
}
use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestATNInterpreter method testSimpleNoBlock.
@Test
public void testSimpleNoBlock() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n" + "C : 'c' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "a : A B ;");
checkMatchedAlt(lg, g, "ab", 1);
}
use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestATNInterpreter method testMustTrackPreviousGoodAlt2WithEOF.
@Test(expected = NoViableAltException.class)
public void testMustTrackPreviousGoodAlt2WithEOF() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n" + "C : 'c' ;\n" + "D : 'd' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "a : (A | A B | A B C) EOF;");
checkMatchedAlt(lg, g, "a", 1);
checkMatchedAlt(lg, g, "ab", 2);
checkMatchedAlt(lg, g, "abc", 3);
try {
checkMatchedAlt(lg, g, "abd", 1);
} catch (NoViableAltException re) {
assertEquals(2, re.getOffendingToken().getTokenIndex());
assertEquals(4, re.getOffendingToken().getType());
throw re;
}
}
use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestATNDeserialization method testNot.
@Test
public void testNot() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "tokens {A, B, C}\n" + "a : ~A ;");
checkDeserializationIsStable(g);
}
use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestATNConstruction method testAorBplus.
@Test
public void testAorBplus() throws Exception {
Grammar g = new Grammar("parser grammar P;\n" + "a : (A|B{;})+;");
String expecting = "RuleStart_a_0->PlusBlockStart_5\n" + "PlusBlockStart_5->s2\n" + "PlusBlockStart_5->s3\n" + "s2-A->BlockEnd_6\n" + "s3-B->s4\n" + "BlockEnd_6->PlusLoopBack_7\n" + "s4-action_0:-1->BlockEnd_6\n" + "PlusLoopBack_7->PlusBlockStart_5\n" + "PlusLoopBack_7->s8\n" + "s8->RuleStop_a_1\n" + "RuleStop_a_1-EOF->s9\n";
checkRuleATN(g, "a", expecting);
}
Aggregations