private static void FindSpecificNode(IAstNode node, int position, Func <IAstNode, bool> match, ref IAstNode deepestNode, bool includeEnd = false) { if (position == node.Start || (!node.Contains(position) && !(includeEnd && node.End == position))) { return; // not this element } if (match(node)) { deepestNode = node; } for (int i = 0; i < node.Children.Count && node.Children[i].Start <= position; i++) { FindSpecificNode(node.Children[i], position, match, ref deepestNode, includeEnd); } }