Skip to content

[Integration] main (293bad4) -> swift/main #296

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 10 commits into from
Apr 19, 2022
2 changes: 1 addition & 1 deletion Documentation/Evolution/StringProcessingAlgorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public protocol CustomMatchingRegexComponent : RegexComponent {
_ input: String,
startingAt index: String.Index,
in bounds: Range<String.Index>
) -> (upperBound: String.Index, match: Match)?
) throws -> (upperBound: String.Index, match: Match)?
}
```

Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let package = Package(
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
]),
.target(
.testTarget(
name: "Prototypes",
dependencies: ["_RegexParser", "_StringProcessing"],
swiftSettings: [
Expand All @@ -100,7 +100,7 @@ let package = Package(
// MARK: Exercises
.target(
name: "Exercises",
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
dependencies: ["_RegexParser", "_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
Expand Down
1 change: 0 additions & 1 deletion Sources/Exercises/Exercises.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public enum Exercises {
HandWrittenParticipant.self,
RegexDSLParticipant.self,
RegexLiteralParticipant.self,
PEGParticipant.self,
NSREParticipant.self,
]
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Exercises/Participants/PEGParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
//
//===----------------------------------------------------------------------===//

// Disabled because Prototypes is a test target.
#if false

struct PEGParticipant: Participant {
static var name: String { "PEG" }
}
Expand Down Expand Up @@ -51,3 +54,4 @@ private func graphemeBreakPropertyData(forLine line: String) -> GraphemeBreakEnt

}

#endif
16 changes: 9 additions & 7 deletions Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,29 @@ extension DSLTree.Node {
@available(SwiftStdlib 5.7, *)
static func repeating(
_ range: Range<Int>,
_ behavior: QuantificationBehavior,
_ behavior: QuantificationBehavior?,
_ node: DSLTree.Node
) -> DSLTree.Node {
// TODO: Throw these as errors
assert(range.lowerBound >= 0, "Cannot specify a negative lower bound")
assert(!range.isEmpty, "Cannot specify an empty range")

let kind: DSLTree.QuantificationKind = behavior.map { .explicit($0.astKind) } ?? .default

switch (range.lowerBound, range.upperBound) {
case (0, Int.max): // 0...
return .quantification(.zeroOrMore, behavior.astKind, node)
return .quantification(.zeroOrMore, kind, node)
case (1, Int.max): // 1...
return .quantification(.oneOrMore, behavior.astKind, node)
return .quantification(.oneOrMore, kind, node)
case _ where range.count == 1: // ..<1 or ...0 or any range with count == 1
// Note: `behavior` is ignored in this case
return .quantification(.exactly(.init(faking: range.lowerBound)), .eager, node)
return .quantification(.exactly(.init(faking: range.lowerBound)), .default, node)
case (0, _): // 0..<n or 0...n or ..<n or ...n
return .quantification(.upToN(.init(faking: range.upperBound)), behavior.astKind, node)
return .quantification(.upToN(.init(faking: range.upperBound)), kind, node)
case (_, Int.max): // n...
return .quantification(.nOrMore(.init(faking: range.lowerBound)), behavior.astKind, node)
return .quantification(.nOrMore(.init(faking: range.lowerBound)), kind, node)
default: // any other range
return .quantification(.range(.init(faking: range.lowerBound), .init(faking: range.upperBound)), behavior.astKind, node)
return .quantification(.range(.init(faking: range.lowerBound), .init(faking: range.upperBound)), kind, node)
}
}
}
Expand Down
Loading