Skip to content

Commit

Permalink
rever cargo.toml changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Nov 10, 2024
1 parent 760f0f7 commit 63c99de
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 36 deletions.
71 changes: 71 additions & 0 deletions Cargo.lock

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

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-language = "0.1.0"
tree-sitter = "~0.20.10"

[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/tree-sitter/go-tree-sitter"
tree_sitter_just "github.com/tree-sitter/tree-sitter-just/bindings/go"
tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-just"
)

func TestCanLoadGrammar(t *testing.T) {
Expand Down
23 changes: 9 additions & 14 deletions bindings/python/tree_sitter_just/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@ typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_just(void);

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

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: 18 additions & 19 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
//! 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 = r#"
//! "#;
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! let language = tree_sitter_just::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Just parser");
//! parser.set_language(tree_sitter_just::language()).expect("Error loading just grammar");
//! 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::LanguageFn;
use tree_sitter::Language;

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

/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_just) };
/// 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 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");

// NOTE: uncomment these to include any queries that this grammar contains:
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");

// 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");
// FIXME: add tags when available
// pub const TAGS_QUERY: &'static str = include_str!("../../queries-src/tags.scm");

#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(&super::LANGUAGE.into())
.expect("Error loading Just parser");
.set_language(super::language())
.expect("Error loading just language");
}
}

0 comments on commit 63c99de

Please sign in to comment.