Skip to content

Commit

Permalink
Replace git submodule with package dependency for tree-sitter integra…
Browse files Browse the repository at this point in the history
…tion (#23)

* include tree-sitter using package dependency

* update version constraints

* Configure supported platforms to system default for compatibility with the tree-sitter library.
  • Loading branch information
yeatse authored Apr 13, 2024
1 parent b01904a commit b39502d
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "tree-sitter"]
path = tree-sitter
url = https://github.com/tree-sitter/tree-sitter.git
[submodule "tree-sitter-swift"]
path = tree-sitter-swift
url = https://github.com/alex-pinkus/tree-sitter-swift
Expand Down
21 changes: 6 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@ let settings: [SwiftSetting] = [

let package = Package(
name: "SwiftTreeSitter",
platforms: [
.macOS(.v10_13),
.iOS(.v12),
.tvOS(.v12),
.macCatalyst(.v13),
.watchOS(.v4)
],
products: [
.library(name: "SwiftTreeSitter", targets: ["SwiftTreeSitter"]),
.library(name: "SwiftTreeSitterLayer", targets: ["SwiftTreeSitterLayer"]),
],
dependencies: [
.package(url: "https://github.com/tree-sitter/tree-sitter", .upToNextMinor(from: "0.20.9")),
],
targets: [
.target(
name: "tree-sitter",
path: "tree-sitter/lib",
sources: ["src/lib.c"],
publicHeadersPath: "include",
cSettings: [.headerSearchPath("src/")]
),
.target(
name: "TestTreeSitterSwift",
path: "tree-sitter-swift",
Expand All @@ -36,7 +25,9 @@ let package = Package(
),
.target(
name: "SwiftTreeSitter",
dependencies: ["tree-sitter"],
dependencies: [
.product(name: "TreeSitter", package: "tree-sitter"),
],
swiftSettings: settings
),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Encoding+Helpers.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

extension String.Encoding {
var internalEncoding: TSInputEncoding? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

final class Input {
typealias Buffer = UnsafeMutableBufferPointer<Int8>
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/InputEdit.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

/// Structure that describes a change to the text content.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Language.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public struct Language: Sendable {
private let tsLanguagePointer: SendableUnsafePointer<TSLanguage>
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/LanguageConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

import tree_sitter
import TreeSitter

/// A structure that holds a language name and its assoicated queries.
public struct LanguageData: Sendable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

public struct Node {
let internalNode: TSNode
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftTreeSitter/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

enum ParserError: Error {
case languageIncompatible
Expand Down Expand Up @@ -54,7 +54,7 @@ extension Parser {
var count: UInt32 = 0
let tsRangePointer = ts_parser_included_ranges(internalParser, &count)

let tsRangeBuffer = UnsafeBufferPointer<tree_sitter.TSRange>(start: tsRangePointer, count: Int(count))
let tsRangeBuffer = UnsafeBufferPointer<TreeSitter.TSRange>(start: tsRangePointer, count: Int(count))

return tsRangeBuffer.map({ TSRange(internalRange: $0) })
}
Expand All @@ -64,7 +64,7 @@ extension Parser {
ranges.withUnsafeBytes { bufferPtr in
let count = newValue.count

guard let ptr = bufferPtr.baseAddress?.bindMemory(to: tree_sitter.TSRange.self, capacity: count) else {
guard let ptr = bufferPtr.baseAddress?.bindMemory(to: TreeSitter.TSRange.self, capacity: count) else {
preconditionFailure("unable to convert pointer")
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

public struct Point: Codable, Sendable {
public let row: UInt32
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Predicate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public enum QueryPredicateStep: Hashable, Sendable {
case done
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Query.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public enum QueryError: Error {
case none
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftTreeSitter/TSRange.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public struct TSRange: Codable, Hashable, Sendable {
public let points: Range<Point>
Expand All @@ -10,12 +10,12 @@ public struct TSRange: Codable, Hashable, Sendable {
self.bytes = bytes
}

init(internalRange range: tree_sitter.TSRange) {
init(internalRange range: TreeSitter.TSRange) {
self.bytes = range.start_byte..<range.end_byte
self.points = Point(internalPoint: range.start_point)..<Point(internalPoint: range.end_point)
}

init(potentiallyInvalidRange range: tree_sitter.TSRange) {
init(potentiallyInvalidRange range: TreeSitter.TSRange) {
self.bytes = range.start_byte..<range.end_byte

let start = Point(internalPoint: range.start_point)
Expand All @@ -25,7 +25,7 @@ public struct TSRange: Codable, Hashable, Sendable {
self.points = start..<safeEnd
}

var internalRange: tree_sitter.TSRange {
var internalRange: TreeSitter.TSRange {
return .init(start_point: points.lowerBound.internalPoint,
end_point: points.upperBound.internalPoint,
start_byte: bytes.lowerBound,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Tree.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tree_sitter
import TreeSitter

/// An immutable tree-sitter tree structure.
public final class Tree: Sendable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/TreeCursor.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public class TreeCursor {
private var internalCursor: TSTreeCursor
Expand Down
1 change: 0 additions & 1 deletion tree-sitter
Submodule tree-sitter deleted from 98be22

0 comments on commit b39502d

Please sign in to comment.