use of org.antlr.v4.runtime.Lexer in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testMustTrackPreviousGoodAlt3.
@Test
public void testMustTrackPreviousGoodAlt3() 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 B | A | A B C ;");
checkMatchedAlt(lg, g, "a", 2);
checkMatchedAlt(lg, g, "ab", 1);
checkMatchedAlt(lg, g, "abc", 3);
checkMatchedAlt(lg, g, "ad", 2);
checkMatchedAlt(lg, g, "abd", 1);
checkMatchedAlt(lg, g, "abcd", 3);
}
use of org.antlr.v4.runtime.Lexer in project antlr4 by tunnelvisionlabs.
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.Lexer in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testPEGAchillesHeel.
@Test
public void testPEGAchillesHeel() 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 | A B ;");
checkMatchedAlt(lg, g, "a", 1);
checkMatchedAlt(lg, g, "ab", 2);
checkMatchedAlt(lg, g, "abc", 2);
}
use of org.antlr.v4.runtime.Lexer in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testMustTrackPreviousGoodAlt2.
@Test
public void testMustTrackPreviousGoodAlt2() 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 ;");
checkMatchedAlt(lg, g, "a", 1);
checkMatchedAlt(lg, g, "ab", 2);
checkMatchedAlt(lg, g, "abc", 3);
checkMatchedAlt(lg, g, "ad", 1);
checkMatchedAlt(lg, g, "abd", 2);
checkMatchedAlt(lg, g, "abcd", 3);
}
use of org.antlr.v4.runtime.Lexer in project antlr4 by tunnelvisionlabs.
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);
}
Aggregations