Created
March 28, 2017 10:31
-
-
Save Wonicon/886eaae2557085637aea2c13ce1bccf6 to your computer and use it in GitHub Desktop.
Check ancestor in ANTLR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.antlr.v4.runtime.ParserRuleContext; | |
public class AntlrExt { | |
public static boolean underContext(ParserRuleContext curr, ParserRuleContext target, ParserRuleContext limit) { | |
do { | |
curr = curr.getParent(); | |
} while (curr.getRuleIndex() != target.getRuleIndex() && curr.getRuleIndex() != limit.getRuleIndex()); | |
return curr.getRuleIndex() == target.getRuleIndex(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment