Merge branch 'master' into node-fields
This commit is contained in:
commit
5035e194ff
34 changed files with 1178 additions and 240 deletions
|
|
@ -138,16 +138,16 @@ extern "C" {
|
|||
) -> *mut TSTree;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_enabled(arg1: *const TSParser) -> bool;
|
||||
pub fn ts_parser_cancellation_flag(arg1: *const TSParser) -> *const usize;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_enabled(arg1: *mut TSParser, arg2: bool);
|
||||
pub fn ts_parser_set_cancellation_flag(arg1: *mut TSParser, arg2: *const usize);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_operation_limit(arg1: *const TSParser) -> usize;
|
||||
pub fn ts_parser_timeout_micros(arg1: *const TSParser) -> u64;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_operation_limit(arg1: *mut TSParser, arg2: usize);
|
||||
pub fn ts_parser_set_timeout_micros(arg1: *mut TSParser, arg2: u64);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_reset(arg1: *mut TSParser);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use std::collections::HashMap;
|
|||
use std::ffi::CStr;
|
||||
use std::marker::PhantomData;
|
||||
use std::os::raw::{c_char, c_void};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::{fmt, ptr, slice, str, u16};
|
||||
|
||||
pub const LANGUAGE_VERSION: usize = ffi::TREE_SITTER_LANGUAGE_VERSION;
|
||||
|
|
@ -348,8 +349,12 @@ impl Parser {
|
|||
unsafe { ffi::ts_parser_reset(self.0) }
|
||||
}
|
||||
|
||||
pub fn set_operation_limit(&mut self, limit: usize) {
|
||||
unsafe { ffi::ts_parser_set_operation_limit(self.0, limit) }
|
||||
pub fn timeout_micros(&self) -> u64 {
|
||||
unsafe { ffi::ts_parser_timeout_micros(self.0) }
|
||||
}
|
||||
|
||||
pub fn set_timeout_micros(&mut self, timeout_micros: u64) {
|
||||
unsafe { ffi::ts_parser_set_timeout_micros(self.0, timeout_micros) }
|
||||
}
|
||||
|
||||
pub fn set_included_ranges(&mut self, ranges: &[Range]) {
|
||||
|
|
@ -359,6 +364,18 @@ impl Parser {
|
|||
ffi::ts_parser_set_included_ranges(self.0, ts_ranges.as_ptr(), ts_ranges.len() as u32)
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn cancellation_flag(&self) -> Option<&AtomicUsize> {
|
||||
(ffi::ts_parser_cancellation_flag(self.0) as *const AtomicUsize).as_ref()
|
||||
}
|
||||
|
||||
pub unsafe fn set_cancellation_flag(&self, flag: Option<&AtomicUsize>) {
|
||||
if let Some(flag) = flag {
|
||||
ffi::ts_parser_set_cancellation_flag(self.0, flag as *const AtomicUsize as *const usize);
|
||||
} else {
|
||||
ffi::ts_parser_set_cancellation_flag(self.0, ptr::null());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Parser {
|
||||
|
|
@ -511,10 +528,11 @@ impl<'tree> Node<'tree> {
|
|||
unsafe { ffi::ts_node_child_count(self.0) as usize }
|
||||
}
|
||||
|
||||
pub fn children<'a>(&'a self) -> impl Iterator<Item = Node<'tree>> + 'a {
|
||||
pub fn children(&self) -> impl Iterator<Item = Node<'tree>> {
|
||||
let me = self.clone();
|
||||
(0..self.child_count())
|
||||
.into_iter()
|
||||
.map(move |i| self.child(i).unwrap())
|
||||
.map(move |i| me.child(i).unwrap())
|
||||
}
|
||||
|
||||
pub fn named_child<'a>(&'a self, i: usize) -> Option<Self> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue