Skip to content

Commit 1b989c2

Browse files
committed
small cleanup. getparent for terminals was getting parent's parent. guard against empty parent.
1 parent ec327d1 commit 1b989c2

3 files changed

Lines changed: 8 additions & 265 deletions

File tree

java/grammars/org/antlr/codebuff/Clojure.g4

Lines changed: 0 additions & 261 deletions
This file was deleted.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,15 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
481481
ParserRuleContext ancestorParent2 = null;
482482
if ( earliestLeftAncestor==null ) { // just use regular parent then
483483
ancestorParent = getParent(node);
484-
ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
484+
if ( ancestorParent!=null ) {
485+
ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
486+
}
485487
}
486488
else {
487489
ancestorParent = getParent(earliestLeftAncestor); // get parent but skip chain rules
488-
ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
490+
if ( ancestorParent!=null ) {
491+
ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
492+
}
489493
}
490494
ParserRuleContext ancestorParent3 = ancestorParent2!=null ? ancestorParent2.getParent() : null;
491495
ParserRuleContext ancestorParent4 = ancestorParent3!=null ? ancestorParent3.getParent() : null;
@@ -787,7 +791,7 @@ public static List<Token> getRealTokens(CommonTokenStream tokens) {
787791
}
788792

789793
public static ParserRuleContext getParent(TerminalNode p) {
790-
return getParent((ParserRuleContext)p.getParent());
794+
return parentClosure((ParserRuleContext)p.getParent());
791795
}
792796

793797
/** Same as p.getParent() except we scan through chain rule nodes */

java/src/org/antlr/codebuff/Tool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* Testing:
3232
*
33-
* Tool -antlr ../grammars /Users/parrt/antlr/code/grammars-v4/clojure/Clojure.g4
33+
* Tool -antlr grammars /Users/parrt/antlr/code/grammars-v4/clojure/Clojure.g4
3434
* Tool -java ../samples/stringtemplate4 src/org/antlr/codebuff/Tool.java
3535
*/
3636
public class Tool {

0 commit comments

Comments
 (0)