use of org.antlr.v4.runtime.tree.RuleNode in project antlr4 by antlr.
the class TestVisitors method testShouldNotVisitEOF.
/**
* This test verifies that {@link AbstractParseTreeVisitor#visitChildren} does not call
* {@link ParseTreeVisitor#visit} after {@link AbstractParseTreeVisitor#shouldVisitNextChild} returns
* {@code false}.
*/
@Test
public void testShouldNotVisitEOF() {
String input = "A";
VisitorBasicLexer lexer = new VisitorBasicLexer(new ANTLRInputStream(input));
VisitorBasicParser parser = new VisitorBasicParser(new CommonTokenStream(lexer));
VisitorBasicParser.SContext context = parser.s();
Assert.assertEquals("(s A <EOF>)", context.toStringTree(parser));
VisitorBasicVisitor<String> listener = new VisitorBasicBaseVisitor<String>() {
@Override
public String visitTerminal(TerminalNode node) {
return node.getSymbol().toString() + "\n";
}
@Override
protected boolean shouldVisitNextChild(RuleNode node, String currentResult) {
return currentResult == null || currentResult.isEmpty();
}
};
String result = listener.visit(context);
String expected = "[@0,0:0='A',<1>,1:0]\n";
Assert.assertEquals(expected, result);
}
Aggregations