Skip to content

Parse namespaces as single tokens#921

Merged
czosel merged 11 commits into
glayzzle:mainfrom
MaartenStaa:parse-namespace-single-token
May 22, 2022
Merged

Parse namespaces as single tokens#921
czosel merged 11 commits into
glayzzle:mainfrom
MaartenStaa:parse-namespace-single-token

Conversation

@MaartenStaa

Copy link
Copy Markdown
Collaborator

As in PHP itself, introduce the tokens T_NAME_RELATIVE, T_NAME_QUALIFIED, and T_NAME_FULLY_QUALIFIED.

Fixes #834.
Fixes #896.

Maarten Staa added 10 commits May 2, 2022 13:43
…NAME_FULLY_QUALIFIED.

This considers an entire namespace path (e.g. `\Foo\Bar` or `namespace\Baz` as a single token.
This path handled top statements such as:

```php
namespace\foo();
```

This would end up in `read_namespace` due to the `T_NAMESPACE` token. However,
with the changes in the previous two commits this is now parsed as a single
`T_NAME_RELATIVE` token, and is parsed as a regular call expression statement
instead.
…able.

I ran into issues when enabling debug mode, that unclosed nodes from one
test (sometimes on purpose), caused unclosed nodes errors on other tests.
By tracking the AST stack on `this` rather than on the `AST` class directly,
this can no longer happen, and each test runs in isolation.
@czosel

czosel commented May 17, 2022

Copy link
Copy Markdown
Collaborator

Hi @MaartenStaa - thanks for this awesome contribution and sorry about the delay with the review. I hope I'll get to it on the weekend!

@czosel czosel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 💯

Comment thread src/ast.js Outdated
@czosel czosel merged commit 12c0a62 into glayzzle:main May 22, 2022
@czosel

czosel commented May 22, 2022

Copy link
Copy Markdown
Collaborator

Released in 3.1.0-beta.6 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum is treated as a reserved word, even before PHP 8.1 Importing a class with \Trait\ in the namespace throws unexpected 'Trait' (T_TRAIT)

2 participants