Remove direct usage of Syntax module from parsers
commit084f7c9ea33502f214d50c1531fee0404aa797a5
authorRuslan Sakevych <ruslans@fb.com>
Mon, 12 Feb 2018 16:00:53 +0000 (12 08:00 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Mon, 12 Feb 2018 16:19:48 +0000 (12 08:19 -0800)
tree9d7561f81db07b8b8c2f4f17ef3c38cc5fdaeccf
parenta9e8cfff796f86f254a89a422948a1d9b3daf1cb
Remove direct usage of Syntax module from parsers

Summary:
Because we are going to use smart constructors instead of `Syntax.make_` functions we can't inspect created nodes anymore. Parsers will be parametrized by smart constructors and couldn't assume `SC.r` (return value from `Make` functions) to be `Syntax.t`. That's why we have to remove all the calls to `Syntax` from parsers.

Changes

1. Removed call to `Syntax.is_namespace_prefix_name`. You pass a `QualifiedName` and it will extract `ItemList` and check if the last separator is not missing.
Now we just propagate this information from the place where we actually create items.
*Note*. if you look at the `scan_qualified_name` and `scan_extended_qualified_name` you'll see that the only separator they accept is backslash, so I called propagated parameter `is_backslash`.

2. Now `require_name_allow_std_constants` is extracting offsets from the lexer to get text of the token. To check off-by-one errors I modified `hphp/hack/test/full_fidelity/cases/test_group_use_errors.php` include that code-path and ran `ocamldebug`.

3. Rewrote `parse_string_literal` to postpone token creation. Now it's calling `make_token` only when it's sure that token is never gonna change. Previously it was using `Syntax.get_token` and `make_token` to add new tokens to the string literal.

Differential Revision: D6894426

fbshipit-source-id: d8eb326106281f6acc69bb6670fa2fb86b19a8e1
hphp/hack/src/parser/full_fidelity_declaration_parser.ml
hphp/hack/src/parser/full_fidelity_expression_parser.ml
hphp/hack/src/parser/full_fidelity_parser_helpers.ml
hphp/hack/test/full_fidelity/cases/test_group_use_errors.php