-
Notifications
You must be signed in to change notification settings - Fork 49
Implement Regex.mapOutput #455
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
fix no capture
@swift-ci please test |
let string1 = "Hello" | ||
|
||
let regex4 = regex3.mapOutput { | ||
"\($0) world!"[...] |
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.
Curious here — does this cause a problem if you leave off the [...]
?
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.
Previously if the output type was just Substring
it would've returned only the whole match instead of actually transforming the output, so I'm testing that even with just a Substring
output type we still attempt to transform.
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.
Can we also add a test of the behavior when dropping an output-mapped regex in a builder block?
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 short-term band aid (which might be necessary). What we need for mapOutput
is a DSLTree node that will transform / map the actual outputs. E.g. contains(captureNamed:)
would honor any tuple labels that were added or removed.
We can merge something like this (but with more tests) as a stop-gap, open an issue, and publish a release note about this being a known problem. Should we also fatal-error if those APIs are called or if the mapping is nested in a way we don't fully support?
@@ -23,6 +23,8 @@ extension Regex { | |||
public let range: Range<String.Index> | |||
|
|||
let value: Any? | |||
|
|||
var transform: ((Any) -> Output)? |
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's the tradeoff of storing transform here vs just doing it when making a Match object?
I.e. |
Hey, I've been lurking this issue for a little while. @Azoy, do you have any info on the status of this feature? |
This implements
mapOutput
on Regex from: https://github.com/apple/swift-evolution/blob/d2b03bf572c7d13c575067641a5d9d1d52cb1750/proposals/0351-regex-builder.md#mapping-output