Skip to content

Commit

Permalink
upgrade tree sitter to '0.22.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bonede committed Mar 19, 2024
1 parent da9cdea commit 3faf1dc
Show file tree
Hide file tree
Showing 28 changed files with 409 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Next generation Tree Sitter Java binding.

[![Maven Central](https://img.shields.io/github/actions/workflow/status/bonede/tree-sitter-ng/main.yml)](https://github.com/bonede/tree-sitter-ng/actions)

[![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter)](https://central.sonatype.com/artifact/io.github.bonede/tree-sitter)

# Getting started
Expand All @@ -12,7 +11,7 @@ Add dependencies to your `build.gradle` or `pom.xml`.
// Gradle
dependencies {
// add tree sitter
implementation 'io.github.bonede:tree-sitter:0.22.1'
implementation 'io.github.bonede:tree-sitter:0.22.2'
// add json parser
implementation 'io.github.bonede:tree-sitter-json:0.20.1'
}
Expand All @@ -25,7 +24,7 @@ dependencies {
<dependency>
<groupId>io.github.bonede</groupId>
<artifactId>tree-sitter</artifactId>
<version>0.22.1</version>
<version>0.22.2</version>
</dependency>
<!-- add json parser -->
<dependency>
Expand Down Expand Up @@ -126,6 +125,8 @@ class Main {
| `io.github.bonede:tree-sitter-markdown:0.7.1` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-markdown) |
| `io.github.bonede:tree-sitter-meson:1.2` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-meson) |
| `io.github.bonede:tree-sitter-nix:master` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-nix) |
| `io.github.bonede:tree-sitter-nginx:main` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-nginx) |
| `io.github.bonede:tree-sitter-nim:0.5.0` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-nim) |
| `io.github.bonede:tree-sitter-objc:main` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-objc) |
| `io.github.bonede:tree-sitter-ocaml:0.20.4` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-ocaml) |
| `io.github.bonede:tree-sitter-ohm:main` | ![Maven Central](https://img.shields.io/maven-central/v/io.github.bonede/tree-sitter-ohm) |
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ include 'tree-sitter-zig'
include 'tree-sitter-tact'
include 'tree-sitter-ohm'
include 'tree-sitter-p4'
include 'tree-sitter-nginx'
include 'tree-sitter-nim'
154 changes: 154 additions & 0 deletions tree-sitter-nginx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@


import org.treesitter.build.Utils

plugins {
id 'java'
id 'signing'
id 'maven-publish'
}

group = 'io.github.bonede'
version = libVersion

repositories {
mavenCentral()
}

dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation project(":tree-sitter")
}

test {
useJUnitPlatform()
}
def libName = "tree-sitter-nginx"


java {
withJavadocJar()
withSourcesJar()
}

publishing {
repositories {
maven {
name = "MavenCentral"
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
credentials {
username = ossrhUsername
password = ossrhPassword
}
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
publications {
maven(MavenPublication) {
from components.java
pom {
name = libName
url = 'https://github.com/bonede/tree-sitter-ng'
description = "Next generation Tree Sitter Java binding"
licenses {
license {
name = 'MIT'
}
}
scm {
connection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git'
developerConnection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git'
url = 'https://github.com/bonede/tree-sitter-ng'
}
developers {
developer {
id = 'bonede'
name = 'Wang Liang'
email = '[email protected]'
}
}
}
}
}
}


signing {
sign configurations.archives
sign publishing.publications
}
tasks.register('downloadSource') {
group = "build setup"
description = "Download parser source"
def zipUrl = "https://gitlab.com/joncoole/tree-sitter-nginx/-/archive/main/tree-sitter-nginx-main.zip"
def downloadDir = Utils.libDownloadDir(project, libName)
def zip = Utils.libZipFile(project, libName, libVersion)
def parserCFile = Utils.libParserCFile(project, libName, libVersion)
inputs.files(layout.projectDirectory.file("gradle.properties"))
outputs.files(parserCFile)
doLast {
download.run {
src zipUrl
dest zip
overwrite false
}
copy {
from zipTree(zip)
into downloadDir
}
}

}

tasks.register("buildNative") {
group = "build"
description = "Build parser native modules"
dependsOn "downloadSource", rootProject.bootstrap
def jniSrcDir = Utils.jniSrcDir(project)
def outDir = Utils.jniOutDir(project)
def jniCFile = Utils.jniCFile(project, "org_treesitter_TreeSitterNginx.c")
def parserCFile = Utils.libParserCFile(project, libName, libVersion)
def scannerCFile = Utils.libScannerCFile(project, libName, libVersion)
def libSrcDir = Utils.libSrcDir(project, libName, libVersion)
def jniInclude = Utils.jniIncludeDir(project)

def targets = Utils.treeSitterTargets(project)
def outputFiles = targets.collect()
{ t -> Utils.jniOutFile(project, t, libName)}
def srcFiles = project.fileTree(libSrcDir) {
include(Utils.libFiles())
}.toList()
outputs.files(outputFiles)
def inputFiles = srcFiles + [parserCFile, rootProject.layout.projectDirectory.file("gradle.properties")]
inputs.files(inputFiles)
doLast{
mkdir(outDir)
targets.each {target ->
def jniMdInclude = Utils.jniMdInclude(project, target)
def jniOutFile = Utils.jniOutFile(project, target, libName)
def files = project.fileTree(libSrcDir) {
include(Utils.libFiles())
}.toList()
def cmd = [
rootProject.downloadZig.zigExe, "c++",
"-g0",
"-shared",
"-target", target,
"-I", libSrcDir,
"-I", jniInclude,
"-I", jniMdInclude,
"-o", jniOutFile,
jniCFile,
]

cmd.addAll(files)
exec{
workingDir jniSrcDir
commandLine(cmd)
}
}
Utils.removeWindowsDebugFiles(project)
}
}
1 change: 1 addition & 0 deletions tree-sitter-nginx/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libVersion=main
12 changes: 12 additions & 0 deletions tree-sitter-nginx/src/main/c/org_treesitter_TreeSitterNginx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#include <jni.h>
void *tree_sitter_nginx();
/*
* Class: org_treesitter_TreeSitterNginx
* Method: tree_sitter_nginx
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_treesitter_TreeSitterNginx_tree_1sitter_1nginx
(JNIEnv *env, jclass clz){
return (jlong) tree_sitter_nginx();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package org.treesitter;

import org.treesitter.utils.NativeUtils;

public class TreeSitterNginx implements TSLanguage {

static {
NativeUtils.loadLib("lib/tree-sitter-nginx");
}
private native static long tree_sitter_nginx();

private final long ptr;

public TreeSitterNginx() {
ptr = tree_sitter_nginx();
}

@Override
public long getPtr() {
return ptr;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

package org.treesitter;

import org.junit.jupiter.api.Test;

class TreeSitterNginxTest {
@Test
void init() {
new TreeSitterNginx();
}
}
Loading

0 comments on commit 3faf1dc

Please sign in to comment.