feat!: introduce tree-sitter-language crate for grammar crates to depend on
Co-authored-by: Conrad <conrad@zed.dev> Co-authored-by: Marshall <marshall@zed.dev> Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
parent
04b9eb5700
commit
38137c71b2
9 changed files with 110 additions and 18 deletions
14
lib/language/Cargo.toml
Normal file
14
lib/language/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "tree-sitter-language"
|
||||
description = "The tree-sitter Language type, used by the library and by language implementations"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[lib]
|
||||
path = "language.rs"
|
||||
20
lib/language/language.rs
Normal file
20
lib/language/language.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/// LanguageFn wraps a C function that returns a pointer to a tree-sitter grammer.
|
||||
#[repr(transparent)]
|
||||
pub struct LanguageFn(unsafe extern "C" fn() -> *const ());
|
||||
|
||||
impl LanguageFn {
|
||||
/// Creates a `LanguageFn`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Only call this with language functions generated from grammars
|
||||
/// by the Tree-sitter CLI.
|
||||
pub const unsafe fn from_raw(f: unsafe extern "C" fn() -> *const ()) -> Self {
|
||||
Self(f)
|
||||
}
|
||||
|
||||
/// Gets the function wrapped by this `LanguageFn`.
|
||||
pub const fn into_raw(self) -> unsafe extern "C" fn() -> *const () {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue