File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Sources/_RegexParser/Regex/Parse Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -503,13 +503,22 @@ extension Source {
503
503
private mutating func lexUntil(
504
504
_ predicate: ( inout Source ) throws -> Bool
505
505
) rethrows -> Located < String > {
506
+ // We track locations outside of recordLoc, as the predicate may advance the
507
+ // input when we hit the end, and we don't want that to affect the location
508
+ // of what was lexed in the `result`. We still want the recordLoc call to
509
+ // attach locations to any thrown errors though.
510
+ // TODO: We should find a better way of doing this, `lexUntil` seems full
511
+ // of footguns.
512
+ let start = currentPosition
513
+ var end = currentPosition
514
+ var result = " "
506
515
try recordLoc { src in
507
- var result = " "
508
516
while try ! predicate( & src) {
509
517
result. append ( src. eat ( ) )
518
+ end = src. currentPosition
510
519
}
511
- return result
512
520
}
521
+ return . init( result, start ..< end)
513
522
}
514
523
515
524
private mutating func lexUntil( eating end: String ) throws -> Located < String > {
Original file line number Diff line number Diff line change @@ -2195,6 +2195,14 @@ extension RegexTests {
2195
2195
$0. as ( AST . Atom. self) !. as ( AST . Atom. Scalar. self) !. location
2196
2196
} )
2197
2197
2198
+ rangeTest ( #"\u{ 65 58 }"# , range ( 5 ..< 7 ) , at: {
2199
+ $0. as ( AST . Atom. self) !. as ( AST . Atom. ScalarSequence. self) !. scalars [ 0 ] . location
2200
+ } )
2201
+
2202
+ rangeTest ( #"\u{ 65 58 }"# , range ( 8 ..< 10 ) , at: {
2203
+ $0. as ( AST . Atom. self) !. as ( AST . Atom. ScalarSequence. self) !. scalars [ 1 ] . location
2204
+ } )
2205
+
2198
2206
// MARK: References
2199
2207
2200
2208
rangeTest ( #"\k<a+2>"# , range ( 3 ..< 6 ) , at: {
You can’t perform that action at this time.
0 commit comments