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

Format switch statements and expressions. #1294

Merged
merged 5 commits into from
Oct 25, 2023
Merged

Format switch statements and expressions. #1294

merged 5 commits into from
Oct 25, 2023

Conversation

munificent
Copy link
Member

Switch statements build on the existing SequencePiece but need some additional flexibility in there to handle the fact that switch case lines are indented +2 and then case body lines are indented +4.

Switch expressions build on the existing ListPiece since the body is sort of like a collection literal. There are a few tweaks needed here too since an unsplit switch expression body gets spaces inside the curly brackets.

Also, switch values (the part in the leading "( ... )") are formatted using ListPiece as well, since they are formatted essentially like a single-element argument list, except that they don't get a trailing comma.

This does not implement all of the kinds of patterns that can appear in cases. It just implements basic constants needed for the tests. It also doesn't support guard clauses yet. Those will come later.

Switch statements build on the existing SequencePiece but need some
additional flexibility in there to handle the fact that switch case
lines are indented +2 and then case body lines are indented +4.

Switch expressions build on the existing ListPiece since the body is
sort of like a collection literal. There are a few tweaks needed here
too since an unsplit switch expression body gets spaces inside the
curly brackets.

Also, switch values (the part in the leading "( ... )") are formatted
using ListPiece as well, since they are formatted essentially like a
single-element argument list, except that they don't get a trailing
comma.

This does not implement all of the kinds of patterns that can appear in
cases. It just implements basic constants needed for the tests. It also
doesn't support guard clauses yet. Those will come later.
Base automatically changed from format-assignment to main October 24, 2023 22:27
lib/src/front_end/ast_node_visitor.dart Outdated Show resolved Hide resolved
lib/src/front_end/delimited_list_builder.dart Outdated Show resolved Hide resolved
lib/src/piece/list.dart Outdated Show resolved Hide resolved
Co-authored-by: Nate Bosch <nbosch@google.com>
@munificent munificent merged commit 2cee560 into main Oct 25, 2023
7 checks passed
@munificent munificent deleted the format-switch branch October 25, 2023 19:15
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.

3 participants