Skip to content
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

4.0 | Change T_GOTO_LABEL to not include colon #185

Open
jrfnl opened this issue Dec 25, 2023 · 2 comments
Open

4.0 | Change T_GOTO_LABEL to not include colon #185

jrfnl opened this issue Dec 25, 2023 · 2 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Dec 25, 2023

Repost from squizlabs/PHP_CodeSniffer#3161 by @gsherwood:

The colon after a goto label does not have to be the very next token; there can be whitespace and comments between them. PHP_CodeSniffer will not tokenize the label correctly unless the colon immediately follows the label.

To fix this, T_GOTO_LABEL should be changed to include the label only, and exclude the colon.

So a: becomes:

T_GOTO_LABEL => a
T_COLON => :

Instead of:

T_GOTO_LABEL => a:

And a /*comment here*/ : becomes:

T_GOTO_LABEL => a
T_WHITESPACE => ·
T_COMMENT => /*comment·here*/
T_WHITESPACE => ·
T_COLON => :

Instead of:

T_STRING => a
T_WHITESPACE => ·
T_COMMENT => /*comment·here*/
T_WHITESPACE => ·
T_COLON => :
@jrfnl
Copy link
Member Author

jrfnl commented May 19, 2024

When addressing this change, I believe there is a related bug, which should also be looked into and fixed: the use of context sensitive keywords as goto labels.

As things are, the context sensitive keywords layer in the tokenizer does not retokenize context sensitive keywords to T_STRING when these are used as a goto label.

While this will always be a parse error, I still believe the keywords should be retokenized to T_STRING for consistency. In the same way as context sensitive keywords used as the name of a class or (global) function are retokenized to T_STRING, even though those usages would also result in a parse error.

@jrfnl
Copy link
Member Author

jrfnl commented May 21, 2024

Reminder for the tests:

  • Test with named parameters and make sure the labels are not tokenized as goto labels: callMe(label: $a, other: $b)

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

No branches or pull requests

1 participant