def evaluate(self, t: ParseTree): # return all TerminalNode descendants of t that match tokenType (or do not match if inverted) return filter( lambda c: isinstance(c, TerminalNode) and (self.invert ^ (c.symbol.type == self.tokenType)), Trees.descendants(t))
def evaluate(self, t:ParseTree): if self.invert: return list() # !* is weird but valid (empty) else: return Trees.descendants(t)
def evaluate(self, t: ParseTree): # return all ParserRuleContext descendants of t that match ruleIndex (or do not match if inverted) return filter( lambda c: isinstance(c, ParserRuleContext) and (self.invert ^ (c.getRuleIndex() == self.ruleIndex)), Trees.descendants(t))