-
Notifications
You must be signed in to change notification settings - Fork 49
Generic Reference
type and match result subscript
#182
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 Linux |
Now that we've flattened the structured capture groups, can the |
Yes, the new capture type produced by |
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.
LGTM
@@ -11,8 +11,24 @@ | |||
|
|||
@dynamicMemberLookup | |||
public struct RegexMatch<Match> { | |||
let input: String |
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.
IIUC, this will (eventually) allow our storage form to be purely range based.
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 now purely range based.
d44dea0
to
96e9e7e
Compare
@swift-ci please test |
To simplify the call site, I chose to precondition instead of returning optionals. Examples: ``` let a = Reference(Substring.self) let result = regex.match { tryCapture(as: a) { oneOrMore(.digit) } transform: { Int($0) } } result[a] // => Any result[a] // => Int ```
96e9e7e
to
8becc44
Compare
@swift-ci please test |
Change
Reference
to generic type overCapture
. Add asubscript<T>(_: Reference<T>) -> T
toRegexMatch
to allow the user to access a capture via a reference.Alternatives considered:
subscript(_: Reference) -> Any
with non-genericReference
. While creating aReference
would remain easy, it would lose the benefits of strong types.Reference<Capture>.init() where Capture == Substring
. This allows writingReference()
to conveniently create aReference<Substring>
, but when it’s used on any transformed capture, it causes the “expression is too complex” error. I think this is a harmful outcome as it's hard for developers to figure that the fix is actually specifying a type in theReference
initializer.Examples: