@@ -158,7 +158,7 @@ fileprivate struct SourceLocationDirectiveArguments {
158
158
/// vice-versa. The ``AbsolutePosition``s must be originating from nodes that are
159
159
/// part of the same tree that was used to initialize this class.
160
160
public final class SourceLocationConverter {
161
- private let file : String
161
+ private let fileName : String
162
162
/// The source of the file, modeled as data so it can contain invalid UTF-8.
163
163
private let source : [ UInt8 ]
164
164
/// Array of lines and the position at the start of the line.
@@ -183,11 +183,11 @@ public final class SourceLocationConverter {
183
183
/// name that contains string interpolation.
184
184
///
185
185
/// - Parameters:
186
- /// - file : The file path associated with the syntax tree.
186
+ /// - fileName : The file path associated with the syntax tree.
187
187
/// - tree: The root of the syntax tree to convert positions to line/columns for.
188
- public init ( file : String , tree: some SyntaxProtocol ) {
188
+ public init ( fileName : String , tree: some SyntaxProtocol ) {
189
189
precondition ( tree. parent == nil , " SourceLocationConverter must be passed the root of the syntax tree " )
190
- self . file = file
190
+ self . fileName = fileName
191
191
self . source = tree. syntaxTextBytes
192
192
( self . lines, endOfFile) = computeLines ( tree: Syntax ( tree) )
193
193
precondition ( tree. totalLength. utf8Length == endOfFile. utf8Offset)
@@ -206,16 +206,33 @@ public final class SourceLocationConverter {
206
206
}
207
207
}
208
208
209
+ /// Create a new ``SourceLocationConverter`` to convert between ``AbsolutePosition``
210
+ /// and ``SourceLocation`` in a syntax tree.
211
+ ///
212
+ /// This initializer is deprecated. Please use `init(fileName:source:)` instead.
213
+ ///
214
+ /// This converter ignores any malformed `#sourceLocation` directives, e.g.
215
+ /// `#sourceLocation` directives with a non-decimal line number or with a file
216
+ /// name that contains string interpolation.
217
+ ///
218
+ /// - Parameters:
219
+ /// - file: The file path associated with the syntax tree.
220
+ /// - tree: The root of the syntax tree to convert positions to line/columns for.
221
+ @available ( * , deprecated, message: " Use init(fileName:tree:) instead " )
222
+ public convenience init ( file: String , tree: SyntaxProtocol ) {
223
+ self . init ( fileName: file, tree: tree)
224
+ }
225
+
209
226
/// - Important: This initializer does not take `#sourceLocation` directives
210
227
/// into account and doesn’t produce `presumedFile` and
211
228
/// `presumedLine`.
212
229
///
213
230
/// - Parameters:
214
231
/// - file: The file path associated with the syntax tree.
215
232
/// - source: The source code to convert positions to line/columns for.
216
- @available ( * , deprecated, message: " Use init(file :tree:) instead " )
233
+ @available ( * , deprecated, message: " Use init(fileName :tree:) instead " )
217
234
public init ( file: String , source: String ) {
218
- self . file = file
235
+ self . fileName = file
219
236
self . source = Array ( source. utf8)
220
237
( self . lines, endOfFile) = self . source. withUnsafeBufferPointer { buf in
221
238
return computeLines ( SyntaxText ( buffer: buf) )
@@ -285,7 +302,7 @@ public final class SourceLocationConverter {
285
302
// Clamp the given position to the end of file if needed.
286
303
let pos = min ( position, endOfFile)
287
304
if pos. utf8Offset < 0 {
288
- return SourceLocation ( line: 1 , column: 1 , offset: 0 , file: self . file )
305
+ return SourceLocation ( line: 1 , column: 1 , offset: 0 , file: self . fileName )
289
306
}
290
307
291
308
precondition ( !lines. isEmpty)
@@ -318,7 +335,7 @@ public final class SourceLocationConverter {
318
335
line: line,
319
336
column: column,
320
337
offset: pos. utf8Offset,
321
- file: self . file
338
+ file: self . fileName
322
339
)
323
340
}
324
341
0 commit comments