Skip to content

Commit 5e1d1fc

Browse files
committed
track repeated child tokens like we do for sibling lists of subtrees.
1 parent 96e86d1 commit 5e1d1fc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

java/src/org/antlr/codebuff/CollectFeatures.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,16 @@ public static int getChildIndex(ParseTree t) {
722722
// we know we have a parent now
723723
// check to see if we are 2nd or beyond element in a sibling list
724724
if ( t instanceof ParserRuleContext ) {
725-
List<ParserRuleContext> siblings = ((ParserRuleContext)parent).getRuleContexts(((ParserRuleContext)t).getClass());
725+
List<ParserRuleContext> siblings =
726+
((ParserRuleContext)parent).getRuleContexts(((ParserRuleContext)t).getClass());
727+
if ( siblings.size()>1 && siblings.indexOf(t)>0 ) {
728+
return CHILD_INDEX_LIST_ELEMENT;
729+
}
730+
}
731+
else {
732+
TerminalNode node = (TerminalNode)t;
733+
List<TerminalNode> siblings =
734+
((ParserRuleContext)parent).getTokens(node.getSymbol().getType());
726735
if ( siblings.size()>1 && siblings.indexOf(t)>0 ) {
727736
return CHILD_INDEX_LIST_ELEMENT;
728737
}

0 commit comments

Comments
 (0)