Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new attribute shorthand #173

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# Rust build
target/**

# C/C++ language server cache
.ccls-cache/**

# Node cache
node_modules

# Tree-sitter ouptut
build/
.build/
log.html
*.wasm
fuzzer-out/

# Fuzzer items
Expand All @@ -26,7 +18,6 @@ fuzzer/artifacts
# Windows things
*.exp
*.lib
*.obj

# Other repos
repositories/
Expand All @@ -41,3 +32,46 @@ setup.py

# Configuring includes for autocompletion in C files
.clangd

# ======================================================================
# Sourced from tree-sitter-rust
# https://github.com/tree-sitter/tree-sitter-rust/blob/master/.gitignore
# ======================================================================
# Rust artifacts
Cargo.lock
target/

# Node artifacts
build/
prebuilds/
node_modules/
*.tgz

# Swift artifacts
.build/

# Go artifacts
go.sum
_obj/

# Python artifacts
.venv/
dist/
*.egg-info
*.whl

# C artifacts
*.a
*.so
*.so.*
*.dylib
*.dll
*.pc

# Example dirs
/examples/*/

# Grammar volatiles
*.wasm
*.obj
*.o
71 changes: 0 additions & 71 deletions Cargo.lock

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include = ["bindings/rust/*", "grammar.js", "queries-flavored/helix/*", "src/*"]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "~0.20.10"
tree-sitter-language = "0.1.0"

[build-dependencies]
cc = "~1.0.100"
4 changes: 2 additions & 2 deletions bindings/go/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tree_sitter_just_test
import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-just"
tree_sitter "github.com/tree-sitter/go-tree-sitter"
tree_sitter_just "github.com/tree-sitter/tree-sitter-just/bindings/go"
)

func TestCanLoadGrammar(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions bindings/go/go.mod

This file was deleted.

9 changes: 9 additions & 0 deletions bindings/node/binding_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="node" />

const assert = require("node:assert");
const { test } = require("node:test");

test("can load grammar", () => {
const parser = new (require("tree-sitter"))();
assert.doesNotThrow(() => parser.setLanguage(require(".")));
});
11 changes: 11 additions & 0 deletions bindings/python/tests/test_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase

import tree_sitter, tree_sitter_just


class TestLanguage(TestCase):
def test_can_load_grammar(self):
try:
tree_sitter.Language(tree_sitter_just.language())
except Exception:
self.fail("Error loading Just grammar")
23 changes: 14 additions & 9 deletions bindings/python/tree_sitter_just/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_just(void);

static PyObject *_binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_just());
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
return PyCapsule_New(tree_sitter_just(), "tree_sitter.Language", NULL);
}

static PyMethodDef methods[] = {
{"language", _binding_language, METH_NOARGS,
"Get the tree-sitter language for this grammar."},
{NULL, NULL, 0, NULL}};
{NULL, NULL, 0, NULL}
};

static struct PyModuleDef module = {.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding",
.m_doc = NULL,
.m_size = -1,
.m_methods = methods};
static struct PyModuleDef module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding",
.m_doc = NULL,
.m_size = -1,
.m_methods = methods
};

PyMODINIT_FUNC PyInit__binding(void) { return PyModule_Create(&module); }
PyMODINIT_FUNC PyInit__binding(void) {
return PyModule_Create(&module);
}
37 changes: 19 additions & 18 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
//! This crate provides just language support for the [tree-sitter][] parsing library.
//! This crate provides Just language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let code = r#"
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_just::language()).expect("Error loading just grammar");
//! let language = tree_sitter_just::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Just parser");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/

use tree_sitter::Language;
use tree_sitter_language::LanguageFn;

extern "C" {
fn tree_sitter_just() -> Language;
fn tree_sitter_just() -> *const ();
}

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_just() }
}
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_just) };

/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries-flavored/helix/highlights.scm");
pub const INJECTIONS_QUERY: &str = include_str!("../../queries-flavored/helix/injections.scm");
pub const LOCALS_QUERY: &str = include_str!("../../queries-flavored/helix/locals.scm");
// NOTE: uncomment these to include any queries that this grammar contains:

// FIXME: add tags when available
// pub const TAGS_QUERY: &'static str = include_str!("../../queries-src/tags.scm");
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");

#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading just language");
.set_language(&super::LANGUAGE.into())
.expect("Error loading Just parser");
}
}
12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterJustTests/TreeSitterJustTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
import SwiftTreeSitter
import TreeSitterJust

final class TreeSitterJustTests: XCTestCase {
func testCanLoadGrammar() throws {
let parser = Parser()
let language = Language(language: tree_sitter_just())
XCTAssertNoThrow(try parser.setLanguage(language),
"Error loading Just grammar")
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-just

go 1.23

require github.com/tree-sitter/go-tree-sitter v0.23
1 change: 1 addition & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ module.exports = grammar({
choice(
$.identifier,
seq($.identifier, "(", field("argument", $.string), ")"),
seq($.identifier, ":", field("argument", $.string)),
),
),
"]",
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@
"prebuildify": "^6.0.0"
},
"scripts": {
"format:check": "prettier --check .",
"format:write": "prettier --write .",
"lint:check": "eslint .",
"lint:fix": "eslint --fix .",
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip"
"prestart": "tree-sitter build --wasm",
"start": "tree-sitter playground",
"test": "node --test bindings/node/*_test.js"
},
"tree-sitter": [
{
Expand Down
42 changes: 42 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading