Skip to content

Update release 6.0 with main #743

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
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
29 changes: 15 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ let package = Package(
.executable(
name: "VariadicsGenerator",
targets: ["VariadicsGenerator"]),
.executable(
name: "RegexBenchmark",
targets: ["RegexBenchmark"])
// Disable to work around rdar://126877024
// .executable(
// name: "RegexBenchmark",
// targets: ["RegexBenchmark"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
Expand Down Expand Up @@ -142,17 +143,17 @@ let package = Package(
"_StringProcessing"
],
swiftSettings: [availabilityDefinition]),
.executableTarget(
name: "RegexBenchmark",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"_RegexParser",
"_StringProcessing",
"RegexBuilder"
],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
]),
// .executableTarget(
// name: "RegexBenchmark",
// dependencies: [
// .product(name: "ArgumentParser", package: "swift-argument-parser"),
// "_RegexParser",
// "_StringProcessing",
// "RegexBuilder"
// ],
// swiftSettings: [
// .unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
// ]),

// MARK: Exercises
.target(
Expand Down
21 changes: 21 additions & 0 deletions Sources/_RegexParser/Regex/Printing/PrettyPrinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public struct PrettyPrinter {

// The current default quantification behavior
public var quantificationBehavior: AST.Quantification.Kind = .eager

// A stack of the current added inline matching options, e.g. (?s) and a
// boolean indicating true = added (?s) and false = removed (?-s).
public var inlineMatchingOptions: [([AST.MatchingOption], Bool)] = []
}

// MARK: - Raw interface
Expand Down Expand Up @@ -142,4 +146,21 @@ extension PrettyPrinter {
printIndented(f)
print(endDelimiter)
}

/// Pushes the list of matching options to the current stack of other matching
/// options and increases the indentation level by 1.
public mutating func pushMatchingOptions(
_ options: [AST.MatchingOption],
isAdded: Bool
) {
indentLevel += 1
inlineMatchingOptions.append((options, isAdded))
}

/// Pops the most recent list of matching options from the printer and
/// decreases the indentation level by 1.
public mutating func popMatchingOptions() -> ([AST.MatchingOption], Bool) {
indentLevel -= 1
return inlineMatchingOptions.removeLast()
}
}
11 changes: 5 additions & 6 deletions Sources/_StringProcessing/ConsumerInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ extension DSLTree.CustomCharacterClass.Member {

return { input, bounds in
let curIdx = bounds.lowerBound
let nextIndex = isCharacterSemantic
? input.index(after: curIdx)
: input.unicodeScalars.index(after: curIdx)
let nextIndex = input.index(
after: curIdx, isScalarSemantics: !isCharacterSemantic)

// Under grapheme semantics, we compare based on single NFC scalars. If
// such a character is not single scalar under NFC, the match fails. In
Expand Down Expand Up @@ -353,9 +352,9 @@ extension AST.Atom.CharacterProperty {
if p(input, bounds) != nil { return nil }

// TODO: bounds check
return opts.semanticLevel == .graphemeCluster
? input.index(after: bounds.lowerBound)
: input.unicodeScalars.index(after: bounds.lowerBound)
return input.index(
after: bounds.lowerBound,
isScalarSemantics: opts.semanticLevel == .unicodeScalar)
}
}

Expand Down
14 changes: 11 additions & 3 deletions Sources/_StringProcessing/Engine/InstPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ struct QuantifyPayload: RawRepresentable {
case asciiBitset = 0
case asciiChar = 1
case any = 2
case builtin = 4
case builtinCC = 4
}

// TODO: figure out how to better organize this...
Expand All @@ -408,6 +408,14 @@ struct QuantifyPayload: RawRepresentable {
var typeMask: UInt64 { 7 }
var payloadMask: UInt64 { 0xFF_FF }

// Calculate the maximum number of trips, else UInt64.max if unbounded
var maxTrips: UInt64 {
guard let maxExtraTrips else {
return UInt64.max
}
return minTrips + maxExtraTrips
}

static func packInfoValues(
_ kind: AST.Quantification.Kind,
_ minTrips: Int,
Expand Down Expand Up @@ -489,7 +497,7 @@ struct QuantifyPayload: RawRepresentable {
+ (model.isInverted ? 1 << 9 : 0)
+ (model.isStrictASCII ? 1 << 10 : 0)
self.rawValue = packedModel
+ QuantifyPayload.packInfoValues(kind, minTrips, maxExtraTrips, .builtin, isScalarSemantics: isScalarSemantics)
+ QuantifyPayload.packInfoValues(kind, minTrips, maxExtraTrips, .builtinCC, isScalarSemantics: isScalarSemantics)
}

var type: PayloadType {
Expand Down Expand Up @@ -535,7 +543,7 @@ struct QuantifyPayload: RawRepresentable {
(self.rawValue & 1) == 1
}

var builtin: _CharacterClassModel.Representation {
var builtinCC: _CharacterClassModel.Representation {
_CharacterClassModel.Representation(rawValue: self.rawValue & 0xFF)!
}
var builtinIsInverted: Bool {
Expand Down
19 changes: 19 additions & 0 deletions Sources/_StringProcessing/Engine/MEBuiltins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,25 @@ extension String {
else { return nil }
return next
}

internal func matchRegexDot(
at currentPosition: Index,
limitedBy end: Index,
anyMatchesNewline: Bool,
isScalarSemantics: Bool
) -> Index? {
guard currentPosition < end else { return nil }

if anyMatchesNewline {
return index(
after: currentPosition, isScalarSemantics: isScalarSemantics)
}

return matchAnyNonNewline(
at: currentPosition,
limitedBy: end,
isScalarSemantics: isScalarSemantics)
}
}

// MARK: - Built-in character class matching
Expand Down
Loading