@@ -21,6 +21,16 @@ API convention:
21
21
- eat() and tryEat() is still used by the parser as a character-by-character interface
22
22
*/
23
23
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
+
24
34
extension Source {
25
35
// MARK: - recordLoc
26
36
@@ -51,12 +61,8 @@ extension Source {
51
61
do {
52
62
guard let result = try f ( & self ) else { return nil }
53
63
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)
60
66
}
61
67
}
62
68
@@ -1841,6 +1847,9 @@ extension Source {
1841
1847
}
1842
1848
throw Unreachable ( " TODO: reason " )
1843
1849
1850
+ case " ( " where !customCC:
1851
+ throw Unreachable ( " Should have lexed a group or group-like atom " )
1852
+
1844
1853
// (sometimes) special metacharacters
1845
1854
case " . " : return customCC ? . char( " . " ) : . any
1846
1855
case " ^ " : return customCC ? . char( " ^ " ) : . startOfLine
0 commit comments