-
Notifications
You must be signed in to change notification settings - Fork 0
Fix namespace handling of keywords #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| DelimitedList\QualifiedNameParts::class, | ||
| TokenKind::BackslashToken, | ||
| function ($token) { | ||
| // a\static() <- INVALID (but not checked for right now) | ||
| // new a\static() <- INVALID | ||
| // new static() <- VALID | ||
| // a\static\b <- INVALID | ||
| // a\function <- INVALID | ||
| // a\true\b <-VALID | ||
| // a\b\true <-VALID | ||
| // a\static::b <-VALID | ||
| // TODO more tests | ||
| return $this->lookahead(TokenKind::BackslashToken) | ||
| ? in_array($token->kind, $this->nameOrReservedWordTokens) | ||
| : in_array($token->kind, $this->nameOrStaticOrReservedWordTokens); | ||
| if ($token->kind === TokenKind::NamespaceKeyword) { | ||
| return false; | ||
| } | ||
| return \in_array($token->kind, $this->nameOrKeywordOrReservedWordTokensExceptNamespace, true); | ||
| }, | ||
| function ($parentNode) { | ||
| $name = $this->lookahead(TokenKind::BackslashToken) | ||
| ? $this->eat($this->nameOrReservedWordTokens) | ||
| : $this->eat($this->nameOrStaticOrReservedWordTokens); // TODO support keyword name | ||
| $name = $this->eat($this->nameOrKeywordOrReservedWordTokensExceptNamespace); // TODO support keyword name | ||
| $name->kind = TokenKind::Name; // bool/true/null/static should not be treated as keywords in this case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reinstate lookahead filtering for qualified-name keywords
The new parseQualifiedNameFn now accepts any keyword except namespace for every segment of a qualified name (in_array($this->nameOrKeywordOrReservedWordTokensExceptNamespace, true)). The previous implementation rejected keywords such as static or function when they were followed by another namespace separator, so constructs like new a\static() or a\function\b produced diagnostics. After this change those invalid identifiers parse as ordinary names, so the parser will silently accept syntactically invalid class or function references in non-namespace contexts. Consider keeping the lookahead logic and only broadening the allowed set where keywords are actually permitted (e.g. namespace declarations) to avoid suppressing errors elsewhere.
Useful? React with 👍 / 👎.
keywords like
global,new,classare valid namespace identifiers. Everything exceptnamespaceworks.