Skip to content

[Integration] main (f779459) -> swift/main #400

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 29 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e748aea
Add NegativeLookahead and Anchor comments (#372)
natecook1000 May 2, 2022
13342eb
Add matching support for `\p{Lc}`
hamishknight May 3, 2022
925f51b
Add parser support for `\p{L&}`
hamishknight May 3, 2022
ade8f01
Merge pull request #373 from hamishknight/case-in-prop
hamishknight May 3, 2022
c44efeb
Update ProposalOverview.md
milseman May 3, 2022
9801855
Add tests for AnyRegexOutput (#371)
milseman May 3, 2022
0e5cfa8
Rename noAutoCapture -> namedCapturesOnly
hamishknight May 4, 2022
2a4b3a6
Implement the `(?n)` option
hamishknight May 4, 2022
f22cb4f
Merge pull request #377 from hamishknight/named-captures-only
hamishknight May 4, 2022
6d833aa
Improve Unicode/UTS18 and semantic level support (#268)
natecook1000 May 5, 2022
09a385b
Support Unicode scalar names in `\p{name=...}` (#382)
natecook1000 May 6, 2022
39c0ed5
Modify DSL test to test for uncaptured backreference (#355)
natecook1000 May 6, 2022
9740416
Introduce ASTStage parameter to `parse`
hamishknight May 9, 2022
4b31736
Implement semantic diagnostics
hamishknight May 9, 2022
466b375
Validate capture lists
hamishknight May 9, 2022
c95e862
Address review feedback
hamishknight May 9, 2022
7f068dc
Merge pull request #379 from hamishknight/sema
hamishknight May 9, 2022
c16e389
Implement \R, \v, \h for character/scalar modes (#384)
natecook1000 May 9, 2022
c13980f
De-deprecate MatchingOptions.matchLevel (#390)
natecook1000 May 9, 2022
61965c3
Restrict character property fuzzy matching to "pattern whitespace"
hamishknight May 10, 2022
05e610a
Improve the wording of a diagnostic
hamishknight May 10, 2022
7752015
Introduce AST.Atom.Scalar
hamishknight May 10, 2022
f436cca
Introduce scalar sequences `\u{AA BB CC}`
hamishknight May 10, 2022
0597164
Fix invalid indexing
hamishknight May 10, 2022
0872d16
Fix source location tracking in `lexUntil`
hamishknight May 10, 2022
5b30c5b
Merge pull request #386 from hamishknight/multiscalar
hamishknight May 10, 2022
b209e4f
Tidy up build flags and fix implicit import circular dependency (#392)
rxwei May 10, 2022
f779459
Catch more unquantifiable elements (#391)
natecook1000 May 10, 2022
f37fc9b
Merge branch 'main' into main-merge
hamishknight May 11, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.DS_Store

# The current toolchain is dumping files in the package root, rude
*.emit-module.*

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
Expand Down
1 change: 1 addition & 0 deletions Documentation/Evolution/ProposalOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Regex Type and Overview

- [Second review](https://forums.swift.org/t/se-0350-second-review-regex-type-and-overview/56886)
- [Proposal](https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md), [Thread](https://forums.swift.org/t/se-0350-regex-type-and-overview/56530)
- [Pitch thread](https://forums.swift.org/t/pitch-regex-type-and-overview/56029)

Expand Down
27 changes: 11 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ let availabilityDefinition = PackageDescription.SwiftSetting.unsafeFlags([
#"SwiftStdlib 5.7:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999"#,
])

let stdlibSettings: [PackageDescription.SwiftSetting] = [
.unsafeFlags(["-enable-library-evolution"]),
.unsafeFlags(["-Xfrontend", "-disable-implicit-concurrency-module-import"]),
.unsafeFlags(["-Xfrontend", "-disable-implicit-string-processing-module-import"]),
availabilityDefinition
]

let package = Package(
name: "swift-experimental-string-processing",
products: [
Expand All @@ -36,10 +43,7 @@ let package = Package(
.target(
name: "_RegexParser",
dependencies: [],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
availabilityDefinition
]),
swiftSettings: stdlibSettings),
.testTarget(
name: "MatchingEngineTests",
dependencies: [
Expand All @@ -51,29 +55,21 @@ let package = Package(
.target(
name: "_StringProcessing",
dependencies: ["_RegexParser", "_CUnicode"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
availabilityDefinition
]),
swiftSettings: stdlibSettings),
.target(
name: "RegexBuilder",
dependencies: ["_StringProcessing", "_RegexParser"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
availabilityDefinition
]),
swiftSettings: stdlibSettings),
.testTarget(
name: "RegexTests",
dependencies: ["_StringProcessing"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
]),
.testTarget(
name: "RegexBuilderTests",
dependencies: ["_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
]),
.testTarget(
Expand Down Expand Up @@ -102,7 +98,6 @@ let package = Package(
name: "Exercises",
dependencies: ["_RegexParser", "_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
]),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See [Declarative String Processing Overview][decl-string]

## Requirements

- [Swift Trunk Development Snapshot](https://www.swift.org/download/#snapshots) DEVELOPMENT-SNAPSHOT-2022-03-09 or later.
- [Swift Trunk Development Snapshot](https://www.swift.org/download/#snapshots) DEVELOPMENT-SNAPSHOT-2022-04-20 or later.

## Trying it out

Expand Down
2 changes: 1 addition & 1 deletion Sources/PatternConverter/PatternConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PatternConverter: ParsableCommand {
print("Converting '\(delim)\(regex)\(delim)'")

let ast = try _RegexParser.parse(
regex,
regex, .semantic,
experimentalSyntax ? .experimental : .traditional)

// Show rendered source ranges
Expand Down
97 changes: 88 additions & 9 deletions Sources/RegexBuilder/Anchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
@_implementationOnly import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

/// A regex component that matches a specific condition at a particular position
/// in an input string.
///
/// You can use anchors to guarantee that a match only occurs at certain points
/// in an input string, such as at the beginning of the string or at the end of
/// a line.
@available(SwiftStdlib 5.7, *)
public struct Anchor {
internal enum Kind {
Expand Down Expand Up @@ -53,14 +59,24 @@ extension Anchor: RegexComponent {

@available(SwiftStdlib 5.7, *)
extension Anchor {
/// An anchor that matches at the start of the input string.
///
/// This anchor is equivalent to `\A` in regex syntax.
public static var startOfSubject: Anchor {
Anchor(kind: .startOfSubject)
}


/// An anchor that matches at the end of the input string or at the end of
/// the line immediately before the the end of the string.
///
/// This anchor is equivalent to `\Z` in regex syntax.
public static var endOfSubjectBeforeNewline: Anchor {
Anchor(kind: .endOfSubjectBeforeNewline)
}


/// An anchor that matches at the end of the input string.
///
/// This anchor is equivalent to `\z` in regex syntax.
public static var endOfSubject: Anchor {
Anchor(kind: .endOfSubject)
}
Expand All @@ -70,33 +86,67 @@ extension Anchor {
// Anchor(kind: resetStartOfMatch)
// }

/// An anchor that matches at the first position of a match in the input
/// string.
public static var firstMatchingPositionInSubject: Anchor {
Anchor(kind: .firstMatchingPositionInSubject)
}

/// An anchor that matches at a grapheme cluster boundary.
///
/// This anchor is equivalent to `\y` in regex syntax.
public static var textSegmentBoundary: Anchor {
Anchor(kind: .textSegmentBoundary)
}

/// An anchor that matches at the start of a line, including the start of
/// the input string.
///
/// This anchor is equivalent to `^` in regex syntax when the `m` option
/// has been enabled or `anchorsMatchLineEndings(true)` has been called.
public static var startOfLine: Anchor {
Anchor(kind: .startOfLine)
}

/// An anchor that matches at the end of a line, including at the end of
/// the input string.
///
/// This anchor is equivalent to `$` in regex syntax when the `m` option
/// has been enabled or `anchorsMatchLineEndings(true)` has been called.
public static var endOfLine: Anchor {
Anchor(kind: .endOfLine)
}

/// An anchor that matches at a word boundary.
///
/// Word boundaries are identified using the Unicode default word boundary
/// algorithm by default. To specify a different word boundary algorithm,
/// see the `RegexComponent.wordBoundaryKind(_:)` method.
///
/// This anchor is equivalent to `\b` in regex syntax.
public static var wordBoundary: Anchor {
Anchor(kind: .wordBoundary)
}

/// The inverse of this anchor, which matches at every position that this
/// anchor does not.
///
/// For the `wordBoundary` and `textSegmentBoundary` anchors, the inverted
/// version corresponds to `\B` and `\Y`, respectively.
public var inverted: Anchor {
var result = self
result.isInverted.toggle()
return result
}
}

/// A regex component that allows a match to continue only if its contents
/// match at the given location.
///
/// A lookahead is a zero-length assertion that its included regex matches at
/// a particular position. Lookaheads do not advance the overall matching
/// position in the input string — once a lookahead succeeds, matching continues
/// in the regex from the same position.
@available(SwiftStdlib 5.7, *)
public struct Lookahead<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>
Expand All @@ -105,19 +155,48 @@ public struct Lookahead<Output>: _BuiltinRegexComponent {
self.regex = regex
}

/// Creates a lookahead from the given regex component.
public init<R: RegexComponent>(
_ component: R,
negative: Bool = false
_ component: R
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component.regex.root))
self.init(node: .nonCapturingGroup(.lookahead, component.regex.root))
}

/// Creates a lookahead from the regex generated by the given builder closure.
public init<R: RegexComponent>(
@RegexComponentBuilder _ component: () -> R
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(.lookahead, component().regex.root))
}
}

/// A regex component that allows a match to continue only if its contents
/// do not match at the given location.
///
/// A negative lookahead is a zero-length assertion that its included regex
/// does not match at a particular position. Lookaheads do not advance the
/// overall matching position in the input string — once a lookahead succeeds,
/// matching continues in the regex from the same position.
@available(SwiftStdlib 5.7, *)
public struct NegativeLookahead<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

init(_ regex: Regex<Output>) {
self.regex = regex
}

/// Creates a negative lookahead from the given regex component.
public init<R: RegexComponent>(
_ component: R
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(.negativeLookahead, component.regex.root))
}

/// Creates a negative lookahead from the regex generated by the given builder
/// closure.
public init<R: RegexComponent>(
negative: Bool = false,
@RegexComponentBuilder _ component: () -> R
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component().regex.root))
self.init(node: .nonCapturingGroup(.negativeLookahead, component().regex.root))
}
}
4 changes: 3 additions & 1 deletion Sources/_RegexParser/Regex/AST/AST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ extension AST.Node {
switch self {
case .atom(let a):
return a.isQuantifiable
case .group, .conditional, .customCharacterClass, .absentFunction:
case .group(let g):
return g.isQuantifiable
case .conditional, .customCharacterClass, .absentFunction:
return true
case .alternation, .concatenation, .quantification, .quote, .trivia,
.empty:
Expand Down
Loading