Skip to content

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

Merged
merged 3 commits into from
Apr 10, 2022
Merged

Conversation

milseman
Copy link
Member

@milseman milseman commented Apr 9, 2022

Adds test to try out throwing custom code. Adds processor support.

Adds test to try out throwing custom code. Adds processor support.
@milseman milseman requested a review from rxwei April 9, 2022 20:30
@milseman
Copy link
Member Author

milseman commented Apr 9, 2022

@swift-ci please test

@milseman
Copy link
Member Author

milseman commented Apr 9, 2022

I would like to add the following, but we don't take throws on Capture currently (should we?)

    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
      }
    }

@milseman
Copy link
Member Author

Added support for throws everywhere

@milseman
Copy link
Member Author

@rxwei it seems you beat me to the second commit by 4 minutes, drat. Care to take a look at the rest?

@rxwei
Copy link
Contributor

rxwei commented Apr 10, 2022

What's the proposed new behavior? Is it the following:

  • Throwing means abort in both Capture and TryCapture.
  • TryCapture backtracks when the capture transform returns nil.

@milseman
Copy link
Member Author

Yes, that’s right

@rxwei
Copy link
Contributor

rxwei commented Apr 10, 2022

LGTM

@rxwei
Copy link
Contributor

rxwei commented Apr 10, 2022

The non-Optional-returning ones on TryCapture could probably be removed.

@milseman
Copy link
Member Author

Done.

@swift-ci please test

@milseman milseman merged commit fed4c53 into swiftlang:main Apr 10, 2022
@milseman milseman deleted the git_me_outta_here branch April 10, 2022 17:07
itingliu added a commit to itingliu/swift-experimental-string-processing that referenced this pull request Apr 13, 2022
- 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.
itingliu added a commit to itingliu/swift-experimental-string-processing that referenced this pull request Apr 13, 2022
- 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.
itingliu added a commit to itingliu/swift-experimental-string-processing that referenced this pull request Apr 16, 2022
- 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.
Azoy pushed a commit to Azoy/swift-experimental-string-processing that referenced this pull request Apr 19, 2022
* 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
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 25, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 26, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 27, 2022
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`.
rxwei added a commit to rxwei/swift-evolution that referenced this pull request Apr 27, 2022
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`.
airspeedswift added a commit to swiftlang/swift-evolution that referenced this pull request Jul 6, 2022
* [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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants