Introduce the EditablePositioned full-fidelity syntax tree
Summary:
Per https://fburl.com/coroutine-debugging, we need a tree that can handle both editing //and// repositioning. This diff introduces this, with the following new types.
=== `SourceData`
This holds data related to the //original// source text. Right now, that's just position information. That's probably all it will ever be. If we have an instance of one of these, then we know where a token or syntax was originally positioned. This also factors out the common logic for computing things like offsets and spans that are used elsewhere in the code.
== `EditablePositionedToken`
An `EditablePositionedToken` represents a token that comes from a positioned source but may have been modified. The token may have had its text or kind changed, or may have been moved to a new location in the AST. An `EditablePositionedToken` falls into one of these categories:
* **Original.** The token was positioned in the original source text and not modified.
* **SynthesizedFromOriginal.** The token was positioned in the original `SourceText` and modified. It may have had its text or kind changed, and it may now be positioned in a location that does not logically correspond to its location in the original `SourceText`.
* **Synthetic.** The token never existed in the original `SourceText`. It was synthesized during the AST computation process.
== `EditablePositionedSyntax`
An `EditablePositionedSyntax` represents a syntax that comes from a positioned source but may have been modified. The syntax may have had its children changed, or may have been moved to a new location in the AST. An `EditablePositionedSyntax` falls into one of these categories:
* **Positioned.** The syntax was positioned in the original source text. It or its children may have been modified.
* **Synthetic.** The syntax never existed in the original `SourceText`. It was synthesized during the AST computation process. Note that this does **not** imply that all of its children are synthetic.
---
All together, this should enable us to move tokens/syntaxes around, recombine them, etc. As long as we maintain handle(s) to the original `SourceData`, we will have enough information to reconstruct the positions of the syntaxes in the original source text.
**Naming is hard!** "EditablePositioned"-blah-blah is not very descriptive. Do you know of a better name? `SynthesiableSyntax`? `DerivedSyntax`? Let me know your thoughts in the comment section below!
**Overall design:** https://fburl.com/coroutine-debugging
Reviewed By: ericlippert
Differential Revision:
D5661355
fbshipit-source-id:
1bfba71da5de80b969fafe15603932f98fe279d2