diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index f76792aea..a931fcef9 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -294,8 +294,8 @@ struct VariadicsGenerator: ParsableCommand { var operatorName: String { switch self { case .zeroOrOne: return ".?" - case .zeroOrMore: return ".+" - case .oneOrMore: return ".*" + case .zeroOrMore: return ".*" + case .oneOrMore: return ".+" } } @@ -320,16 +320,16 @@ struct VariadicsGenerator: ParsableCommand { result += "Component: \(regexProtocolName)" return result }() - let captures = (0..( _ children: C ) -> CaptureStructure where C.Element: _TreeNode { -// assert(children.count > 1) return children.map { $0._captureStructure(&self) }.reduce(.empty, +) @@ -113,17 +112,15 @@ extension CaptureStructure.Constructor { } let branchCaptures = trueBranch._captureStructure(&self) + falseBranch._captureStructure(&self) - return captures + branchCaptures.map( - CaptureStructure.optional) + return captures + branchCaptures.map(CaptureStructure.optional) } public mutating func quantifying( _ child: T, amount: AST.Quantification.Amount ) -> CaptureStructure { - return child._captureStructure(&self).map( - amount == .zeroOrOne - ? CaptureStructure.optional - : CaptureStructure.array) + let result = child._captureStructure(&self) + return amount.bounds.atLeast == 0 + ? result.map(CaptureStructure.optional) : result } // TODO: Will need to adjust for DSLTree support, and diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 158e17042..10db6bc78 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -517,7 +517,7 @@ public func zeroOrMore( } @_disfavoredOverload -public postfix func .+( +public postfix func .*( _ component: Component ) -> Regex { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) @@ -541,7 +541,7 @@ public func oneOrMore( } @_disfavoredOverload -public postfix func .*( +public postfix func .+( _ component: Component ) -> Regex { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) @@ -582,7 +582,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -590,14 +590,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -606,7 +606,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0)> where Component.Match == (W, C0) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -614,14 +614,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0)> where Component.Match == (W, C0) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { +) -> Regex<(Substring, C0)> where Component.Match == (W, C0) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -630,7 +630,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -638,21 +638,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { + ) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -660,7 +660,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -668,14 +668,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0?, C1?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -684,7 +684,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0, C1)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -692,14 +692,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0, C1)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { +) -> Regex<(Substring, C0, C1)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -708,7 +708,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -716,21 +716,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { + ) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -738,7 +738,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -746,14 +746,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0?, C1?, C2?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -762,7 +762,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0, C1, C2)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -770,14 +770,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0, C1, C2)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { +) -> Regex<(Substring, C0, C1, C2)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -786,7 +786,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -794,21 +794,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -816,7 +816,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -824,14 +824,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -840,7 +840,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0, C1, C2, C3)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -848,14 +848,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0, C1, C2, C3)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { +) -> Regex<(Substring, C0, C1, C2, C3)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -864,7 +864,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -872,21 +872,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -894,7 +894,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -902,14 +902,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -918,7 +918,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0, C1, C2, C3, C4)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -926,14 +926,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0, C1, C2, C3, C4)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { +) -> Regex<(Substring, C0, C1, C2, C3, C4)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -942,7 +942,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -950,21 +950,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -972,7 +972,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -980,14 +980,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -996,7 +996,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -1004,14 +1004,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -1020,7 +1020,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -1028,21 +1028,21 @@ public func optionally( public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -1050,7 +1050,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -1058,14 +1058,14 @@ public func zeroOrMore( public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -1074,7 +1074,7 @@ public postfix func .+( public func oneOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -1082,14 +1082,14 @@ public func oneOrMore( public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -1098,7 +1098,7 @@ public postfix func .*( public func optionally( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -1106,21 +1106,21 @@ public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -1128,7 +1128,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -1136,14 +1136,14 @@ public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -1152,7 +1152,7 @@ public postfix func .+( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -1160,14 +1160,14 @@ public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } @@ -1176,7 +1176,7 @@ public postfix func .*( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @@ -1184,21 +1184,21 @@ public func optionally( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } public postfix func .?( _ component: Component -) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } extension RegexBuilder { public static func buildLimitedAvailability( _ component: Component - ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + ) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) } } @@ -1206,7 +1206,7 @@ extension RegexBuilder { public func zeroOrMore( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @@ -1214,14 +1214,14 @@ public func zeroOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } -public postfix func .+( +public postfix func .*( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) } @@ -1230,7 +1230,7 @@ public postfix func .+( _ component: Component, _ behavior: QuantificationBehavior = .eagerly -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @@ -1238,14 +1238,14 @@ public func oneOrMore( _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } -public postfix func .*( +public postfix func .+( _ component: Component -) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { +) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) } diff --git a/Tests/RegexTests/AlgorithmsTests.swift b/Tests/RegexTests/AlgorithmsTests.swift index 1454daaf5..7d1ade03e 100644 --- a/Tests/RegexTests/AlgorithmsTests.swift +++ b/Tests/RegexTests/AlgorithmsTests.swift @@ -146,12 +146,13 @@ class RegexConsumerTests: XCTestCase { input: "9+16, 0+3, 5+5, 99+1", result: "25, 3, 10, 100", { match in "\(match.result.1 + match.result.2)" }) - - replaceTest( - oneOrMore { int; "," }, - input: "3,5,8,0, 1,0,2,-5,x8,8,", - result: "16 3-5x16", - { match in "\(match.result.1.reduce(0, +))" }) + + // TODO: Need to support capture history + // replaceTest( + // oneOrMore { int; "," }, + // input: "3,5,8,0, 1,0,2,-5,x8,8,", + // result: "16 3-5x16", + // { match in "\(match.result.1.reduce(0, +))" }) replaceTest( Regex { int; "x"; int; optionally { "x"; int } }, diff --git a/Tests/RegexTests/CaptureTests.swift b/Tests/RegexTests/CaptureTests.swift index e1798520f..2d8836a3a 100644 --- a/Tests/RegexTests/CaptureTests.swift +++ b/Tests/RegexTests/CaptureTests.swift @@ -54,7 +54,9 @@ func captureTest( _ expected: CaptureStructure, _ tests: (input: String, output: Capture)..., skipEngine: Bool = false, - skipLegacy: Bool = false + skipLegacy: Bool = false, + file: StaticString = #file, + line: UInt = #line ) { let ast = try! parse(regex, .traditional) @@ -65,7 +67,9 @@ func captureTest( \(expected) Actual: \(capStructure) - """) + """, + file: file, + line: line) return } @@ -78,7 +82,9 @@ func captureTest( \(capStructure) DSLTree: \(dslCapStructure) - """) + """, + file: file, + line: line) return } @@ -95,16 +101,18 @@ func captureTest( guard isEqual(cap, output) else { XCTFail(""" - regex: \(regex), input: "\(input)" - Structure: - \(capStructure) - Capture list: - \(capFlat.latestUntyped(from: input)) - Expected: - \(output) - Actual: - \(cap) - """) + regex: \(regex), input: "\(input)" + Structure: + \(capStructure) + Capture list: + \(capFlat.latestUntyped(from: input)) + Expected: + \(output) + Actual: + \(cap) + """, + file: file, + line: line) continue } } @@ -115,12 +123,14 @@ func captureTest( guard isEqual(vmCap, output) else { XCTFail(""" - regex: \(regex), input: "\(input)" - Capture Structure: - \(capStructure) - Legacy VM Capture: - \(vmCap) - """) + regex: \(regex), input: "\(input)" + Capture Structure: + \(capStructure) + Legacy VM Capture: + \(vmCap) + """, + file: file, + line: line) continue } } @@ -174,16 +184,18 @@ extension RegexTests { captureTest( "a(b)*c", - .array(.atom()), - ("abc", array("b")), - ("ac", array("")), - ("abbc", array("b", "b"))) + .optional(.atom()), + ("abc", some("b")), + ("ac", none), + ("abbc", some("b")), + skipLegacy: true) captureTest( "a(b)+c", - .array(.atom()), - ("abc", array("b")), - ("abbc", array("b", "b"))) + .atom(), + ("abc", "b"), + ("abbc", "b"), + skipLegacy: true) captureTest( "a(b)?c", @@ -230,19 +242,19 @@ extension RegexTests { captureTest( "((a)|(b))*", .tuple( - .array(.atom()), - .array(.optional(.atom())), - .array(.optional(.atom()))), - ("a", tuple(array("a"), array(some("a")), array(none))), + .optional(.atom()), + .optional(.optional(.atom())), + .optional(.optional(.atom()))), + ("a", tuple(some("a"), some(some("a")), none)), skipEngine: true, skipLegacy: true) captureTest( "((a)|(b))+", .tuple( - .array(.atom()), - .array(.optional(.atom())), - .array(.optional(.atom()))), + .atom(), + .optional(.atom()), + .optional(.atom())), // TODO: test cases skipEngine: true, skipLegacy: true) @@ -251,9 +263,9 @@ extension RegexTests { "(((a)|(b))*)", .tuple( .atom(), - .array(.atom()), - .array(.optional(.atom())), - .array(.optional(.atom()))), + .optional(.atom()), + .optional(.optional(.atom())), + .optional(.optional(.atom()))), // TODO: test cases skipEngine: true, skipLegacy: true) @@ -293,9 +305,9 @@ extension RegexTests { "((((a)*)?)*)?", .tuple([ .optional(.atom()), - .optional(.array(.atom())), - .optional(.array(.optional(.atom()))), - .optional(.array(.optional(.array(.atom())))), + .optional(.optional(.atom())), + .optional(.optional(.optional(.atom()))), + .optional(.optional(.optional(.optional(.atom())))), ]), // TODO: test cases skipEngine: true, @@ -313,7 +325,7 @@ extension RegexTests { captureTest( "a|(b)*", - .optional(.array(.atom())), + .optional(.optional(.atom())), ("a", none), ("", someArray()), ("b", someArray("b")), @@ -323,7 +335,7 @@ extension RegexTests { captureTest( "a|(b)+", - .optional(.array(.atom())), + .optional(.atom()), ("a", noArray), ("b", someArray("b")), ("bbb", someArray("b", "b", "b")), @@ -357,7 +369,7 @@ extension RegexTests { captureTest( "a|(b|c)*", - .optional(.array(.atom())), + .optional(.optional(.atom())), ("a", noArray), ("", noArray), ("b", someArray("b")), @@ -392,10 +404,10 @@ extension RegexTests { captureTest( "a(b(c)*)", - .tuple(.atom(), .array(.atom())), - ("ab", tuple("b", array(""))), - ("abc", tuple("bc", array("c"))), - ("abcc", tuple("bcc", array("c", "c"))), + .tuple(.atom(), .optional(.atom())), + ("ab", tuple("b", none)), + ("abc", tuple("bc", some("c"))), + ("abcc", tuple("bcc", some("c"))), skipLegacy: true) captureTest( @@ -408,10 +420,10 @@ extension RegexTests { captureTest( "a(b(c))*", - .tuple(.array(.atom()), .array(.atom())), - ("a", tuple(array(""), array(""))), - ("abc", tuple(array("bc"), array("c"))), - ("abcbc", tuple(array("bc", "bc"), array("c", "c"))), + .tuple(.optional(.atom()), .optional(.atom())), + ("a", tuple(none, none)), + ("abc", tuple(some("bc"), some("c"))), + ("abcbc", tuple(some("bc"), some("c"))), skipLegacy: true) captureTest( diff --git a/Tests/RegexTests/ParseTests.swift b/Tests/RegexTests/ParseTests.swift index 547b13631..ac062111a 100644 --- a/Tests/RegexTests/ParseTests.swift +++ b/Tests/RegexTests/ParseTests.swift @@ -250,14 +250,14 @@ extension RegexTests { concat( zeroOrMore(of: capture(atom(.any))), capture(zeroOrMore(of: atom(.any)))), - captures: .tuple([.array(.atom()), .atom()])) + captures: .tuple([.optional(.atom()), .atom()])) parseTest( "((.))*((.)?)", concat( zeroOrMore(of: capture(capture(atom(.any)))), capture(zeroOrOne(of: capture(atom(.any))))), captures: .tuple([ - .array(.atom()), .array(.atom()), .atom(), .optional(.atom()) + .optional(.atom()), .optional(.atom()), .atom(), .optional(.atom()) ])) parseTest( #"abc\d"#, @@ -289,7 +289,7 @@ extension RegexTests { concat(quant( .zeroOrMore, .reluctant, nonCapture(capture(capture(alt("a", "b"))))), "c"), - captures: .tuple(.array(.atom()), .array(.atom()))) + captures: .tuple(.optional(.atom()), .optional(.atom()))) parseTest( "(a)|b|(c)d", alt(capture("a"), "b", concat(capture("c"), "d")), @@ -1138,7 +1138,7 @@ extension RegexTests { trueBranch: oneOrMore(of: capture("a")), falseBranch: "b" ), captures: .tuple([ - .atom(), .optional(.atom()), .atom(), .optional(.array(.atom())) + .atom(), .optional(.atom()), .atom(), .optional(.atom()) ])) parseTest(#"(?(?:(a)?(b))(a)+|b)"#, conditional( @@ -1148,7 +1148,7 @@ extension RegexTests { trueBranch: oneOrMore(of: capture("a")), falseBranch: "b" ), captures: .tuple([ - .optional(.atom()), .atom(), .optional(.array(.atom())) + .optional(.atom()), .atom(), .optional(.atom()) ])) parseTest(#"(?y)(?(xxx)a|b)"#, concat( diff --git a/Tests/RegexTests/RegexDSLTests.swift b/Tests/RegexTests/RegexDSLTests.swift index 48311afb7..0902addb0 100644 --- a/Tests/RegexTests/RegexDSLTests.swift +++ b/Tests/RegexTests/RegexDSLTests.swift @@ -95,7 +95,7 @@ class RegexDSLTests: XCTestCase { }.+ } XCTAssertTrue( - try XCTUnwrap("abc".match(regex)?.match) == ("abc", ["c"])) + try XCTUnwrap("abc".match(regex)?.match) == ("abc", "c")) } do { let regex = choiceOf { @@ -134,8 +134,8 @@ class RegexDSLTests: XCTestCase { func testCombinators() throws { try _testDSLCaptures( - ("aaaabccccdddkj", ("aaaabccccdddkj", "b", "cccc", ["d", "d", "d"], "k", nil, "j")), - captureType: (Substring, Substring, Substring, [Substring], Substring, Substring?, Substring?).self, ==) + ("aaaabccccdddkj", ("aaaabccccdddkj", "b", "cccc", "d", "k", nil, "j")), + captureType: (Substring, Substring, Substring, Substring, Substring, Substring?, Substring?).self, ==) { "a".+ capture(oneOrMore(Character("b"))) // Substring @@ -149,8 +149,8 @@ class RegexDSLTests: XCTestCase { func testQuantificationBehavior() throws { try _testDSLCaptures( - ("abc1def2", ("abc1def2", ["2"])), - captureType: (Substring, [Substring]).self, ==) + ("abc1def2", ("abc1def2", "2")), + captureType: (Substring, Substring).self, ==) { oneOrMore { oneOrMore(.word) @@ -159,8 +159,8 @@ class RegexDSLTests: XCTestCase { } try _testDSLCaptures( - ("abc1def2", ("abc1def2", ["1", "2"])), - captureType: (Substring, [Substring]).self, ==) + ("abc1def2", ("abc1def2", "2")), + captureType: (Substring, Substring).self, ==) { oneOrMore { oneOrMore(.word, .reluctantly) @@ -169,8 +169,8 @@ class RegexDSLTests: XCTestCase { } try _testDSLCaptures( - ("abc1def2", ("abc1def2", ["1", "2"])), - captureType: (Substring, [Substring]).self, ==) + ("abc1def2", ("abc1def2", "2")), + captureType: (Substring, Substring).self, ==) { oneOrMore { oneOrMore(.reluctantly) { @@ -233,9 +233,9 @@ class RegexDSLTests: XCTestCase { } } try _testDSLCaptures( - ("aaa 123 apple orange apple", ("aaa 123 apple orange apple", 123, [.apple, .orange, .apple])), - ("aaa ", ("aaa ", nil, [])), - captureType: (Substring, Int?, [Word]).self, ==) + ("aaa 123 apple orange apple", ("aaa 123 apple orange apple", 123, .apple)), + ("aaa ", ("aaa ", nil, nil)), + captureType: (Substring, Int?, Word?).self, ==) { "a".+ oneOrMore(.whitespace) @@ -266,7 +266,7 @@ class RegexDSLTests: XCTestCase { "e".? } } - let _: (Substring, Substring, [Int]).Type + let _: (Substring, Substring, Int?).Type = type(of: regex2).Match.self let regex3 = Regex { "a".+ @@ -278,7 +278,7 @@ class RegexDSLTests: XCTestCase { "e".? } } - let _: (Substring, Substring, Int, [Double]).Type + let _: (Substring, Substring, Int, Double?).Type = type(of: regex3).Match.self let regex4 = Regex { "a".+ @@ -292,7 +292,7 @@ class RegexDSLTests: XCTestCase { } } let _: ( - Substring, Substring, [(Substring, Substring, [Substring])]).Type + Substring, Substring, Substring, Substring, Substring?).Type = type(of: regex4).Match.self }