Fixed incorrectly marking "class" in "A::class" as a keyword. #1

Merged
neochief merged 1 commit from php-class-fix into main 2021-09-24 08:34:02 +02:00
neochief commented 2021-09-23 16:47:44 +02:00 (Migrated from github.com)

Hi!

There's a special class constant "::class" in PHP (https://www.php.net/manual/en/language.oop5.constants.php). If you have an expression like "$a = SomeClass::class;", the "class" is currently wrongly rendered as a keyword. This pull request fixes the behavior so that the "::class" constant would be rendered as a generic Name token.

I spent the last 5 hours figuring out the best way to tackle this problem and this solution is the best thing I can think of, given my very limited knowledge of the lezer philosophy. If you think that there's a better way to fix this, please just give me a nudge in that direction and I'll update the code.

Hi! There's a special class constant "::class" in PHP (https://www.php.net/manual/en/language.oop5.constants.php). If you have an expression like "$a = SomeClass::class;", the "class" is currently wrongly rendered as a keyword. This pull request fixes the behavior so that the "::class" constant would be rendered as a generic Name token. I spent the last 5 hours figuring out the best way to tackle this problem and this solution is the best thing I can think of, given my very limited knowledge of the lezer philosophy. If you think that there's a better way to fix this, please just give me a nudge in that direction and I'll update the code.
marijnh commented 2021-09-23 17:08:56 +02:00 (Migrated from github.com)

Hi, thanks for the pull request. This is mostly the correct approach. But for consistency, and in order to support upper-case CLASS tokens, could you align the definition of the class token with the one for static, which has a similar issue in PHP? I.e.

class { @extend[@name=class]<Name, "class" | "CLASS"> }

and then use class wherever you now have ckw<"class">.

Hi, thanks for the pull request. This is mostly the correct approach. But for consistency, and in order to support upper-case `CLASS` tokens, could you align the definition of the class token with the one for `static`, which has a similar issue in PHP? I.e. ``` class { @extend[@name=class]<Name, "class" | "CLASS"> } ``` and then use `class` wherever you now have `ckw<"class">`.
neochief commented 2021-09-23 18:38:06 +02:00 (Migrated from github.com)

Thanks! I didn't notice the "static"-related code before, I wish I saw it earlier. Anyway, I have updated the code.

Thanks! I didn't notice the "static"-related code before, I wish I saw it earlier. Anyway, I have updated the code.
marijnh commented 2021-09-24 08:34:08 +02:00 (Migrated from github.com)

Thanks!

Thanks!
neochief commented 2021-09-24 11:59:11 +02:00 (Migrated from github.com)

I'm glad I was able to help. Thanks for your hard work!

I'm glad I was able to help. Thanks for your hard work!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/php!1
No description provided.