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

Allow observing an indent after conditional #22611

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

som-snytt
Copy link
Contributor

Normally do not infer NEWLINE within parens,
but special case old syntax for conditionals,
so that it can observe indented syntax.
The mechanism is to inject an Indented region
when parsing a parenthesized condition which is
within an InParens region, such as an arg list.
The effect is not to advance past EOL after (true).

Fixes #22608

@som-snytt som-snytt force-pushed the issue/22608-nl-in-parens branch 2 times, most recently from e65b79e to 1564f74 Compare February 16, 2025 00:20
@som-snytt
Copy link
Contributor Author

Note to self: #19099 is infix indent. (PR from end of queue.)

@som-snytt
Copy link
Contributor Author

It would be nice to avoid case r => r; not only do I have to name something, but it introduces an extraneous local variable. It means return x$1, or case _ => _ or case _ => return _

@som-snytt som-snytt marked this pull request as ready for review February 16, 2025 18:07
@Gedochao Gedochao requested a review from odersky February 18, 2025 12:02
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@@ -105,6 +105,9 @@ object Parsers {
private val InCase: Region => Region = Scanners.InCase(_)
private val InCond: Region => Region = Scanners.InParens(LPAREN, _)
private val InFor : Region => Region = Scanners.InBraces(_)
private val InBrk : Region => Region =
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what InBrk is supposed to mean. Can we find a better name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it would be good to point to the issue number to explain what this fixes.

@odersky odersky assigned som-snytt and unassigned odersky Feb 18, 2025
Normally do not infer NEWLINE within parens,
but special case old syntax for conditionals,
so that it can observe indented syntax.
The mechanism is to inject an Indented region
when parsing a parenthesized condition which is
within an InParens region, such as an arg list.
The effect is not to advance past EOL after `(true)`.
@som-snytt som-snytt force-pushed the issue/22608-nl-in-parens branch from 971dacf to a19c14a Compare February 18, 2025 17:19
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

That's clear now.

@odersky odersky merged commit 6bf8eae into scala:main Feb 19, 2025
29 checks passed
@som-snytt som-snytt deleted the issue/22608-nl-in-parens branch February 19, 2025 10:28
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.

Indentation parsing of if can fail when overlapped in brackets
2 participants