Skip to content

Commit 58005fd

Browse files
committed
Change lookahead function to Lookahead type
1 parent 9497168 commit 58005fd

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Sources/RegexBuilder/Anchor.swift

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,26 @@ extension Anchor {
107107
}
108108
}
109109

110-
public func lookahead<R: RegexComponent>(
111-
negative: Bool = false,
112-
@RegexComponentBuilder _ content: () -> R
113-
) -> Regex<R.Output> {
114-
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, content().regex.root))
115-
}
116-
117-
public func lookahead<R: RegexComponent>(
118-
_ component: R,
119-
negative: Bool = false
120-
) -> Regex<R.Output> {
121-
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, component.regex.root))
110+
public struct Lookahead<Output>: _BuiltinRegexComponent {
111+
public var regex: Regex<Output>
112+
113+
init(_ regex: Regex<Output>) {
114+
self.regex = regex
115+
}
116+
117+
public init<R: RegexComponent>(
118+
_ component: R,
119+
negative: Bool = false
120+
) where R.Output == Output {
121+
self.init(node: .nonCapturingGroup(
122+
negative ? .negativeLookahead : .lookahead, component.regex.root))
123+
}
124+
125+
public init<R: RegexComponent>(
126+
negative: Bool = false,
127+
@RegexComponentBuilder _ component: () -> R
128+
) where R.Output == Output {
129+
self.init(node: .nonCapturingGroup(
130+
negative ? .negativeLookahead : .lookahead, component().regex.root))
131+
}
122132
}

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ class RegexDSLTests: XCTestCase {
306306
matchType: Substring.self, ==)
307307
{
308308
OneOrMore("a")
309-
lookahead(CharacterClass.digit)
310-
lookahead("2", negative: true)
309+
Lookahead(CharacterClass.digit)
310+
Lookahead("2", negative: true)
311311
CharacterClass.word
312312
}
313313
}

0 commit comments

Comments
 (0)