use of org.antlr.v4.runtime.Parser in project antlr4 by antlr.
the class TestGrammarParserInterpreter method testAltsWithLabels.
@Test
public void testAltsWithLabels() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : ID # foo\n" + " | INT # bar\n" + " ;\n", lg);
// it won't show the labels here because my simple node text provider above just shows the alternative
testInterp(lg, g, "s", "a", "(s:1 a)");
testInterp(lg, g, "s", "3", "(s:2 3)");
}
use of org.antlr.v4.runtime.Parser 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.runtime.Parser 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.runtime.Parser 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.runtime.Parser 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");
}
Aggregations