-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
fix: separate binary expression from pattern #606
fix: separate binary expression from pattern #606
Conversation
ec0e028
to
f9c8f41
Compare
1625496
to
df2dd83
Compare
df2dd83
to
3806135
Compare
@@ -3498,8 +3498,6 @@ export interface PatternCstNode extends CstNode { | |||
|
|||
export type PatternCtx = { | |||
primaryPattern: PrimaryPatternCstNode[]; | |||
AndAnd?: IToken[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of modifying the CST in order to make it easier to print the code afterwards, as it makes the java parser maintenance much more difficult for each deviation from the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clementdessoude I looked into the spec while implementing this solution, because I had similar concerns. What I found was that a Pattern is a TypePattern, which is a LocalVariableDeclaration, meaning that according to the spec, a Pattern should not contain AndAnd or a binaryExpression within it. I made this change because it seemed to make the parser more aligned with the spec.
All that being said, this solution is occasionally failing tests because it seems to have slowed down parsing, so I'll need to find a fix for that. But I do think this change to the CST is appropriate, unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the &&
style of the switch label "guarded" pattern is no more, and has been replaced with when
in Java 21 (the first version that supports switch label pattern matching outside of a preview feature), which is scheduled to release tomorrow. So I will likely need to rethink this solution regardless. https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-SwitchLabel
What changed with this PR:
Rather than treating the optional binary expression following a pattern as part of the pattern itself, treat the entire expression as a binary expression, of which the pattern is a part, so that the usual binary expression formatting applies.
Example
Input
Output
Relative issues or prs:
Closes #605