Skip to content

Switch back to Swift tuples for typed captures #127

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 2 commits into from
Feb 8, 2022

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Jan 25, 2022

This depends on #114 and #126. Please review 3db17b5.

@rxwei rxwei force-pushed the swift-tuples branch 3 times, most recently from 12c7e6e to 3db17b5 Compare January 31, 2022 04:11
@rxwei rxwei mentioned this pull request Feb 3, 2022
@rxwei
Copy link
Contributor Author

rxwei commented Feb 7, 2022

@swift-ci please test linux

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, if I'm reading the diffs right between this and #126

input[range], DynamicCaptures(captures)
) as! Match
if Match.self == (Substring, DynamicCaptures).self {
convertedMatch = (input[range], DynamicCaptures(captures)) as! Match
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering, what is this code path for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See testDynamicCaptures(). This is used for compiling and running a regex string that's not known at compile time (#36).

rxwei added 2 commits February 7, 2022 16:11
…ions. This allows for a lot more flexibility with overloading a quantifier based on the input `Match` type. The immediate benefit of this is getting rid of void and nested void types (see example below), and as a result eliminate the need for void-filtering within concatenation. A more important benefit is being able to get rid of nominal tuples and switch back to Swift tuples, as Swift tuples enable strongly typed named captures and eliminates the complexity that comes with nominal tuples.

-----

Before:
```swift
let r0 = OneOrMore(.digit) // => `.Match == Tuple2<Substring, [()]>`
let r1 = Optionally(.digit) // => `.Match == Tuple2<Substring, ()?>`
let r2 = OneOrMore(Repeat(Optionally(.digit))) // => `.Match == Tuple2<Substring, [[()?]]>`
"123".match(r2) // => `RegexMatch<Tuple2<Substring, [[()?]]>>?`
```
After:
```swift
let r0 = oneOrMore(.digit) // => `.Match == Substring`
let r1 = optionally(.digit) // => `.Match == Substring`
let r2 = oneOrMore(many(optionally(.digit))) // => `.Match == Substring`
"123".match(r2) // => `RegexMatch<Substring>`
```

-----

Before:
```swift
/(?<number>\d+)/ // => `Regex<Tuple2<Substring, Substring>>`
```

After:
```swift
/(?<number>\d+)/ // => `Regex<(Substring, number: Substring)>`
```
@rxwei
Copy link
Contributor Author

rxwei commented Feb 8, 2022

@swift-ci please test Linux

@rxwei rxwei merged commit 4c252c0 into swiftlang:main Feb 8, 2022
@rxwei rxwei deleted the swift-tuples branch February 8, 2022 01:29
@rxwei rxwei mentioned this pull request Feb 8, 2022
rxwei added a commit to rxwei/swift that referenced this pull request Feb 10, 2022
Typed captures no longer use ad-hoc nominal tuples. We use Swift native tuples instead. See swiftlang/swift-experimental-string-processing#127.

Update checkout tag to dev/6.
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