Skip to content

Commit

Permalink
ok this is kinda funny
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 30, 2024
1 parent b296bb0 commit b4f306c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package org.polyvariant.treesitter4s.lowlevel
import com.sun.jna.*
import org.polyvariant.treesitter4s.internal.TreeSitterLibrary

import java.util.concurrent.ConcurrentHashMap
import scala.jdk.CollectionConverters.*
import java.io.Closeable

object TreeSitterPlatform {
Expand Down Expand Up @@ -51,15 +49,6 @@ object TreeSitterPlatform {

type Language = CC

/* private */
// val languages = new ConcurrentHashMap[String, (NativeLibrary, Language)]

// def close(): Unit = {
// languages.values().asScala.foreach(_._1.close())
// languages.clear()
// }
def close(): Unit = ()

val Language: LanguageMethods =
new {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package org.polyvariant.treesitter4s

import org.polyvariant.treesitter4s.lowlevel.TreeSitter

import scala.util.Using

// High-level Tree Sitter API.
// For the lower-level one, see TreeSitter in the lowlevel package.
trait TreeSitterAPI {
Expand All @@ -30,15 +28,12 @@ trait TreeSitterAPI {

object TreeSitterAPI {

// hm what's interesting is that the committed version segfaults on
// a different function (ts_node_string) and here we crash at ts_parser_set_language.
// strange things
def make(language: (ts: TreeSitter) => ts.Language): TreeSitterAPI =
Using.resource(TreeSitter.instance()) { ts =>
Using.resource(language(ts)) { lang =>
internal.Facade.make(ts, lang)
}
}
def make(language: (ts: TreeSitter) => ts.Language): TreeSitterAPI = {
val ts = TreeSitter.instance()
val lang = language(ts)

internal.Facade.make(ts, lang)
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.polyvariant.treesitter4s.lowlevel

import java.io.Closeable

trait TreeSitter extends AutoCloseable {
trait TreeSitter {
type Parser
type Tree

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import weaver._
import org.polyvariant.treesitter4s.TreeSitterAPI

object BindingTests extends FunSuite {
val tsPython = TreeSitterAPI.make(_.Language("python"))

def parseExample(s: String): Tree = tsPython.parse(s)
val ts = TreeSitterAPI.make(_.Language("python"))
def parseExample(s: String): Tree = ts.parse(s)

test("root node child count") {
val tree = parseExample("def main = print('Hello')\n")
Expand Down

0 comments on commit b4f306c

Please sign in to comment.