-
Notifications
You must be signed in to change notification settings - Fork 49
Throwing customization hooks #261
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
Adds test to try out throwing custom code. Adds processor support.
@swift-ci please test |
I would like to add the following, but we don't take struct Poison: Error, Hashable {}
struct Overflow: Error, Hashable {}
let addressRegex = Regex {
"0x"
Capture(OneOrMore(.hexDigit)) { hex -> Int in
guard let i = Int(hex, radix: 16) else {
throw Overflow()
}
if i == 0xdeadbeef {
throw Poison()
}
return i
}
} |
Added support for |
@rxwei it seems you beat me to the second commit by 4 minutes, drat. Care to take a look at the rest? |
What's the proposed new behavior? Is it the following:
|
Yes, that’s right |
LGTM |
The non-Optional-returning ones on TryCapture could probably be removed. |
Done. @swift-ci please test |
- Update the name `CustomRegexComponent` to `CustomMatchingRegexComponent` per pitch - Adopt `throws` for `CustomMatchingRegexComponent` as added in swiftlang#261. Errors thrown by `CustomMatchingRegexComponent`'s conformers will be bubbled up to the engine and surfaced at client-side.
- Update the name `CustomRegexComponent` to `CustomMatchingRegexComponent` per pitch - Adopt `throws` for `CustomMatchingRegexComponent` as added in swiftlang#261. Errors thrown by `CustomMatchingRegexComponent`'s conformers will be bubbled up to the engine and surfaced at client-side.
- Update the name `CustomRegexComponent` to `CustomMatchingRegexComponent` per pitch - Adopt `throws` for `CustomMatchingRegexComponent` as added in swiftlang#261. Errors thrown by `CustomMatchingRegexComponent`'s conformers will be bubbled up to the engine and surfaced at client-side.
* Throwing customization hooks * Adds test to try out throwing custom code. * Adds processor support. * Add throws to capture transform API, plumbing * Remove non-failable try-capture overloads
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename Output associated type to RegexOutput. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename `Output` associated type to `RegexOutput`. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename `Output` associated type to `RegexOutput`. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`.
* [SE-0351] Revise regex builder proposal Revision: - Capture takes throwing closures. (swiftlang/swift-experimental-string-processing#261) - Rename `Output` associated type to `RegexOutput`. (swiftlang/swift-experimental-string-processing#281) - Define primary associated type for `RegexComponent`. Clarification: - Clarify that `RegexComponent` and `Regex: RegexComponent` will be in the stdlib, not in `RegexBuilder`. - Make detailed design driven by example and move API definition to a collapsible. This is so that the complex result builder machinery won't obscure the API design. - Add alternative considered section about unifying `Capture` and `TryCapture`. * Add section about anchors and lookaheads * Add section re `mapOutput` * Move mapOutput to Regex instead of RegexComponent * Address comments. * Minor fix in RegexComponent declaration * Capture transform shouldn't be restricted to taking a `Substring` * Fix syntax highlighting * Update 0351-regex-builder.md * Revise `RegexComponentBuilder.buildPartialBlock(first:)`. Also fix broken links. * Update 0351-regex-builder.md Co-authored-by: Nate Cook <[email protected]> Co-authored-by: Stephen Canon <[email protected]> Co-authored-by: Ben Cohen <[email protected]>
Adds test to try out throwing custom code. Adds processor support.