use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestGrammarParserInterpreter method testOneAlt.
@Test
public void testOneAlt() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : ID\n" + " ;\n", lg);
testInterp(lg, g, "s", "a", "(s:1 a)");
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestParserInterpreter method testEmptyRuleAfterEOFInChild.
@Test
public void testEmptyRuleAfterEOFInChild() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : x y;\n" + "x : A EOF ;\n" + "y : ;", lg);
ParseTree t = testInterp(lg, g, "s", "a", "(s (x a <EOF>) y)");
// s
assertEquals("0..1", t.getSourceInterval().toString());
// x
assertEquals("0..1", t.getChild(0).getSourceInterval().toString());
// unspecified assertEquals("1..0", t.getChild(1).getSourceInterval().toString()); // y
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestParserInterpreter method testEmptyInputWithCallsAfter.
@Test
public void testEmptyInputWithCallsAfter() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : x y ;\n" + "x : EOF ;\n" + "y : z ;\n" + "z : ;", lg);
ParseTree t = testInterp(lg, g, "s", "", "(s (x <EOF>) (y z))");
// s
assertEquals("0..0", t.getSourceInterval().toString());
// x
assertEquals("0..0", t.getChild(0).getSourceInterval().toString());
// unspecified assertEquals("0..-1", t.getChild(1).getSourceInterval().toString()); // x
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
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)");
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestParserInterpreter method testEmptyInput.
@Test
public void testEmptyInput() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : x EOF ;\n" + "x : ;\n", lg);
ParseTree t = testInterp(lg, g, "s", "", "(s x <EOF>)");
// s
assertEquals("0..0", t.getSourceInterval().toString());
// x
assertEquals("0..-1", t.getChild(0).getSourceInterval().toString());
}
Aggregations