Skip to content

[5.8] Introduce if/switch expressions #1305

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

Merged

Conversation

hamishknight
Copy link
Contributor

5.8 cherry-pick of #1228


Introduce IfExprSyntax and SwitchExpr syntax, which replace IfStmtSyntax and SwitchStmtSyntax, and can represent both if/switch expressions, as well as regular if/switch statements when wrapped in an ExpressionStmtSyntax. Implement the parsing logic such that we start parsing IfExprSyntax and SwitchExprSyntax in expression position.

This replaces IfStmtSyntax, and will be wrapped in
an ExpressionStmtSyntax when used as a statement.
Update the parser to support parsing IfExprSyntax.
For now, this only updates the existing statement
parsing, and does not attempt to parse in
expression position.
This replaces SwitchStmtSyntax, and will be
wrapped in an ExpressionStmtSyntax when used as a
statement.
Update the parser to support parsing SwitchExprSyntax.
For now, this only updates the existing statement
parsing, and does not attempt to parse in
expression position.
Start parsing if and switch expressions as unary
expressions (as we don't allow postfix grammar for
them). In addition, parse if/switch expressions
in statement position if we see a
`try`/`await`/`move`, or a trailing `as Type`.
Clean up some code, allow `if` and `switch` to
count as the start of an expression, and add some
substructure test assertions.
@hamishknight
Copy link
Contributor Author

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.

1 participant