diff --git a/Cargo.toml b/Cargo.toml index 52ba959..ef852ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = ">=0.21.0" +tree-sitter-language = "0.1.0" [build-dependencies] cc = "1.0.92" diff --git a/bindings/go/binding_test.go b/bindings/go/binding_test.go index 8f9c805..964e819 100644 --- a/bindings/go/binding_test.go +++ b/bindings/go/binding_test.go @@ -3,13 +3,13 @@ package tree_sitter_yaml_test import ( "testing" - tree_sitter "github.com/smacker/go-tree-sitter" - "github.com/tree-sitter/tree-sitter-yaml" + tree_sitter "github.com/tree-sitter/go-tree-sitter" + tree_sitter_yaml "github.com/tree-sitter/tree-sitter-yaml/bindings/go" ) func TestCanLoadGrammar(t *testing.T) { language := tree_sitter.NewLanguage(tree_sitter_yaml.Language()) if language == nil { - t.Errorf("Error loading YAML grammar") + t.Errorf("Error loading Yaml grammar") } } diff --git a/bindings/go/go.mod b/bindings/go/go.mod deleted file mode 100644 index e9941e6..0000000 --- a/bindings/go/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/tree-sitter-grammars/tree-sitter-yaml - -go 1.22 - -require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 diff --git a/bindings/python/tree_sitter_yaml/binding.c b/bindings/python/tree_sitter_yaml/binding.c index 6dfac56..9ab64a6 100644 --- a/bindings/python/tree_sitter_yaml/binding.c +++ b/bindings/python/tree_sitter_yaml/binding.c @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_yaml(void); -static PyObject* _binding_language(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_yaml()); +static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_yaml(), "tree_sitter.Language", NULL); } static PyMethodDef methods[] = { diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index c7560ae..555a22c 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,17 +1,16 @@ -//! This crate provides YAML language support for the [tree-sitter][] parsing library. +//! This crate provides Yaml 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#" -//! key: value -//! list: -//! - item1 -//! - item2 //! "#; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(&tree_sitter_yaml::language()).expect("Error loading YAML grammar"); +//! let language = tree_sitter_yaml::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading Yaml parser"); //! let tree = parser.parse(code, None).unwrap(); //! assert!(!tree.root_node().has_error()); //! ``` @@ -21,34 +20,23 @@ //! [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_yaml() -> Language; + fn tree_sitter_yaml() -> *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_yaml() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_yaml) }; /// 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"); -/// The highlight queries for this grammar. -pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); +// NOTE: uncomment these to include any queries that this grammar contains: -#[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 YAML grammar"); - } -} +// 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"); diff --git a/package.json b/package.json index f2d34a2..8273e0a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "devDependencies": { "prebuildify": "^6.0.1", - "tree-sitter-cli": "^0.22.5" + "tree-sitter-cli": "^0.23.0" }, "peerDependencies": { "tree-sitter": "^0.21.1" @@ -49,11 +49,10 @@ } }, "scripts": { - "build": "tree-sitter generate --no-bindings", - "postbuild": "npm run --prefix schema/core build", - "test": "tree-sitter test", "install": "node-gyp-build", - "prebuildify": "prebuildify --napi --strip" + "prestart": "tree-sitter build --wasm", + "start": "tree-sitter playground", + "test": "node --test bindings/node/*_test.js" }, "publishConfig": { "access": "public" diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 17f0e94..799f599 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -47,6 +47,7 @@ struct TSLexer { uint32_t (*get_column)(TSLexer *); bool (*is_at_included_range_start)(const TSLexer *); bool (*eof)(const TSLexer *); + void (*log)(const TSLexer *, const char *, ...); }; typedef enum {