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 @@ -2332,6 +2332,14 @@ extension RegexTests {
2332
2332
$0. as ( AST . Atom. self) !. as ( AST . Atom. Scalar. self) !. location
2333
2333
} )
2334
2334
2335
+ rangeTest ( #"\u{ 65 58 }"# , range ( 5 ..< 7 ) , at: {
2336
+ $0. as ( AST . Atom. self) !. as ( AST . Atom. ScalarSequence. self) !. scalars [ 0 ] . location
2337
+ } )
2338
+
2339
+ rangeTest ( #"\u{ 65 58 }"# , range ( 8 ..< 10 ) , at: {
2340
+ $0. as ( AST . Atom. self) !. as ( AST . Atom. ScalarSequence. self) !. scalars [ 1 ] . location
2341
+ } )
2342
+
2335
2343
// MARK: References
2336
2344
2337
2345
rangeTest ( #"\k<a+2>"# , range ( 3 ..< 6 ) , at: {
You can’t perform that action at this time.
0 commit comments