-
Notifications
You must be signed in to change notification settings - Fork 441
Helper methods to modify leading and trailing trivia on nodes #91
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
Conversation
} | ||
set { | ||
if let trailingTrivia = newValue { | ||
self = withTrailingTrivia(trailingTrivia) |
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.
What if I set this to nil
?
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.
This is a tricky one. As the getter returns nil
when there is no token in the hierarchy, it doesn't make sense to set nil: it's not like it should remove all tokens form the hierarchy. The only options I thought of are:
- Have the setter do nothing when setting nil (that's the option I chose). Unfortunately, this can be very surprising:
print(node.leadingTrivia) // [.spaces(1)]
node.leadingTrivia = nil
print(node.leadingTrivia) // [.spaces(1)]
- Have the setter trap when setting nil. That's another good option AFAIK.
- Don't implement a setter and only rely on
with...Trivia
functions. I'm not a fan of this option as we have convenience setter for all other properties.
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.
What about making node.leadingTrivia = nil
have the same semantics as setting node.leadingTrivia = []
? Without looking too much into detail, it's a behaviour I would expect / would be able to explain when it occurs.
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.
That's indeed another option, but it still has the same surprising behaviour as noop that the getter won't be returning the same value you just set.
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.
Yeah, still both values represent some kind of “nothingness”.
It also reminded me of some Cocoa pattern where setting a property to nil
caused it to take on a particular value (I think like black for text colour). It's not really relevant here but it shows that having the setter set a different value than is afterwards returned by the getter is not completely unprecedented in the Apple ecosystem.
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.
Sounds fair, I'll make the change.
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.
FWIW that pattern is codified into the language as null_resettable
. I think it's perfectly valid here.
dc805f7
to
c0266e1
Compare
@ahoppen @nkcsgexi @harlanhaskins Any news? |
@swift-ci please test |
Sorry for the delay here, @hartbit! |
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.
Looking good!
Thanks!! |
Fix scrunching of range operators.
This is implemented recursively on
RawSyntax
and throughSyntaxData
and appropriate public methods were made available on all syntax nodes and collections.