Skip to content

Parse catch multiple exceptions #107

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

Closed

Conversation

runz0rd
Copy link
Contributor

@runz0rd runz0rd commented Feb 15, 2017

For #103

Theres still the issue of detecting class names that do not implement Throwable. Any idea where can this fit in?

Copy link
Contributor

@mousetraps mousetraps left a comment

Choose a reason for hiding this comment

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

@runz0rd You're on a roll! 🚀

Left a few comments, and +1 after that!


catch (BadMethodCallException | InvalidArgumentException $e) {
echo "L0: In catch-block multiple Exception\n";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Were these changes intentional? (this file is autogenerated from the PHP spec tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the grammar tests from this file were failing. This was intentionally added to test if a valid case would pass. Want this one removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, let's revert this file but just make sure that there are handwritten test cases added for this scenario (which it looks like you already added). The spec tests are generated using this script and will be overwritten whenever we take updates from php-langspec. Original source here.

return $this->parseDelimitedList(
DelimitedList\QualifiedNameList::class,
TokenKind::CommaToken,
$delimiter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see what you meant in the delimited list PR - yeah, I don't think this is a super common case to handle, so I think it makes sense to special case this usage (or come up with some other idea that doesn't add additional memory usage.)

@@ -79,6 +79,17 @@ public static function getDiagnostics($node) : \Generator {
}
}
}
elseif ($node instanceof Node\CatchClause) {
$lastElement = \end($node->qualifiedNameList->children);
if($lastElement instanceof Token && $lastElement->kind == TokenKind::BarToken) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space between if and paren here and everywhere else. sorry, we don't have automatic code style checking yet #83

Copy link
Contributor

Choose a reason for hiding this comment

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

Also === instead of ==

src/Parser.php Outdated
$catchClause->qualifiedNameList = $this->parseQualifiedNameList($catchClause, TokenKind::BarToken);
if(\is_null($catchClause->qualifiedNameList)) {
$catchClause->qualifiedNameList = new MissingToken(TokenKind::QualifiedName, $this->getCurrentToken()->fullStart);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -1863,14 +1863,18 @@ private function parseCatchClause($parentNode) {
$catchClause->parent = $parentNode;
$catchClause->catch = $this->eat(TokenKind::CatchKeyword);
$catchClause->openParen = $this->eat(TokenKind::OpenParenToken);
$catchClause->qualifiedName = $this->parseQualifiedName($catchClause); // TODO generate missing token or error if null
$catchClause->qualifiedNameList = $this->parseQualifiedNameList($catchClause, TokenKind::BarToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also add a new test case to handle this scenario.

@mousetraps
Copy link
Contributor

Theres still the issue of detecting class names that do not implement Throwable. Any idea where can this fit in?

Cool idea, and probably best left as an exercise to the consumer 😉. For that, we'd need to resolve imports, build a symbol table, etc., which are more "language service-y" things to do. cc @felixfbecker

src/Parser.php Outdated
@@ -1863,14 +1863,18 @@ private function parseCatchClause($parentNode) {
$catchClause->parent = $parentNode;
$catchClause->catch = $this->eat(TokenKind::CatchKeyword);
$catchClause->openParen = $this->eat(TokenKind::OpenParenToken);
$catchClause->qualifiedName = $this->parseQualifiedName($catchClause); // TODO generate missing token or error if null
$catchClause->qualifiedNameList = $this->parseQualifiedNameList($catchClause, TokenKind::BarToken);
if(\is_null($catchClause->qualifiedNameList)) {

Choose a reason for hiding this comment

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

using === null is a lot faster and does the same

@felixfbecker
Copy link

I agree that checking the class extends Throwable is the domain of a language service :)

@roblourens
Copy link
Member

roblourens commented Aug 7, 2017

Hey @runz0rd, this looks ok to me - sorry it fell through the cracks. If you're still up for it, I would accept it if you can get it merged with the latest stuff in master.

Also, where did the --TEST-- and --EXPECT-- come from in the test? I don't see that in other php-langspec tests. CI is failing, not sure whether that's the reason.

@mousetraps
Copy link
Contributor

Also, where did the --TEST-- and --EXPECT-- come from in the test? I don't see that in other php-langspec tests. CI is failing, not sure whether that's the reason.

@roblourens those look like the raw php language spec test format. The files in tests/cases/php-langspec are autogenerated using the tests/generate_spec_tests.php script, and shouldn't be changed manually.

If upstream changes happen in php/php-langspec, they can be pulled in using git subtree. Then run generate_spec_tests.php to regenerate test cases for the parser.

@roblourens
Copy link
Member

Got it, thanks!

@roblourens
Copy link
Member

This will be handled in #244, and now would be a breaking change.

@roblourens roblourens closed this May 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants