Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Attributes #405

Merged
merged 5 commits into from
Dec 7, 2020
Merged

Attributes #405

merged 5 commits into from
Dec 7, 2020

Conversation

KapitanOczywisty
Copy link
Contributor

@KapitanOczywisty KapitanOczywisty commented Nov 27, 2020

This is implementation of Attributes added in PHP 8.0. However documentation for this feature is rather bad, so I'd advice you to use sth like https://3v4l.org/ to determinate how this feature really works.

Implemented:

  • argument-less attribute #[MyAttribute]
  • attribute with arguments #[MyAttribute(true)]
  • attribute with named arguments #[MyAttribute(name:'Bob')]
  • namespaced attributes #[\Ye\Old\Attribute]
  • multiple attributes #[A,B,C]
  • multilined attributes
#[
A,
B(true)
]
  • anonymous class attributes (single-line only) new #[MyAttribute] class {}, also it's valid to write new#[MyAttribute]class{}
  • Attribute as class name, for use as argument #[Attribute(Attribute::TARGET_CLASS)]
  • test spec

Scopes

  • meta.attribute.php for whole #[....]
  • support.attribute.php for attribute name, w/ namespace scopes like in classes
  • support.attribute.builtin.php for Attribute and future builtins
  • arguments are the same as in function call

Not implemented

  • multilined attributes for anonymous classes - I'm not sure if I should implement this, since it would need some trickery to add with TM grammar (feedback is welcome)

@KapitanOczywisty KapitanOczywisty mentioned this pull request Nov 27, 2020
12 tasks
@@ -206,7 +206,7 @@
{
'begin': '''(?ix)
(?:
(?:^|(?<=}))\\s*(?:(abstract|final)\\s+)?(class)\\s+([a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)
\\b(?:(abstract|final)\\s+)?(class)\\s+([a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed complicated look-behind. As far I'm concerned, there is no case where this could backfire, but I could be wrong.

@KapitanOczywisty
Copy link
Contributor Author

@sadick254 ready for review 😃

Copy link
Contributor

@sadick254 sadick254 left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@sadick254 sadick254 merged commit 2a12e89 into atom:master Dec 7, 2020
@KapitanOczywisty KapitanOczywisty deleted the attributes branch December 14, 2022 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants