Skip to content
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

Clarify naming around paren expressions #3444

Merged
merged 5 commits into from
Dec 8, 2023

Conversation

geoffromer
Copy link
Contributor

(Split out of #3410)

Consistently use ParenExpr solely for parenthesized single expressions, and use more syntax-oriented terminology for states and nodes that might represent either a ParenExpr or a tuple literal.

(Split out of carbon-language#3410)

Consistently use `ParenExpr` solely for parenthesized single expressions, and use more syntax-oriented terminology for states and nodes that might represent either a `ParenExpr` or a tuple literal.
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Thanks for splitting this out!

Comment on lines +750 to +751
// ( ... )
// ^
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this occur on TupleLiteralElementFinish? Should it be removed or replaced with something like ( ... , ... ) pointing to the close )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You may be right that at the moment the "..." always contains a comma, but that's not an invariant that HandleTupleLiteralElementFinish either enforces or relies on; it's just a contingent fact about how this state is currently used. In particular, if we chose to reimplement CallExpr in terms of TupleLiteral, that would no longer be true, and as far as I know, nothing about TupleLiteralElementFinish itself would need to change to accommodate that. As a result, I don't see much benefit to narrowing its contract in that way.

toolchain/parse/state.def Outdated Show resolved Hide resolved
toolchain/parse/state.def Show resolved Hide resolved
Comment on lines 47 to 48
// On a comma, push another expression handler.
if (list_token_kind == Context::ListTokenKind::Comma) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I found this confusing, given that we always have a comma in this case.

Suggested change
// On a comma, push another expression handler.
if (list_token_kind == Context::ListTokenKind::Comma) {
// If the close paren is not next, push another expression handler.
if (list_token_kind != Context::ListTokenKind::CommaClose) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but with some other comment changes in light of your other comment.

toolchain/parse/handle_paren_expr.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

A couple of tiny comments, but then LGTM.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Looks good, not merging due to conflicts.

@geoffromer geoffromer added this pull request to the merge queue Dec 8, 2023
Merged via the queue into carbon-language:trunk with commit 5897e57 Dec 8, 2023
6 checks passed
@geoffromer geoffromer deleted the paren-expr-naming branch December 8, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants