Skip to content

[Integration] main (4d04019) -> swift/main #442

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 46 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3f54941
Implement .as for Regex
Azoy May 3, 2022
7e1ab7d
Unify Match and AnyRegexOutput
Azoy May 3, 2022
bc51e91
Ban numeric escapes in custom character classes
hamishknight May 10, 2022
a4a4a9a
Ban confusable multi-scalar ASCII characters
hamishknight May 10, 2022
db58c1b
Reserve `<{...}>` for interpolation syntax
hamishknight May 10, 2022
a53a40b
Remove the namedCaptureOffset and StructuredCapture
Azoy May 10, 2022
87ea119
Disable resilience on _RegexParser (#397)
rxwei May 11, 2022
baf9f22
Introduce `One`
rxwei May 12, 2022
d9d02c1
Ban `]` as literal first character of custom character class
hamishknight May 12, 2022
d3ea692
Merge pull request #404 from hamishknight/ban-empty-cc
hamishknight May 12, 2022
21f7910
Subsume referencedCaptureOffsets
Azoy May 12, 2022
c7b70a4
Add optional tests
Azoy May 12, 2022
b8178c2
Merge pull request #403 from rxwei/1
rxwei May 12, 2022
9d86c21
Wrap character classes around One
Azoy May 12, 2022
24c139a
fix intersection, subtraction, symmetricDiference
Azoy May 12, 2022
489c63c
Merge pull request #410 from Azoy/more-patternconverter-updates
Azoy May 13, 2022
9cf3cfc
Merge pull request #393 from hamishknight/stricter-syntax
hamishknight May 13, 2022
adf5688
Don't get stuck on empty matches (#415)
natecook1000 May 15, 2022
4f1e0ee
Underscore internal algorithms methods (#414)
natecook1000 May 15, 2022
4f8f67a
Remove the last SPI use of _RegexParser symbols (#416)
natecook1000 May 15, 2022
a4d7be0
Keep track of initial options in compiled program (#412)
natecook1000 May 16, 2022
c000596
More unicode properties (#385)
natecook1000 May 16, 2022
812c394
Keep substring bounds when searching in Regex.wholeMatch
natecook1000 May 17, 2022
ba33c0d
Merge pull request #421 from natecook1000/fix_wholematch_substring
natecook1000 May 17, 2022
7969272
Merge pull request #376 from Azoy/types-types-and-more-types
Azoy May 18, 2022
74f3b99
Add test fixtures for renderAsBuilderDSL (#423)
natecook1000 May 19, 2022
88dc9dd
Fix algorithms overload resolution issues (#402)
natecook1000 May 19, 2022
06dbc16
Introduce Source.lookahead
hamishknight May 24, 2022
8242df6
Remove `throws` from a couple of lexing methods
hamishknight May 24, 2022
e80322b
Add ASTBuilder helper for char class set operations
hamishknight May 24, 2022
1e57c5a
Simplify character class parsing a little
hamishknight May 24, 2022
95dc487
Dump the inverted bit of a custom character class
hamishknight May 24, 2022
9d84967
Allow empty comments
hamishknight May 24, 2022
24b64cd
Lex whitespace in range quantifiers
hamishknight May 24, 2022
8388d0f
Parse end-of-line comments in custom character classes
hamishknight May 24, 2022
5b0524a
Allow trivia between character class range operands
hamishknight May 24, 2022
bd9bf23
Merge pull request #431 from hamishknight/trivia-pursuit
hamishknight May 25, 2022
720ddd2
Implement named backreferences
hamishknight May 25, 2022
4b7d534
Remove `namedCaptureOffsets` from MECaptureList
hamishknight May 25, 2022
471e073
Merge pull request #433 from hamishknight/named-refs
hamishknight May 25, 2022
5495a75
Make `RegexCompilationError` internal
rxwei May 26, 2022
a936e9e
Merge pull request #438 from rxwei/internal-regex-compilation-error
rxwei May 26, 2022
f1b8581
Formalize Unicode block properties
hamishknight May 26, 2022
05f73db
Parse Java character properties
hamishknight May 26, 2022
4d04019
Merge pull request #440 from hamishknight/chunk-loader
hamishknight May 27, 2022
6d1d146
Merge branch 'main' into main-merge
hamishknight May 27, 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
Prev Previous commit
Next Next commit
Don't get stuck on empty matches (#415)
This fixes an issue where calling `matches(of:)` with an pattern
that matches an empty substring gets stuck searching the same position
over and over.
  • Loading branch information
natecook1000 authored May 15, 2022
commit adf5688a1618b950b051af5b23ddc71502aa0fed
12 changes: 10 additions & 2 deletions Sources/_StringProcessing/Algorithms/Matching/Matches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,22 @@ extension BidirectionalCollection where SubSequence == Substring {
let regex = r.regex

var result = [Regex<R.RegexOutput>.Match]()
while start < end {
while start <= end {
guard let match = try? regex._firstMatch(
slice.base, in: start..<end
) else {
break
}
result.append(match)
start = match.range.upperBound
if match.range.isEmpty {
if match.range.upperBound == end {
break
}
// FIXME: semantic level
start = slice.index(after: match.range.upperBound)
} else {
start = match.range.upperBound
}
}
return result
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Regex/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ extension Regex {

var low = inputRange.lowerBound
let high = inputRange.upperBound
while low < high {
while true {
if let m = try _match(input, in: low..<high, mode: .partialFromFront) {
return m
}
if low == high { return nil }
input.formIndex(after: &low)
}
return nil
}
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/RegexTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class AlgorithmTests: XCTestCase {
let actualCol: [Range<Int>] = string[...].ranges(of: regex)[...].map(string.offsets(of:))
XCTAssertEqual(actualCol, expected, file: file, line: line)

let matchRanges = string.matches(of: regex).map { string.offsets(of: $0.range) }
XCTAssertEqual(matchRanges, expected, file: file, line: line)

let firstRange = string.firstRange(of: regex).map(string.offsets(of:))
XCTAssertEqual(firstRange, expected.first, file: file, line: line)
}
Expand Down Expand Up @@ -332,6 +335,11 @@ class AlgorithmTests: XCTestCase {
XCTAssertEqual(
s2.matches(of: regex).map(\.0),
["aa"])

XCTAssertEqual(
s2.matches(of: try Regex("a*?")).map { s2.offsets(of: $0.range) }, [0..<0, 1..<1, 2..<2])
XCTAssertEqual(
s2.ranges(of: try Regex("a*?")).map(s2.offsets(of:)), [0..<0, 1..<1, 2..<2])
}

func testSwitches() {
Expand Down