Skip to content

Commit 626f567

Browse files
committed
Working? Solution
Sloppy reverse quant Fix reverse quant?
1 parent b5764dd commit 626f567

File tree

17 files changed

+1460
-115
lines changed

17 files changed

+1460
-115
lines changed

Sources/RegexBuilder/Anchor.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,52 @@ public struct NegativeLookahead<Output>: _BuiltinRegexComponent {
226226
self.init(_RegexFactory().negativeLookaheadNonCapturing(component()))
227227
}
228228
}
229+
230+
// TODO: Write header doc
231+
@available(SwiftStdlib 5.10, *)
232+
public struct Lookbehind<Output>: _BuiltinRegexComponent {
233+
public var regex: Regex<Output>
234+
235+
init(_ regex: Regex<Output>) {
236+
self.regex = regex
237+
}
238+
239+
/// Creates a lookbehind from the given regex component.
240+
public init<R: RegexComponent>(
241+
_ component: R
242+
) where R.RegexOutput == Output {
243+
self.init(_RegexFactory().lookbehindNonCapturing(component))
244+
}
245+
246+
/// Creates a lookbehind from the regex generated by the given builder closure.
247+
public init<R: RegexComponent>(
248+
@RegexComponentBuilder _ component: () -> R
249+
) where R.RegexOutput == Output {
250+
self.init(_RegexFactory().lookbehindNonCapturing(component()))
251+
}
252+
}
253+
254+
// TODO: Write header doc
255+
@available(SwiftStdlib 5.10, *)
256+
public struct NegativeLookbehind<Output>: _BuiltinRegexComponent {
257+
public var regex: Regex<Output>
258+
259+
init(_ regex: Regex<Output>) {
260+
self.regex = regex
261+
}
262+
263+
/// Creates a negative lookbehind from the given regex component.
264+
public init<R: RegexComponent>(
265+
_ component: R
266+
) where R.RegexOutput == Output {
267+
self.init(_RegexFactory().negativeLookbehindNonCapturing(component))
268+
}
269+
270+
/// Creates a negative lookbehind from the regex generated by the given builder
271+
/// closure.
272+
public init<R: RegexComponent>(
273+
@RegexComponentBuilder _ component: () -> R
274+
) where R.RegexOutput == Output {
275+
self.init(_RegexFactory().negativeLookbehindNonCapturing(component()))
276+
}
277+
}

Sources/_RegexParser/Regex/Parse/Sema.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ extension RegexValidator {
370370
}
371371
switch kind.value {
372372
case .capture, .namedCapture, .nonCapture, .lookahead, .negativeLookahead,
373-
.atomicNonCapturing:
373+
.atomicNonCapturing, .lookbehind:
374374
break
375375

376376
case .balancedCapture:
@@ -384,7 +384,7 @@ extension RegexValidator {
384384
case .nonAtomicLookahead:
385385
error(.unsupported("non-atomic lookahead"), at: kind.location)
386386

387-
case .lookbehind, .negativeLookbehind, .nonAtomicLookbehind:
387+
case .negativeLookbehind, .nonAtomicLookbehind:
388388
error(.unsupported("lookbehind"), at: kind.location)
389389

390390
case .scriptRun, .atomicScriptRun:

0 commit comments

Comments
 (0)