use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestGrammarParserInterpreter method testAltsAsSet.
@Test
public void testAltsAsSet() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : ID\n" + " | INT\n" + " ;\n", lg);
testInterp(lg, g, "s", "a", "(s:1 a)");
testInterp(lg, g, "s", "3", "(s:1 3)");
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestParserInterpreter method testCall2.
@Test
public void testCall2() 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" + "s : t C ;\n" + "t : u ;\n" + "u : A{;} | B ;\n", lg);
testInterp(lg, g, "s", "ac", "(s (t (u a)) c)");
testInterp(lg, g, "s", "bc", "(s (t (u b)) c)");
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestParserInterpreter method testEOFInChild.
@Test
public void testEOFInChild() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : x ;\n" + "x : A EOF ;", lg);
ParseTree t = testInterp(lg, g, "s", "a", "(s (x a <EOF>))");
assertEquals("0..1", t.getSourceInterval().toString());
assertEquals("0..1", t.getChild(0).getSourceInterval().toString());
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestParserInterpreter method testEmptyStartRule.
@Test
public void testEmptyStartRule() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : ;", lg);
testInterp(lg, g, "s", "", "s");
testInterp(lg, g, "s", "a", "s");
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestParserInterpreter method testStarAorB.
@Test
public void testStarAorB() 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" + "s : (A{;}|B)* C ;\n", lg);
testInterp(lg, g, "s", "c", "(s c)");
testInterp(lg, g, "s", "ac", "(s a c)");
testInterp(lg, g, "s", "bc", "(s b c)");
testInterp(lg, g, "s", "abaaabc", "(s a b a a a b c)");
testInterp(lg, g, "s", "babac", "(s b a b a c)");
}
Aggregations