private static void _findAllNodes(IParseTree t, int index, bool findTokens, IList<IParseTree> nodes)
{
// check this node (the root) first
if (findTokens && t is ITerminalNode)
{
ITerminalNode tnode = (ITerminalNode)t;
if (tnode.Symbol.Type == index)
{
nodes.Add(t);
}
}
else
{
if (!findTokens && t is ParserRuleContext)
{
ParserRuleContext ctx = (ParserRuleContext)t;
if (ctx.RuleIndex == index)
{
nodes.Add(t);
}
}
}
// check children
for (int i = 0; i < t.ChildCount; i++)
{
_findAllNodes(t.GetChild(i), index, findTokens, nodes);
}
}