Hi Joe,
The ParserRuleContext::getRuleContexts method is probably what you are
looking for. Assuming you're doing this more than once, and hence want
a helper to do it in a generic fashion, something like this:
public List<String> getChildTextFromRules(Collection<? extends
ParserRuleContext> rules, Class<? extends ParserRuleContext>
childType) {
return rules
.stream()
.flatMap(stmt -> stmt.getRuleContexts(childType).stream())
.map(ParserRuleContext::getText)
.collect(Collectors.toList());
}
(Or write it using for loops instead of streams, if you prefer.)
Then your example visitor method body just becomes:
return getChildTextFromRules(ctx.ss,
InterfaceDemoParser.IdentifierContext.class);
Cheers,
Duane.
> --
> You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
antlr-discussi...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/antlr-discussion/b9c88750-51cc-4435-9d99-ca891a59ba21%40googlegroups.com.
--
"I never could learn to drink that blood and call it wine" - Bob Dylan