-
Notifications
You must be signed in to change notification settings - Fork 440
Add a function to merge trivia from a node into an existing trivia #1478
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
@swift-ci please test |
/// Creates a new `Trivia` by appending the provided `TriviaPiece` to the end. | ||
public func appending(_ piece: TriviaPiece) -> Trivia { | ||
var copy = pieces | ||
copy.append(piece) | ||
return Trivia(pieces: copy) | ||
} |
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.
Another natural candidate would be appending(_ trivia: Trivia) -> Trivia
. I might actually prefer to have a bunch of appending
methods instead of overloading +
. But that’s not really part of this PR.
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 too prefer appending
, I'm happy to do that here if you want. I generally dislike operator overloading 😅
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.
OK, so let’s get rid of the +
overload now 🗑️
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 used... in quite a few places. I'd rather get this in for now, so another PR it is 😅. I've added the other appending
and used it in the +
implementations.
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.
👍🏽 Maybe we can deprecate it in a follow-up PR 🤔
This one actually depends on #1477 so I'll wait to re-run tests until it's in. |
The actual `Trivia` definition doesn't need to be generated at all, only the static funcs and vars. Move it into SwiftSyntax proper.
4808ee2
to
c2557f9
Compare
@@ -227,7 +227,12 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { | |||
case .accessPathComponent: | |||
assert(layout.count == 5) | |||
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) | |||
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier)])) |
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.
Seems like we didn't regenerate in aea4442?
@swift-ci please test |
@swift-ci please test |
f83fe74
to
f032eee
Compare
@swift-ci please test |
@swift-ci please test |
Generally when a node is removed, we need to add its trivia to an existing node. Add a small helper function to aid in this case.
@swift-ci please test |
@swift-ci please test Windows platform |
Generally when a node is removed, we need to add its trivia to an
existing node. Add a small helper function to aid in this case.