Introduce AST nodes for PatternMatchClass arguments#6881
Conversation
| CommentPlacement::Default(comment) | ||
| } | ||
|
|
||
| CommentPlacement::Default(comment) |
There was a problem hiding this comment.
This gets dramatically simplified.
There was a problem hiding this comment.
Anything that deletes code is a "dramatic simplification" for me
28e9b61 to
d6f2d14
Compare
| use crate::FormatNodeRule; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct FormatPatternArguments; |
There was a problem hiding this comment.
This is very, very similar to arguments.rs, but it's difficult to share much code.
| } | ||
| } | ||
| OptionalParentheses::Never | ||
| } |
There was a problem hiding this comment.
This specific logic is way simpler now -- we only care if there are dangling comments, not where they are, since these are dangling comments between Point2D and its arguments.
|
Adding these AST nodes does require a bunch of boilerplate, but I think it's worth it for the improved representation. |
d6f2d14 to
0ccb998
Compare
0ccb998 to
9d3ad6a
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
9d3ad6a to
6b3ecfb
Compare
MichaReiser
left a comment
There was a problem hiding this comment.
Can you verify that the following continues to parse successfully (maybe add a test?)
match a:
case Point2D((0), 0, x=(1), y=2):
...| CommentPlacement::Default(comment) | ||
| } | ||
|
|
||
| CommentPlacement::Default(comment) |
6b3ecfb to
3b31526
Compare
CodSpeed Performance ReportMerging #6881 will create unknown performance changesComparing Summary
Benchmarks breakdown
|
Summary
This PR introduces two new AST nodes to improve the representation of
PatternMatchClass. As a reminder,PatternMatchClasslooks like this:Historically, this was represented as a vector of patterns (for the
0, 0portion) and parallel vectors of keyword names (forxandy) and values (for1and2). This introduces a bunch of challenges for the formatter, but importantly, it's also really different from how we represent similar nodes, like arguments (func(0, 0, x=1, y=2)) or parameters (def func(x, y)).So, firstly, we now use a single node (
PatternArguments) for the entire parenthesized region, making it much more consistent with our other nodes. So, above,PatternArgumentswould be(0, 0, x=1, y=2).Secondly, we now have a
PatternKeywordnode forx=1andy=2. This is much more similar to the howKeywordis represented withinArgumentsfor call expressions.Closes #6866.
Closes #6880.