Skip to content

Commit ef7264c

Browse files
committed
more range renames
1 parent 487bc84 commit ef7264c

20 files changed

Lines changed: 365 additions & 366 deletions

Sources/Compiler/Compiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public struct Compiler {
5151

5252
for stmtSyntax in stmtSyntaxes {
5353
if !stmtSyntax.accept(visitor: &validator) {
54-
diagnostics.add(.illegalStatement(in: context, at: stmtSyntax.range))
54+
diagnostics.add(.illegalStatement(in: context, at: stmtSyntax.location))
5555
}
5656

5757
guard let (stmt, diags) = stmtSyntax.accept(visitor: &compiler) else { continue }

Sources/Compiler/Diagnostic.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public 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
}

Sources/Compiler/DiagnosticReporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct StdoutDiagnosticReporter: DiagnosticReporter {
1313
public init() {}
1414

1515
public func report(diagnostic: Diagnostic, source: String, fileName: String) {
16-
let source = source[diagnostic.range.range]
16+
let source = source[diagnostic.location.range]
1717

1818
print("""
1919
\(source)

Sources/Compiler/Diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public struct Diagnostics {
4040

4141
public mutating func trying<Output>(
4242
_ action: () throws -> Output,
43-
at range: SourceLocation
43+
at location: SourceLocation
4444
) -> Output? {
4545
do {
4646
return try action()
4747
} catch {
48-
add(.init("\(error)", at: range))
48+
add(.init("\(error)", at: location))
4949
return nil
5050
}
5151
}

Sources/Compiler/Gen/Rewriter.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ struct Rewriter {
2525
mutating func removeNonSql<S: StmtSyntax>(_ stmt: S, in source: String) -> String {
2626
let rangesToRemove = stmt.accept(visitor: &self)
2727

28-
guard !rangesToRemove.isEmpty else { return "\(source[stmt.range.range]);" }
28+
guard !rangesToRemove.isEmpty else { return "\(source[stmt.location.range]);" }
2929

3030
var final = ""
31-
var start = stmt.range.lowerBound
31+
var start = stmt.location.lowerBound
3232

3333
// Remove in reverse so the range start does not change.
3434
for range in rangesToRemove.sorted(by: { $0.lowerBound < $1.lowerBound }) {
3535
final.append(contentsOf: source[start..<range.lowerBound])
3636
start = range.upperBound
3737
}
3838

39-
if start < stmt.range.upperBound {
40-
final.append(contentsOf: source[start..<stmt.range.upperBound])
39+
if start < stmt.location.upperBound {
40+
final.append(contentsOf: source[start..<stmt.location.upperBound])
4141
}
4242

4343
return "\(final.trimmingCharacters(in: .whitespaces));"
@@ -61,13 +61,13 @@ struct Rewriter {
6161
let rowRanges: [(Range<Substring.Index>, Parameter<String>)] = parameters
6262
.compactMap { param -> [(Range<Substring.Index>, Parameter<String>)]? in
6363
guard case .row = param.type else { return nil }
64-
return param.ranges.map { ($0.range, param) }
64+
return param.locations.map { ($0.range, param) }
6565
}
6666
.flatMap(\.self)
6767
.sorted { $0.0.lowerBound < $1.0.lowerBound }
6868

6969
guard !rowRanges.isEmpty else {
70-
return [.text(source[stmt.range.range])]
70+
return [.text(source[stmt.location.range])]
7171
}
7272

7373
guard rangesToRemove.isEmpty else {
@@ -83,7 +83,7 @@ struct Rewriter {
8383
}
8484

8585
var segments: [SourceSegment] = []
86-
var startIndex = stmt.range.lowerBound
86+
var startIndex = stmt.location.lowerBound
8787

8888
for (rowRange, param) in rowRanges {
8989
let textRange = startIndex..<rowRange.lowerBound
@@ -95,8 +95,8 @@ struct Rewriter {
9595

9696
// If the last range wasnt to the end of the string
9797
// then make sure to append the rest
98-
if startIndex < stmt.range.upperBound {
99-
let textRange = startIndex..<stmt.range.upperBound
98+
if startIndex < stmt.location.upperBound {
99+
let textRange = startIndex..<stmt.location.upperBound
100100
let text = source[textRange]
101101
segments.append(.text(text))
102102
}
@@ -109,15 +109,15 @@ extension Rewriter: StmtSyntaxVisitor {
109109
func visit(_ stmt: borrowing CreateTableStmtSyntax) -> [Range<Substring.Index>] {
110110
switch stmt.kind {
111111
case .columns(let columns):
112-
return columns.values.compactMap { $0.type.alias?.range.range }
112+
return columns.values.compactMap { $0.type.alias?.location.range }
113113
case .select:
114114
return []
115115
}
116116
}
117117

118118
func visit(_ stmt: borrowing AlterTableStmtSyntax) -> [Range<Substring.Index>] {
119119
return switch stmt.kind {
120-
case .addColumn(let c): c.type.alias.map { [$0.range.range] } ?? []
120+
case .addColumn(let c): c.type.alias.map { [$0.location.range] } ?? []
121121
default: []
122122
}
123123
}
@@ -134,7 +134,7 @@ extension Rewriter: StmtSyntaxVisitor {
134134

135135
func visit(_ stmt: borrowing QueryDefinitionStmtSyntax) -> [Range<Substring.Index>] {
136136
// Remove the `DEFINE QUERY name AS`
137-
return [stmt.range.lowerBound..<stmt.statement.range.lowerBound]
137+
return [stmt.location.lowerBound..<stmt.statement.location.lowerBound]
138138
}
139139

140140
func visit(_ stmt: borrowing PragmaStmt) -> [Range<Substring.Index>] { [] }
@@ -152,8 +152,8 @@ extension Rewriter: StmtSyntaxVisitor {
152152
func visit(_ stmt: borrowing CreateVirtualTableStmtSyntax) -> [Range<Substring.Index>] {
153153
return stmt.arguments.flatMap { argument -> [Range<Substring.Index>] in
154154
guard case let .fts5Column(_, typeName, notNull, _) = argument else { return [] }
155-
if let typeName, let notNull { return [typeName.range.range, notNull.range] }
156-
if let typeName { return [typeName.range.range] }
155+
if let typeName, let notNull { return [typeName.location.range, notNull.range] }
156+
if let typeName { return [typeName.location.range] }
157157
if let notNull { return [notNull.range] }
158158
return []
159159
}

Sources/Compiler/Parse/Lexer.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Lexer {
4141
private var eof: Token {
4242
return Token(
4343
kind: .eof,
44-
range: SourceLocation(
44+
location: SourceLocation(
4545
range: source.endIndex..<source.endIndex
4646
)
4747
)
@@ -87,9 +87,9 @@ struct Lexer {
8787
advance()
8888
if self.current == ">" {
8989
advance()
90-
return Token(kind: .doubleArrow, range: location(from: currentIndex, to: peekIndex))
90+
return Token(kind: .doubleArrow, location: location(from: currentIndex, to: peekIndex))
9191
} else {
92-
return Token(kind: .arrow, range: location(from: currentIndex, to: peekIndex))
92+
return Token(kind: .arrow, location: location(from: currentIndex, to: peekIndex))
9393
}
9494
case ("*", _): return consumeSingle(of: .star)
9595
case ("=", _): return consumeSingle(of: .equal)
@@ -136,7 +136,7 @@ struct Lexer {
136136
}
137137

138138
let location = location(from: start, to: currentIndex)
139-
return Token(kind: Token.Kind(word: source[location.range]), range: location)
139+
return Token(kind: Token.Kind(word: source[location.range]), location: location)
140140
}
141141

142142
private mutating func parseNumber() -> Token {
@@ -166,7 +166,7 @@ struct Lexer {
166166
.int(integer(from: string, at: location.range))
167167
}
168168

169-
return Token(kind: kind, range: location)
169+
return Token(kind: kind, location: location)
170170
}
171171

172172
private mutating func scientificNotation(
@@ -216,7 +216,7 @@ struct Lexer {
216216
let value = mantissa * pow(10, exponent)
217217
return Token(
218218
kind: .double(value),
219-
range: location(from: mantissaRange.lowerBound, to: exponentRange.upperBound)
219+
location: location(from: mantissaRange.lowerBound, to: exponentRange.upperBound)
220220
)
221221
}
222222

@@ -243,10 +243,10 @@ struct Lexer {
243243

244244
guard let value = Int(source[numberRange], radix: 16) else {
245245
diagnostics.add(.init("Invalid hex number", at: location))
246-
return Token(kind: .hex(0), range: location)
246+
return Token(kind: .hex(0), location: location)
247247
}
248248

249-
return Token(kind: .hex(value), range: location)
249+
return Token(kind: .hex(value), location: location)
250250
}
251251

252252
private mutating func parseString() -> Token {
@@ -266,7 +266,7 @@ struct Lexer {
266266
diagnostics.add(.init("Unterminated string", at: location(from: start, to: currentIndex)))
267267
}
268268

269-
return Token(kind: .string(source[stringRange]), range: location(from: tokenStart, to: currentIndex))
269+
return Token(kind: .string(source[stringRange]), location: location(from: tokenStart, to: currentIndex))
270270
}
271271

272272
private mutating func skipWhitespace() {
@@ -278,14 +278,14 @@ struct Lexer {
278278
private mutating func consumeSingle(of kind: Token.Kind) -> Token {
279279
let start = currentIndex
280280
advance()
281-
return Token(kind: kind, range: location(from: start, to: currentIndex))
281+
return Token(kind: kind, location: location(from: start, to: currentIndex))
282282
}
283283

284284
private mutating func consumeDouble(of kind: Token.Kind) -> Token {
285285
let start = currentIndex
286286
advance()
287287
advance()
288-
return Token(kind: kind, range: location(from: start, to: currentIndex))
288+
return Token(kind: kind, location: location(from: start, to: currentIndex))
289289
}
290290

291291
private mutating func integer<S: StringProtocol>(

0 commit comments

Comments
 (0)