If you want to keep track of a single syntax node while you're changing the tree, you can use SyntaxAnnotation.

To use it, create a new SyntaxAnnotation (or a custom derived type, if you need to keep some additional information with that annotation) and then add it to a node by calling annotation.AddAnnotationTo(node) or node.WithAdditionalAnnotations(annotation). Keep in mind that the node is still immutable, so you need to replace the original one with the annotated one in the tree.

Then, after you perform some modifications to the tree, you can get the annotated node back by using something like parentNode.GetAnnotatedNodesAndTokens(annotation).Single().AsNode(). (You can also get all nodes annotated by a specific derived type of annotation by parentNode.GetAnnotatedNodesAndTokens(typeof(CustomAnnotationType)).)

Locating a node in a CompilationUnitSyntax AND SemanticModel
Is it possible to write code in Mathematica that implements various differentiation methods (like forward, central, extrapolated, etc.)?
