-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat(php8): named arguments #673
Conversation
What I suggested in #673 didn't make sense because arguments are a list of |
e5feadf
to
ebc6676
Compare
ebc6676
to
b55446b
Compare
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.
would be less error prone to use setState from lexer and check ahead with next
https://github.com/glayzzle/php-parser/blob/master/src/lexer.js#L339
src/parser/function.js
Outdated
const name = this.text(); | ||
let res; | ||
try { | ||
res = this.read_expr(); |
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.
hi, not sure that's the right way, you can also go ahead scan next tokens to see f it matches a T_STRING + ':' and if not go for expr call
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.
fixed 🙂
Hi @ichiriac, thanks for the review! Unfortunately I don’t really have time to work on this currently. If you prefer to make the changes yourself, go ahead 😉 |
@ichiriac I tried to refactor this a you suggested, but it doesn't work when heredocs are used as function arguments (see tests): stringManipulator(<<<END
a
b
c
END); Can you point me in the right direction? 🙂 |
Alright, I found a solution / workaround: I only check ahead if the current token is T_STRING or a keyword - that way, the rollback is not needed for HEREDOC. |
@cseufert Can you take a look at these changes before we merge into the |
It appears that the current code does not follow the nikic parser, as it returns some arguments as thier immediate node, rather than returning an argument AST node (Arg in PHP-Parser). Is this something that we can break doing this update, or should we retain the backward compatibility? Also the function arguments return Entry for some of them, however this seems tied to an array entry, so I guess adding a name to this is not the best option. As I understand it, backtracking is quite expensive in the parser, this patch will backtrack quite regularly, do we want to do a work around to avoid this? The issue here is the workaround will be quite complex. |
Hi @cseufert, thanks for the review! I think we should try to keep backwards compatibility as far as possible - in this case, the deviation from the nikic PHP parser must have already existed before PHP8. |
I'll go ahead and merge this so that we can try it in the prettier plugin. @ichiriac as always, your feedback is still appreciated 🙂 |
cc @Selion05
fixes #653