Commit d1aa698
committed
Drop arrays and unzip tuples for quantified captures.
To bridge the typing gap between regex literals and regex builder, this patch introduces the following changes:
1. Repeating quantifiers no longer produce an array capture. Instead, produce an optional capture when the lower bound is `0`, otherwise an atom capture. After matching, this capture corresponds to the last occurrence in the match. A history-saving quantifier variant will be introduced at a later time.
2. Applying a quantifier on a tuple-capturing regex will map quantification onto every tuple element, resulting in a tuple of quantified captures (unzipped).
-----
```swift
let literal = /a((b)(b)+)*(c)+(d)?/
// 0 ^~~~~~~~~~~~~~~~
// 1 ^~~~~~
// 2 ^~~
// 3 ^~~
// 4 ^~~
// 5 ^~~
// => Regex<(Substring, Substring?, Substring?, Substring?, Substring, Substring?)>
// Equivalent regex using regex builder:
let dsl = Regex { // 0
"a"
zeroOrMore {
capture { // 1
capture { // 2
"b"
}
oneOrMore {
capture { // 3
"b"
}
}
}
}
oneOrMore {
capture { // 4
"c"
}
}
optionally {
capture { // 5
"d"
}
}
}
// => Regex<(Substring, Substring?, Substring?, Substring?, Substring, Substring?)>
```1 parent ff635c6 commit d1aa698
File tree
7 files changed
+208
-198
lines changed- Sources
- VariadicsGenerator
- _MatchingEngine/Regex/Parse
- _StringProcessing/RegexDSL
- Tests/RegexTests
7 files changed
+208
-198
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
298 | | - | |
| 297 | + | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
| 323 | + | |
| 324 | + | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| |||
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
116 | | - | |
117 | | - | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
127 | 124 | | |
128 | 125 | | |
129 | 126 | | |
| |||
0 commit comments