Introduce dedicated node to store markup
commit7b60fb50ccb40ffef6a5fb559f93a8ba3d822977
authorVladimir Matveev <vladima@fb.com>
Mon, 26 Jun 2017 18:58:07 +0000 (26 11:58 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Mon, 26 Jun 2017 19:08:25 +0000 (26 12:08 -0700)
treed3d7c811e3d5ba1117d38a3df28ec705e04c6438
parentd799861373acd478832e66a5a191e9d74e1fc9f9
Introduce dedicated node to store markup

Summary:
Previously we used to parse markup as a trivia which is inconvenient for a several reasons:
- markup is emitted during codegen which means that it should preserve its position relative to other source elements. Also position-based representation the tree loses information about trivia kinds so when at some point we need markup we need to repeat all the work that was already done by parser before.
- script section that starts with `<?=` short tag should contain only expressions or expression statements, declarations and other kinds of statements are not legal there (because content of this section is treated as if it is passed as an argument to `echo` function).

In the code markup can appear at positions where statements are permitted so for our purposes we can treat markup as a special kind of statement that starts with optional `?>` tag followed by arbitrary text that is not `<?` and ends with optional `<?` followed by the identifier (like `php` or `hh` possibly with different casing) or `=` for `<?=` tag, something like this:

```lang=ocaml
type script_section =
{  prefix: Token option
;  text: string
;  expression: expr option
;  suffix: script_suffix }

type script_suffix =
{  less_than_question: Token
;  name: Token }
```

`expression` in `script_section` represents expression statement that starts with `<?=` - this structure makes it very convenient to deal with such expressions on later steps. Alternative will be to treat this expression statement as a sibling of a markup section but then in order to determine if script section is permitted to have declarations or to emit the code we'll need to pull in previous statement to check if it was markup that ends with `<?=` - step which is quite invasive for a existing codebase and that is very easy to miss in a new code.

*NOTE*: since this change alters the structure of the tree it touches pretty much all ffp baselines. Adding ~700 files more to this diff (which is already large) will make it impossible to digest so at this point in case if test finishes *successfully* I'm patching its output to adapt it to a previous shape of the tree. Updating all test baselines will be sent as a separate diff.

Reviewed By: ericlippert

Differential Revision: D5277354

fbshipit-source-id: e56ebaaaef6551d6877fba6b79a79d1f41c1d156
27 files changed:
hphp/hack/src/hackfmt/hack_format.ml
hphp/hack/src/parser/full_fidelity_ast.ml
hphp/hack/src/parser/full_fidelity_declaration_parser.ml
hphp/hack/src/parser/full_fidelity_expression_parser.ml
hphp/hack/src/parser/full_fidelity_lexer.ml
hphp/hack/src/parser/full_fidelity_lexer.mli
hphp/hack/src/parser/full_fidelity_lexer_sig.ml
hphp/hack/src/parser/full_fidelity_minimal_trivia.ml
hphp/hack/src/parser/full_fidelity_parser_helpers.ml
hphp/hack/src/parser/full_fidelity_positioned_syntax.ml
hphp/hack/src/parser/full_fidelity_pretty_printer.ml
hphp/hack/src/parser/full_fidelity_statement_parser.ml
hphp/hack/src/parser/full_fidelity_statement_parser_type.ml
hphp/hack/src/parser/full_fidelity_syntax.ml
hphp/hack/src/parser/full_fidelity_syntax_kind.ml
hphp/hack/src/parser/full_fidelity_syntax_tree.ml
hphp/hack/src/parser/full_fidelity_syntax_type.ml
hphp/hack/src/parser/full_fidelity_token_kind.ml
hphp/hack/src/parser/full_fidelity_trivia_kind.ml
hphp/hack/src/parser/full_fidelity_type_lexer.ml
hphp/hack/src/parser/js/full_fidelity_editable.js
hphp/hack/src/parser/js/full_fidelity_schema.json
hphp/hack/src/parser/php/full_fidelity_editable.php
hphp/hack/src/parser/schema/full_fidelity_schema.ml
hphp/hack/src/parser/schema/schema_definition.ml
hphp/hack/test/full_fidelity/full_fidelity_test_utils.ml
hphp/hack/test/full_fidelity/full_fidelity_unit_test.ml