Skip to content

Commit

Permalink
Update to tree-sitter 0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Sep 11, 2024
1 parent 9369bb9 commit 42ee1b3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.library(name: "SwiftTreeSitterLayer", targets: ["SwiftTreeSitterLayer"]),
],
dependencies: [
.package(url: "https://github.com/tree-sitter/tree-sitter", .upToNextMinor(from: "0.20.9")),
.package(url: "https://github.com/tree-sitter/tree-sitter", .upToNextMinor(from: "0.23.0")),
],
targets: [
.target(
Expand Down
13 changes: 7 additions & 6 deletions Sources/SwiftTreeSitter/Language.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import Foundation
import TreeSitter

public struct Language: Sendable {
private let tsLanguagePointer: SendableUnsafePointer<TSLanguage>
private let tsLanguagePointer: SendableOpaquePointer

/// Creates an instance.
///
/// - Parameters:
/// - language: The TSLanguage instance to wrap.
public init(language: UnsafePointer<TSLanguage>) {
public init(language: OpaquePointer) {
self.init(language)
}

/// Creates a new instance by wrapping a pointer to a tree sitter parser.
///
/// - Parameters:
/// - language: The TSLanguage instance to wrap.
public init(_ language: UnsafePointer<TSLanguage>) {
self.tsLanguagePointer = SendableUnsafePointer(language)
public init(_ language: OpaquePointer) {
self.tsLanguagePointer = SendableOpaquePointer(language)
}

public var tsLanguage: UnsafePointer<TSLanguage> {
public var tsLanguage: OpaquePointer {
tsLanguagePointer.pointer
}
}
Expand Down Expand Up @@ -66,7 +66,8 @@ extension Language {
}
}

extension Language: Hashable {}
extension Language: Hashable {
}

extension Language {
/// Construct a query object from data in a file.
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftTreeSitter/LanguageConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct LanguageConfiguration: Sendable {

#if !os(WASI)
extension LanguageConfiguration {
public init(_ tsLanguage: UnsafePointer<TSLanguage>, name: String, queries: [Query.Definition: Query]) {
public init(_ tsLanguage: OpaquePointer, name: String, queries: [Query.Definition: Query]) {
self.init(Language(tsLanguage), name: name, queries: queries)
}

Expand All @@ -55,7 +55,7 @@ extension LanguageConfiguration {
/// Create a configuration with a name assumed to match a bundle.
///
/// The bundle must be nested within resources and follow the pattern `TreeSitter\(name)_TreeSitter\(name)`.
public init(_ tsLanguage: UnsafePointer<TSLanguage>, name: String) throws {
public init(_ tsLanguage: OpaquePointer, name: String) throws {
try self.init(Language(tsLanguage), name: name)
}

Expand All @@ -66,7 +66,7 @@ extension LanguageConfiguration {
self.init(language, name: name, queries: queries)
}

public init(_ tsLanguage: UnsafePointer<TSLanguage>, name: String, bundleName: String) throws {
public init(_ tsLanguage: OpaquePointer, name: String, bundleName: String) throws {
try self.init(Language(tsLanguage), name: name, bundleName: bundleName)
}

Expand All @@ -76,7 +76,7 @@ extension LanguageConfiguration {
self.init(language, name: name, queries: queries)
}

public init(_ tsLanguage: UnsafePointer<TSLanguage>, name: String, queriesURL: URL) throws {
public init(_ tsLanguage: OpaquePointer, name: String, queriesURL: URL) throws {
try self.init(Language(tsLanguage), name: name, queriesURL: queriesURL)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Parser {
try setLanguage(language.tsLanguage)
}

public func setLanguage(_ language: UnsafePointer<TSLanguage>) throws {
public func setLanguage(_ language: OpaquePointer) throws {
let success = ts_parser_set_language(internalParser, language)

if success == false {
Expand Down
12 changes: 2 additions & 10 deletions Sources/SwiftTreeSitter/SendableTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@ struct SendableOpaquePointer: @unchecked Sendable {
}
}

struct SendableUnsafePointer<T>: @unchecked Sendable {
let pointer: UnsafePointer<T>

init(_ pointer: UnsafePointer<T>) {
self.pointer = pointer
}
}

extension SendableUnsafePointer: Equatable {}
extension SendableUnsafePointer: Hashable {}
extension SendableOpaquePointer: Equatable {}
extension SendableOpaquePointer: Hashable {}

0 comments on commit 42ee1b3

Please sign in to comment.