Introduce the EditablePositioned full-fidelity syntax tree
commit4156378e9950424946c4188a0f174fd58a2f143b
authorMichael Tingley <tingley@fb.com>
Wed, 30 Aug 2017 23:47:48 +0000 (30 16:47 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Thu, 31 Aug 2017 00:00:33 +0000 (30 17:00 -0700)
treeea4b6703b3c54fb0af8020583b308ee2834d816e
parentd4e2f6839cc03221aba3c33f132712ce40ac3f38
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
17 files changed:
hphp/hack/src/hh_single_parse.ml
hphp/hack/src/parser/coroutine/coroutine_closure_generator.ml
hphp/hack/src/parser/coroutine/coroutine_context.ml
hphp/hack/src/parser/coroutine/coroutine_lowerer.ml
hphp/hack/src/parser/coroutine/coroutine_lowerer.mli
hphp/hack/src/parser/coroutine/coroutine_method_lowerer.ml
hphp/hack/src/parser/coroutine/coroutine_state_machine_data.ml
hphp/hack/src/parser/coroutine/coroutine_state_machine_generator.ml
hphp/hack/src/parser/coroutine/coroutine_suspend_rewriter.ml
hphp/hack/src/parser/coroutine/coroutine_suspend_rewriter.mli
hphp/hack/src/parser/coroutine/coroutine_syntax.ml
hphp/hack/src/parser/coroutine/coroutine_type_lowerer.ml
hphp/hack/src/parser/full_fidelity_ast.ml
hphp/hack/src/parser/full_fidelity_editable_positioned_original_source_data.ml [new file with mode: 0644]
hphp/hack/src/parser/full_fidelity_editable_positioned_syntax.ml [new file with mode: 0644]
hphp/hack/src/parser/full_fidelity_editable_positioned_token.ml [new file with mode: 0644]
hphp/hack/src/parser/lambda_analyzer.ml