Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/_StringProcessing/RegexDSL/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public struct RegexMatch<Match> {
public subscript<T>(dynamicMember keyPath: KeyPath<Match, T>) -> T {
match[keyPath: keyPath]
}

// Allows `.0` when `Match` is not a tuple.
@_disfavoredOverload
public subscript(
dynamicMember keyPath: KeyPath<(Match, _doNotUse: ()), Match>
) -> Match {
match
}
}

extension RegexProtocol {
Expand Down
5 changes: 5 additions & 0 deletions Tests/RegexTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class RegexDSLTests: XCTestCase {
}
}

func testMatchResultDotZeroWithoutCapture() throws {
let match = try XCTUnwrap("aaa".match { oneOrMore { "a" } })
XCTAssertEqual(match.0, "aaa")
}

func testAlternation() throws {
do {
let regex = choiceOf {
Expand Down