77
88public struct Diagnostic : Error {
99 public let message : String
10- public let range : SourceLocation
10+ public let location : SourceLocation
1111 public let suggestion : Suggestion ?
1212
1313 public enum Suggestion : Sendable {
@@ -17,21 +17,21 @@ public struct Diagnostic: Error {
1717
1818 public init (
1919 _ message: String ,
20- at range : SourceLocation ,
20+ at location : SourceLocation ,
2121 suggestion: Suggestion ? = nil
2222 ) {
2323 self . message = message
24- self . range = range
24+ self . location = location
2525 self . suggestion = suggestion
2626 }
2727
2828 init (
2929 expected: TypeNameSyntax ,
3030 got actual: TypeNameSyntax ,
31- at range : SourceLocation
31+ at location : SourceLocation
3232 ) {
3333 self . message = " Incorrect type, expected ' \( expected. name) ' got ' \( actual. name) ' "
34- self . range = range
34+ self . location = location
3535 self . suggestion = . replace( expected. name. description)
3636 }
3737
@@ -45,84 +45,84 @@ extension Diagnostic {
4545 static func incorrectType(
4646 _ actual: TypeNameSyntax ,
4747 expected: TypeNameSyntax ,
48- at range : SourceLocation
48+ at location : SourceLocation
4949 ) -> Diagnostic {
5050 Diagnostic (
5151 " Incorrect type, expected ' \( expected. name) ' got ' \( actual. name) ' " ,
52- at: range ,
52+ at: location ,
5353 suggestion: . replace( expected. name. description)
5454 )
5555 }
5656
5757 static func expectedNumber(
5858 _ actual: TypeNameSyntax ,
59- at range : SourceLocation
59+ at location : SourceLocation
6060 ) -> Diagnostic {
6161 Diagnostic (
6262 " Incorrect type, expected number got ' \( actual. name) ' " ,
63- at: range
63+ at: location
6464 )
6565 }
6666
6767 static func ambiguous(
6868 _ identifier: Substring ,
69- at range : SourceLocation
69+ at location : SourceLocation
7070 ) -> Diagnostic {
7171 Diagnostic (
7272 " ' \( identifier) ' is ambigious in the current context " ,
73- at: range
73+ at: location
7474 )
7575 }
7676
7777 static func tableDoesNotExist( _ identifier: IdentifierSyntax ) -> Diagnostic {
7878 Diagnostic (
7979 " Table ' \( identifier) ' does not exist " ,
80- at: identifier. range
80+ at: identifier. location
8181 )
8282 }
8383
8484 static func tableAlreadyExists( _ identifier: IdentifierSyntax ) -> Diagnostic {
8585 Diagnostic (
8686 " Table ' \( identifier) ' already exists " ,
87- at: identifier. range
87+ at: identifier. location
8888 )
8989 }
9090
9191 static func columnDoesNotExist( _ identifier: IdentifierSyntax ) -> Diagnostic {
9292 Diagnostic (
9393 " Column ' \( identifier) ' does not exist " ,
94- at: identifier. range
94+ at: identifier. location
9595 )
9696 }
9797
98- static func nameRequired( at range : SourceLocation ) -> Diagnostic {
98+ static func nameRequired( at location : SourceLocation ) -> Diagnostic {
9999 return Diagnostic (
100100 " Name required, add via 'AS' " ,
101- at: range ,
101+ at: location ,
102102 suggestion: . append( " AS \( Diagnostic . placeholder ( name: " name " ) ) " )
103103 )
104104 }
105105
106106 static func unexpectedToken(
107107 of kind: Token . Kind ,
108108 expected: Token . Kind ? = nil ,
109- at range : SourceLocation
109+ at location : SourceLocation
110110 ) -> Diagnostic {
111111 if let expected {
112- return Diagnostic ( " Unexpected token \( kind) , expected ' \( expected) ' " , at: range )
112+ return Diagnostic ( " Unexpected token \( kind) , expected ' \( expected) ' " , at: location )
113113 } else {
114- return Diagnostic ( " Unexpected token \( kind) " , at: range )
114+ return Diagnostic ( " Unexpected token \( kind) " , at: location )
115115 }
116116 }
117117
118118 static func unexpected( token: Token ) -> Diagnostic {
119- return unexpectedToken ( of: token. kind, at: token. range )
119+ return unexpectedToken ( of: token. kind, at: token. location )
120120 }
121121
122122 static func unexpectedToken(
123123 of kind: Token . Kind ,
124124 expectedAnyOf expected: Token . Kind ... ,
125- at range : SourceLocation
125+ at location : SourceLocation
126126 ) -> Diagnostic {
127127 var expectedMessage = " "
128128 for (index, kind) in expected. enumerated ( ) {
@@ -135,28 +135,28 @@ extension Diagnostic {
135135 expectedMessage += " ' \( kind) ' "
136136 }
137137
138- return Diagnostic ( " Unexpected token \( kind) , expected any of \( expected) " , at: range )
138+ return Diagnostic ( " Unexpected token \( kind) , expected any of \( expected) " , at: location )
139139 }
140140
141141 static func illegalStatement(
142142 in context: String ,
143- at range : SourceLocation
143+ at location : SourceLocation
144144 ) -> Diagnostic {
145- return Diagnostic ( " Statement is not allowed in \( context) " , at: range )
145+ return Diagnostic ( " Statement is not allowed in \( context) " , at: location )
146146 }
147147
148148 static func alreadyHasPrimaryKey(
149149 _ table: Substring ,
150- at range : SourceLocation
150+ at location : SourceLocation
151151 ) -> Diagnostic {
152- return Diagnostic ( " Table ' \( table) ' already has a primary key " , at: range )
152+ return Diagnostic ( " Table ' \( table) ' already has a primary key " , at: location )
153153 }
154154
155155 static func unableToUnify(
156156 _ t1: Type ,
157157 with t2: Type ,
158- at range : SourceLocation
158+ at location : SourceLocation
159159 ) -> Diagnostic {
160- return Diagnostic ( " Unable to unify types ' \( t1) ' and ' \( t2) ' " , at: range )
160+ return Diagnostic ( " Unable to unify types ' \( t1) ' and ' \( t2) ' " , at: location )
161161 }
162162}
0 commit comments