-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9931e4b
Showing
22 changed files
with
2,147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
max_line_length = 120 | ||
|
||
[LICENSE] | ||
max_line_length = off | ||
|
||
[README.md] | ||
max_line_length = off | ||
|
||
[*.yml] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: weekly | ||
day: sunday | ||
commit-message: | ||
prefix: ci | ||
labels: [dependencies] | ||
open-pull-requests-limit: 1 | ||
groups: | ||
actions: | ||
patterns: ["*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
paths: | ||
- src/* | ||
- .github/workflows/* | ||
pull_request: | ||
paths: | ||
- src/* | ||
- .github/workflows/* | ||
|
||
concurrency: | ||
cancel-in-progress: true | ||
group: ${{github.workflow}}-${{github.ref_name}} | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{matrix.os}} | ||
name: Test target ${{matrix.target}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: | ||
- x86_64-linux-gnu | ||
- x86_64-linux-musl | ||
- aarch64-linux-gnu | ||
- x86_64-windows-gnu | ||
- x86_64-windows-msvc | ||
- aarch64-macos-none | ||
include: | ||
- os: ubuntu-latest | ||
target: x86_64-linux-gnu | ||
- os: ubuntu-latest | ||
target: x86_64-linux-musl | ||
- os: ubuntu-latest | ||
target: aarch64-linux-gnu | ||
flags: -fqemu -Ddynamic-linker=/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 | ||
- os: windows-latest | ||
target: x86_64-windows-gnu | ||
- os: windows-latest | ||
target: x86_64-windows-msvc | ||
- os: macos-latest | ||
target: aarch64-macos-none | ||
- os: macos-latest | ||
target: x86_64-macos-none | ||
flags: -frosetta | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Zig | ||
uses: mlugg/setup-zig@v1 | ||
- name: Set up MSVC | ||
uses: ilammy/msvc-dev-cmd@v1 | ||
if: matrix.target == 'x86_64-windows-msvc' | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
if: matrix.target == 'aarch64-linux-gnu' | ||
with: | ||
platforms: arm64 | ||
- name: Install packages | ||
if: matrix.target == 'aarch64-linux-gnu' | ||
run: |- | ||
sudo apt-get update | ||
sudo apt-get install -y libc6-dev-arm64-cross | ||
printf 'LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib\n' >> "$GITHUB_ENV" | ||
- name: Run unit tests | ||
run: zig build test -Dtarget=${{matrix.target}} ${{matrix.flags}} --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Docs | ||
|
||
run-name: Update API docs | ||
|
||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
types: [completed] | ||
branches: [master] | ||
|
||
concurrency: | ||
cancel-in-progress: true | ||
group: ${{github.workflow}}-${{github.ref_name}} | ||
|
||
permissions: | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
name: Publish docs on GitHub pages | ||
if: github.event.workflow_run.conclusion == 'success' | ||
environment: | ||
name: github-pages | ||
url: ${{steps.deployment.outputs.page_url}} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Zig | ||
uses: mlugg/setup-zig@v1 | ||
- name: Generate documentation | ||
run: zig build docs --verbose | ||
- name: Upload pages artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: zig-out/docs | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Update | ||
|
||
on: | ||
schedule: | ||
# every Saturday at 13:00 UTC | ||
- cron: "0 13 * * 6" | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
name: Update dependencies | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Zig | ||
uses: mlugg/setup-zig@v1 | ||
- name: Create app token | ||
uses: actions/create-github-app-token@v1 | ||
id: app-token | ||
with: | ||
app-id: ${{vars.BACKPORT_APP}} | ||
private-key: ${{secrets.BACKPORT_KEY}} | ||
- name: Update tree-sitter | ||
run: |- | ||
tag="$(gh release view --json tagName -q .tagName)" | ||
url="https://github.com/$GH_REPO/archive/refs/tags/$tag.tar.gz" | ||
zig fetch --save=tree-sitter "$url" | ||
env: | ||
GH_REPO: tree-sitter/tree-sitter | ||
GH_TOKEN: ${{github.token}} | ||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
add-paths: build.zig.zon | ||
labels: dependencies | ||
commit-message: "build: update dependencies" | ||
title: "build: update dependencies" | ||
branch: update-zig-dependencies | ||
base: ${{github.head_ref}} | ||
token: ${{steps.app-token.outputs.token}} | ||
sign-commits: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### Zig ### | ||
.zig-cache/ | ||
zig-out/ | ||
build/ | ||
build-*/ | ||
docgen_tmp/ | ||
|
||
### JetBrains ### | ||
.idea/* | ||
out/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Vim ### | ||
[._]*.s[a-v][a-z] | ||
[._]*.sw[a-p] | ||
[._]s[a-rt-v][a-z] | ||
[._]ss[a-gi-z] | ||
[._]sw[a-p] | ||
Session.vim | ||
.nvimrc | ||
tags | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2024 tree-sitter contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Zig Tree-sitter | ||
|
||
[![CI][ci]](https://github.com/tree-sitter/zig-tree-sitter/actions/workflows/ci.yml) | ||
[![docs][docs]](https://tree-sitter.github.io/kotlin-tree-sitter/) | ||
|
||
Zig bindings to the [tree-sitter] parsing library. | ||
|
||
## Usage | ||
|
||
TBA | ||
|
||
[tree-sitter]: https://tree-sitter.github.io/tree-sitter/ | ||
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/zig-tree-sitter/ci.yml?logo=github&label=CI | ||
[docs]: https://img.shields.io/github/deployments/tree-sitter/zig-tree-sitter/github-pages?logo=zig&label=API%20Docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) !void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const core = b.dependency("tree-sitter", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const lib = b.addStaticLibrary(.{ | ||
.name = "zig-tree-sitter", | ||
.root_source_file = b.path("src/root.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
.link_libc = true, | ||
}); | ||
lib.linkLibrary(core.artifact("tree-sitter")); | ||
|
||
b.installArtifact(lib); | ||
|
||
const module = b.addModule("tree_sitter", .{ | ||
.root_source_file = b.path("src/root.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
module.linkLibrary(lib); | ||
|
||
const docs = b.addObject(.{ | ||
.name = "tree_sitter", | ||
.root_source_file = b.path("src/root.zig"), | ||
.target = target, | ||
.optimize = .Debug, | ||
}); | ||
|
||
const install_docs = b.addInstallDirectory(.{ | ||
.source_dir = docs.getEmittedDocs(), | ||
.install_dir = .prefix, | ||
.install_subdir = "docs", | ||
}); | ||
|
||
const docs_step = b.step("docs", "Install generated docs"); | ||
docs_step.dependOn(&install_docs.step); | ||
|
||
const tests = b.addTest(.{ | ||
.root_source_file = b.path("src/test.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
tests.linkLibrary(lib); | ||
|
||
const run_tests = b.addRunArtifact(tests); | ||
|
||
const test_step = b.step("test", "Run unit tests"); | ||
test_step.dependOn(&run_tests.step); | ||
|
||
// HACK: fetch tree-sitter-c only for tests (ziglang/zig#19914) | ||
var args = try std.process.argsWithAllocator(b.allocator); | ||
defer args.deinit(); | ||
while (args.next()) |a| { | ||
if (std.mem.eql(u8, a, "test")) { | ||
if (b.lazyDependency("tree-sitter-c", .{})) |dep| { | ||
const dep_lib = dep.builder.addStaticLibrary(.{ | ||
.name = "tree-sitter-c", | ||
.target = target, | ||
.optimize = optimize, | ||
.link_libc = true, | ||
}); | ||
dep_lib.addIncludePath(dep.path("src")); | ||
dep_lib.addCSourceFile(.{ | ||
.file = dep.path("src/parser.c"), | ||
}); | ||
tests.linkLibrary(dep_lib); | ||
} | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.{ | ||
.name = "tree_sitter", | ||
|
||
.version = "0.24.0", | ||
|
||
.dependencies = .{ | ||
.@"tree-sitter" = .{ | ||
.url = "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v0.24.3.tar.gz", | ||
.hash = "1220d7730b4b548db37a9c352adc8bda88d9cada68c02883fcef2c6dca3b83fb642e", | ||
}, | ||
.@"tree-sitter-c" = .{ | ||
.url = "https://github.com/tree-sitter/tree-sitter-c/archive/refs/tags/v0.23.1.tar.gz", | ||
.hash = "1220422ed862a57c2a4bc3e0987fd014536c0caafff70656b84a566f2cde43e9a603", | ||
.lazy = true, | ||
}, | ||
}, | ||
|
||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
"src", | ||
"LICENSE", | ||
"README.md", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// Set the allocation functions used by the library. | ||
/// | ||
/// By default, Tree-sitter uses the standard libc allocation functions, | ||
/// but aborts the process when an allocation fails. This function lets | ||
/// you supply alternative allocation functions at runtime. | ||
/// | ||
/// If you pass `null` for any parameter, Tree-sitter will switch back to | ||
/// its default implementation of that function. | ||
/// | ||
/// If you call this function after the library has already been used, then | ||
/// you must ensure that either: | ||
/// 1. All the existing objects have been freed. | ||
/// 2. The new allocator shares its state with the old one, so it is capable | ||
/// of freeing memory that was allocated by the old allocator. | ||
pub extern fn ts_set_allocator( | ||
new_malloc: ?*const fn (size: usize) callconv(.C) ?*anyopaque, | ||
new_calloc: ?*const fn (nmemb: usize, size: usize) callconv(.C) ?*anyopaque, | ||
new_realloc: ?*const fn (ptr: ?*anyopaque, size: usize) callconv(.C) ?*anyopaque, | ||
new_free: ?*const fn (ptr: ?*anyopaque) callconv(.C) void | ||
) void; |
Oops, something went wrong.