Introduce language ref-count management C APIs, remove Copy impl for Language in Rust
This commit is contained in:
parent
660481dbf7
commit
da16cb1459
27 changed files with 363 additions and 314 deletions
|
|
@ -664,6 +664,14 @@ extern "C" {
|
|||
#[doc = " Set the maximum start depth for a query cursor.\n\n This prevents cursors from exploring children nodes at a certain depth.\n Note if a pattern includes many children, then they will still be checked.\n\n The zero max start depth value can be used as a special behavior and\n it helps to destructure a subtree by staying on a node and using captures\n for interested parts. Note that the zero max start depth only limit a search\n depth for a pattern's root node but other nodes that are parts of the pattern\n may be searched at any depth what defined by the pattern structure.\n\n Set to `UINT32_MAX` to remove the maximum start depth."]
|
||||
pub fn ts_query_cursor_set_max_start_depth(self_: *mut TSQueryCursor, max_start_depth: u32);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get another reference to the given language."]
|
||||
pub fn ts_language_copy(self_: *const TSLanguage) -> *const TSLanguage;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Free any dynamically-allocated resources for this language, if\n this is the last reference."]
|
||||
pub fn ts_language_delete(self_: *const TSLanguage);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the number of distinct node types in the language."]
|
||||
pub fn ts_language_symbol_count(self_: *const TSLanguage) -> u32;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ pub const PARSER_HEADER: &'static str = include_str!("../include/tree_sitter/par
|
|||
/// An opaque object that defines how to parse a particular language. The code for each
|
||||
/// `Language` is generated by the Tree-sitter CLI.
|
||||
#[doc(alias = "TSLanguage")]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
#[repr(transparent)]
|
||||
pub struct Language(*const ffi::TSLanguage);
|
||||
|
||||
|
|
@ -385,6 +385,18 @@ impl Language {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clone for Language {
|
||||
fn clone(&self) -> Self {
|
||||
unsafe { Self(ffi::ts_language_copy(self.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Language {
|
||||
fn drop(&mut self) {
|
||||
unsafe { ffi::ts_language_delete(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
/// Create a new parser.
|
||||
pub fn new() -> Parser {
|
||||
|
|
@ -403,7 +415,7 @@ impl Parser {
|
|||
/// and compare it to this library's [`LANGUAGE_VERSION`](LANGUAGE_VERSION) and
|
||||
/// [`MIN_COMPATIBLE_LANGUAGE_VERSION`](MIN_COMPATIBLE_LANGUAGE_VERSION) constants.
|
||||
#[doc(alias = "ts_parser_set_language")]
|
||||
pub fn set_language(&mut self, language: Language) -> Result<(), LanguageError> {
|
||||
pub fn set_language(&mut self, language: &Language) -> Result<(), LanguageError> {
|
||||
let version = language.version();
|
||||
if version < MIN_COMPATIBLE_LANGUAGE_VERSION || version > LANGUAGE_VERSION {
|
||||
Err(LanguageError { version })
|
||||
|
|
@ -1553,7 +1565,7 @@ impl Query {
|
|||
/// The query is associated with a particular language, and can only be run
|
||||
/// on syntax nodes parsed with that language. References to Queries can be
|
||||
/// shared between multiple threads.
|
||||
pub fn new(language: Language, source: &str) -> Result<Self, QueryError> {
|
||||
pub fn new(language: &Language, source: &str) -> Result<Self, QueryError> {
|
||||
let mut error_offset = 0u32;
|
||||
let mut error_type: ffi::TSQueryError = 0;
|
||||
let bytes = source.as_bytes();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue