Implement full-fidelity parsing and formatting for the coroutine keyword
commit6951f335ea3622148ebe0532196466086af67eeb
authorMichael Tingley <tingley@fb.com>
Thu, 20 Apr 2017 22:01:45 +0000 (20 15:01 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Thu, 20 Apr 2017 22:13:02 +0000 (20 15:13 -0700)
treee2c5a7893c04491398a502c435f7b627c0f7b608
parentb7bba8833c31ab96b77c968c3cac984c9ed40d29
Implement full-fidelity parsing and formatting for the coroutine keyword

Summary:
Supports parsing the `coroutine` keyword as a modifier for function-like constructs in places where `async` is supported today:

1. Function declarations:
```
coroutine function test(): void {}
```

2. Anonymous functions:
```
function foo(): int {
  $x = coroutine function() {
    return 5;
  };
  return $x();
}
```

3. Lambdas:
```
function f(): (function(int): int) {
  return coroutine $v ==> 1;
}
```

4. Blocks:
```
function test(): void {
  return coroutine {
    return 1;
  };
}
```

In addition to parsing, this diff also implements formatting. It does //most// of the lowering as well. However, I have not yet updated `ast.ml` to include the new `coroutine` construct as a `fun_type`. This step has been left as a `TODO` in the code.

Reviewed By: ericlippert

Differential Revision: D4884746

fbshipit-source-id: 9489e9c11b4d9bcdca44b58a6c69cf2170c96fa0
42 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_pretty_printer.ml
hphp/hack/src/parser/full_fidelity_syntax.ml
hphp/hack/src/parser/full_fidelity_token_kind.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/test/full_fidelity/cases/test_array_expression.exp
hphp/hack/test/full_fidelity/cases/test_array_key_value_precedence.exp
hphp/hack/test/full_fidelity/cases/test_attribute_spec.exp
hphp/hack/test/full_fidelity/cases/test_awaitable_creation.exp
hphp/hack/test/full_fidelity/cases/test_class_method_declaration.exp
hphp/hack/test/full_fidelity/cases/test_closure_type.exp
hphp/hack/test/full_fidelity/cases/test_constructor_destructor.exp
hphp/hack/test/full_fidelity/cases/test_for_statements.exp
hphp/hack/test/full_fidelity/cases/test_foreach_statements.exp
hphp/hack/test/full_fidelity/cases/test_function_call.exp
hphp/hack/test/full_fidelity/cases/test_list_precedence.exp
hphp/hack/test/full_fidelity/cases/test_literals.exp
hphp/hack/test/full_fidelity/cases/test_namespace.exp
hphp/hack/test/full_fidelity/cases/test_simple.exp
hphp/hack/test/full_fidelity/cases/test_statements.exp
hphp/hack/test/full_fidelity/cases/test_try_statement.exp
hphp/hack/test/full_fidelity/cases/test_types_type_const.exp
hphp/hack/test/hackfmt/tests/async_coroutine_function1.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/async_coroutine_function1.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_anon_function1.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_anon_function1.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_block1.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_block1.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_function1.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_function1.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda1.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda1.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda2.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda2.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda3.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/coroutine_lambda3.php.exp [new file with mode: 0644]