@@ -21,6 +21,16 @@ API convention:
2121- eat() and tryEat() is still used by the parser as a character-by-character interface
2222*/
2323
24+ extension Error {
25+ func addingLocation( _ loc: Range < Source . Position > ) -> Error {
26+ // If we're already a LocatedError, don't change the location.
27+ if self is _LocatedErrorProtocol {
28+ return self
29+ }
30+ return Source . LocatedError< Self> ( self , loc)
31+ }
32+ }
33+
2434extension Source {
2535 // MARK: - recordLoc
2636
@@ -51,12 +61,8 @@ extension Source {
5161 do {
5262 guard let result = try f ( & self ) else { return nil }
5363 return Located ( result, start..< currentPosition)
54- } catch let e as Source . LocatedError < ParseError > {
55- throw e
56- } catch let e as ParseError {
57- throw LocatedError ( e, start..< currentPosition)
58- } catch {
59- fatalError ( " FIXME: Let's not keep the boxed existential... " )
64+ } catch let e {
65+ throw e. addingLocation ( start..< currentPosition)
6066 }
6167 }
6268
@@ -1841,6 +1847,9 @@ extension Source {
18411847 }
18421848 throw Unreachable ( " TODO: reason " )
18431849
1850+ case " ( " where !customCC:
1851+ throw Unreachable ( " Should have lexed a group or group-like atom " )
1852+
18441853 // (sometimes) special metacharacters
18451854 case " . " : return customCC ? . char( " . " ) : . any
18461855 case " ^ " : return customCC ? . char( " ^ " ) : . startOfLine
0 commit comments