-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add callable template support #199
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.
Hi, I took a look since this somehow ended up in my notifications and piqued my curiosity. But I'm really just passing by and only wanted to point out a few topics for discussion, so don't take my comments too seriously :)
Nice work overall!
@ondrejmirtes this parser PR should be fully done, phpstan/phpstan#8964 (comment) might be easy for you, but I am not familiar with phpstan internals so I would appreciate a help with the integration into phpstan. Thank you. |
@ondrejmirtes this PR is here for over a month, may I ask you to review it? |
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.
These are the two main issues I see in this PR.
Also I find the changes of the parser hard to understand, I have to inspect them in depth to understand the implications. Maybe if you could do the changes to the TypeParser in multiple smaller steps, I'd welcome them as separate PRs that I would merge before this one.
The credo to live by is: "Make the change easy, then make the easy change."
@ondrejmirtes sorry to tagging you again, can I please ask you to merge this PR if there is no feedback left? |
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); | ||
|
||
// trailing comma case | ||
if (!$isFirst && $tokens->isCurrentTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET)) { |
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.
I don't understand why is there so much repeated code. We're already parsing template types in similar position for @method
, there has to be a way to reuse that code: #160
Everything you should need is already in parseTemplateTagValue.
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.
Can you please guide me how and what to reuse? The code in #160 (Parser/PhpDocParser in general) is for phpdoc instead of for type (Parser/TypeParser).
If the newly introduced Ast/Type/CallableTypeTemplateNode class is wanted (and it probably is - callable template should not consist of anything like description), then the code cannot be simplified much. As the grammar is not completely the same, basically the only parsing part to deduplicate would be <
, ,
, of
.
If you want, feel free to push any changes to my branch.
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.
I think #160 implements the very same use case as this PR: it parses inline template tag definitions, disallowing descriptions, but accounting for everything else (bound types, defaults, ...). Perhaps it could suffice to extract the parseTemplateTagValue
method into a TemplateTagParser
that could be used in TypeParser
as well?
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.
Yes, that logic should be extracted so that it's usable by both TypeParser and PhpDocParser.
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.
@mvorisek are you going to look into this feedback or should i have a go at it?
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.
@mad-briller Please have a go at it :)
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.
@mad-briller would you like to join the forces? Feel free to either reuse this PR as a separate one or submit a PR againts https://github.com/mvorisek/phpdoc-parser/tree/parse_generic_callable - this PR should be basically done, but the code should be deduplicated per #199 (comment) request.
Landed thru #232, thanks everyone involved! |
needed for phpstan/phpstan#8964
based on phpstan/phpstan#8964 (comment) analysis