Add BlobLineMap key

Changed files
+6 -3
Sources
PterodactylBuild
PterodactylSyntax
+1
Sources/PterodactylBuild/FXValue+Conformances.swift
···
extension SyntaxTree: FXValue {}
extension Token: FXValue {}
extension Graph: FXValue where Vertex: Codable {}
+
extension LineMap: FXValue {}
extension String: @retroactive FXValue {}
extension Set: @retroactive FXValue where Element: Codable {}
+5 -3
Sources/PterodactylSyntax/LineMap.swift
···
import Algorithms
import Foundation
-
public struct LineMap: Codable {
-
private var utf16LineOffsets: [Int] = [0]
+
public struct LineMap: Codable, Sendable {
+
private let utf16LineOffsets: [Int]
public init(source: String) {
+
var offsets: [Int] = []
for idx in source.indices {
let c = source[idx]
if c == "\n" || c == "\r\n" || c == "\r" {
let next = source.index(after: idx)
let utf16Offset = next.utf16Offset(in: source)
-
utf16LineOffsets.append(utf16Offset)
+
offsets.append(utf16Offset)
}
}
+
self.utf16LineOffsets = offsets
}
public func location(at utf16Offset: Int) -> (line: Int, column: Int) {