Skip to content

Support parsing multiple exception types in catch clauses #103

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
mousetraps opened this issue Feb 13, 2017 · 6 comments
Closed

Support parsing multiple exception types in catch clauses #103

mousetraps opened this issue Feb 13, 2017 · 6 comments

Comments

@mousetraps
Copy link
Contributor

PHP 7.1 introduced support for catching multiple exception types:
https://wiki.php.net/rfc/multiple-catch

image

We should handle this condition on the parser by parsing as a delimited list of qualified names, where the delimiter is the TokenKind::BarToken, and we should be able to reuse the logic from parseQualifiedNameList

@nesl247
Copy link

nesl247 commented Nov 15, 2017

Any update on this?

@BPScott
Copy link

BPScott commented Feb 13, 2018

I've filed an issue with php-langspec as this is not currently documented and tested upstream: php/php-langspec#216

@TysonAndre
Copy link
Contributor

My thoughts on solving this:

Add a new property to the tolerant-php-parser object representing the catch{} Node (i.e. CatchClause, parsed by parseCatchClause).

CatchClause->remainingQualifiedNameList would either be null or begin with | and end with T1 [ | T2...]. It would be parsed if the next token was |. It would be immediately after qualifiedName.

  • In a future backwards incompatible release (1.0 if following semver?), rename CatchClause->qualifiedName to qualifiedNameList and remove remainingQualifiedNameList

@Zerquix18
Copy link

More than a year a still no fix 😢

@jens1o
Copy link
Contributor

jens1o commented May 4, 2018

@Zerquix18 Feel free to file a pr :)

@felixfbecker
Copy link

@Zerquix18 Seriously, whining won't make it be fixed any faster. A PR will. This project is driven by community contributions.

TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue May 12, 2018
Add a new array `otherQualifiedNameList` alongside qualifiedName
to `CatchClause`. (Contains remaining `Token`s and `QualifiedName`s)
(This design breaks backwards compatibility as little as possible)

- A future backwards incompatible release should merge the two
  properties into `qualifiedNameList`,
  or something along those lines.

Add a new helper method to parse the catch list.

- The new helper is required because
  `tests/cases/php-langspec/exception_handling/odds_and_ends.php`
  should not fail because `catch (int $e)` is **syntactically** valid php
  (in 7.x), i.e. `php --syntax-check` doesn't reject it.
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this issue May 12, 2018
Add a new array `otherQualifiedNameList` alongside qualifiedName
to `CatchClause`. (Contains remaining `Token`s and `QualifiedName`s)
(This design breaks backwards compatibility as little as possible)

- A future backwards incompatible release should merge the two
  properties into `qualifiedNameList`,
  or something along those lines.

Add a new helper method to parse the catch list.

- The new helper is required because
  `tests/cases/php-langspec/exception_handling/odds_and_ends.php`
  should not fail because `catch (int $e)` is **syntactically** valid php
  (in 7.x), i.e. `php --syntax-check` doesn't reject it.
roblourens added a commit that referenced this issue May 26, 2018
Fixes #103: Support parsing multiple exception types
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

7 participants