Skip to content

[Integration] main (50ec05d) -> swift/main #225

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 27 commits into from
Mar 22, 2022

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Mar 21, 2022

No description provided.

rxwei and others added 27 commits March 8, 2022 14:17
…exComponentBuilder`. (swiftlang#200)

We've decided to use `RegexComponent` for the protocol, and use `RegexComponentBuilder` for the builder type since we want the user to import a module named `RegexBuilder` to get the DSL.
Replace free functions such as `oneOrMore` with types such as `OneOrMore`. This hides overloads of free functions as initializers within those types. It also makes the DSL consistent with SwiftUI.

- `oneOrMore` -> `OneOrMore`
- `zeroOrMore` -> `ZeroOrMore`
- `optionally` -> `Optionally`
- `repeating` -> `Repeat`
- `choiceOf` -> `ChoiceOf`
- `capture` -> `Capture`
- `tryCapture` -> `TryCapture`

Note: The reason we didn't realize this was possible (e.g. in swiftlang#126) was because we were narrowly focused on including the subpattern type in the quantifier/combinator's generic parameter, i.e. `OneOrMore<Component: RegexComponent>`, which made it impossible to deduce each type's `typealias Match` from `Component`. Now we have an unconstrained generic parameter (e.g. `OneOrMore<Match>`) which gives us the full flexibility to hide `Match` deduction rules in initializers' type signatures.
Transition from the old name `buildBlock(combining:into:)` to the [newly proposed](https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561) `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)`.

Requires DEVELOPMENT-SNAPSHOT-2022-03-09 or later.
This is something we should've done earlier, as we've been referring to this type as `MatchResult` the whole time.  The only reason I named it `RegexMatch` was because the (now deleted) VM had a lower-level type named `MatchResult`.
Rename `RegexMatch` to `MatchResult`.
- Add a new pitch for the regex builder DSL.
- Update the strongly typed regex captures pitch to the latest design.
Fix typo and `ChoiceOf` initializer in DSL pitch.
Given that the `Regex` type pitch is going to include the `Regex.Match` type, we add the extension that contains `subscript(_: Reference)` to the DSL pitch. Also fix the `Reference` code example.
Add `Regex.Match.subscript(_: Reference)` to DSL pitch.
- Require creating an branch from a commit on main instead of merging from main, as main is moving constantly.
- Require creating a dummy PR in apple/swift before we have full CI in this repo.
Rename Alternation to OrderedChoice, scrap groupTransform and capturing from group in favor of a capture node.
- Rename the `Match` associatedtype in `RegexComponent` to `Output`.
- Rename `MatchResult` to `Regex.Match`.

The new names have been pitched as part of the [regex type](https://forums.swift.org/t/pitch-regex-type-and-overview/56029) and the [regex builder DSL](https://forums.swift.org/t/pitch-regex-builder-dsl/56007).
`AnyRegexOutput` is a collection type that represents a type-erased regex output with two use cases:
- When a `Regex` is initialized from a string, e.g. `Regex("(a)|(b)|c")`, it has type `Regex<AnyRegexOutput>`. One can iterate over the output to access output elements (the whole match followed by any captures).
- When working with an existing code base that uses dynamic `Regex` creation from strings, one can type-erase the match result of a strongly typed regex, e.g. `Regex<(Substring, Substring, Substring)>.Match`, and use it as a drop in replacement for the dynamic regex match.

This has been pitched as part of the [regex type](https://forums.swift.org/t/pitch-regex-type-and-overview/56029).

---

Example:

```swift
let regex = try! Regex(#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#)
let line = """
  A6F0..A6F1    ; Extend # Mn   [2] BAMUM COMBINING MARK KOQNDON..BAMUM \
  COMBINING MARK TUKWENTIS
  """
let match = line.firstMatch(of: regex)!
let output = match.output // `AnyRegexOutput`
output.0            // => (the entire match)
output[0].bounds    // => (the bounds of the entire match)
output[0].substring // => (the entire match)
output[1].substring // => "A6F0"
output[2].substring // => "A6F1"
output[3].substring // => "Extend"
```
Supports conversion from `AnyRegexOutput` to a user-specified type.
@rxwei
Copy link
Contributor Author

rxwei commented Mar 21, 2022

@swift-ci please test

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rxwei rxwei merged commit 93a894e into swiftlang:swift/main Mar 22, 2022
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