File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Sources/_MatchingEngine/Regex/Parse Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,14 @@ extension Source {
140
140
return result
141
141
}
142
142
143
+ /// Attempt to eat the given character, returning its source location if
144
+ /// successful, `nil` otherwise.
145
+ mutating func tryEatWithLoc( _ c: Character ) -> SourceLocation ? {
146
+ let start = currentPosition
147
+ guard tryEat ( c) else { return nil }
148
+ return . init( start ..< currentPosition)
149
+ }
150
+
143
151
/// Throws an expected ASCII character error if not matched
144
152
mutating func expectASCII( ) throws -> Located < Character > {
145
153
try recordLoc { src in
@@ -1475,15 +1483,13 @@ extension Source {
1475
1483
) throws -> ( dashLoc: SourceLocation , AST . Atom ) ? {
1476
1484
// Make sure we don't have a binary operator e.g '--', and the '-' is not
1477
1485
// ending the custom character class (in which case it is literal).
1478
- let start = currentPosition
1479
- guard peekCCBinOp ( ) == nil && !starts( with: " -] " ) && tryEat ( " - " ) else {
1480
- return nil
1481
- }
1482
- let dashLoc = Location ( start ..< currentPosition)
1483
- guard let end = try lexAtom ( context: context) else {
1486
+ guard peekCCBinOp ( ) == nil , !starts( with: " -] " ) ,
1487
+ let dash = tryEatWithLoc ( " - " ) ,
1488
+ let end = try lexAtom ( context: context)
1489
+ else {
1484
1490
return nil
1485
1491
}
1486
- return ( dashLoc , end)
1492
+ return ( dash , end)
1487
1493
}
1488
1494
}
1489
1495
You can’t perform that action at this time.
0 commit comments