use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testArbitraryLeftPrefix.
@Test
public void testArbitraryLeftPrefix() 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 | A+ C ;");
checkMatchedAlt(lg, g, "aac", 2);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testAmbigAltChooseFirst.
@Test
public void testAmbigAltChooseFirst() 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 ;");
checkMatchedAlt(lg, g, "ab", 1);
checkMatchedAlt(lg, g, "abc", 1);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testCommonLeftPrefix.
@Test
public void testCommonLeftPrefix() 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 | A C ;");
checkMatchedAlt(lg, g, "ab", 1);
checkMatchedAlt(lg, g, "ac", 2);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNInterpreter method testMustTrackPreviousGoodAlt.
@Test
public void testMustTrackPreviousGoodAlt() 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, "ac", 1);
checkMatchedAlt(lg, g, "abc", 2);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class BaseTest method createATN.
protected ATN createATN(Grammar g, boolean useSerializer) {
if (g.atn == null) {
semanticProcess(g);
assertEquals(0, g.tool.getNumErrors());
ParserATNFactory f;
if (g.isLexer()) {
f = new LexerATNFactory((LexerGrammar) g);
} else {
f = new ParserATNFactory(g);
}
g.atn = f.createATN();
assertEquals(0, g.tool.getNumErrors());
}
ATN atn = g.atn;
if (useSerializer) {
char[] serialized = ATNSerializer.getSerializedAsChars(atn, Arrays.asList(g.getRuleNames()));
return new ATNDeserializer().deserialize(serialized);
}
return atn;
}
Aggregations