style: wrap comments
This commit is contained in:
parent
b35efa8f33
commit
5825e24d56
13 changed files with 246 additions and 220 deletions
|
|
@ -46,8 +46,8 @@ pub const MIN_COMPATIBLE_LANGUAGE_VERSION: usize =
|
|||
pub const ARRAY_HEADER: &str = include_str!("../src/array.h");
|
||||
pub const PARSER_HEADER: &str = include_str!("../src/parser.h");
|
||||
|
||||
/// An opaque object that defines how to parse a particular language. The code for each
|
||||
/// `Language` is generated by the Tree-sitter CLI.
|
||||
/// 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(Debug, PartialEq, Eq, Hash)]
|
||||
#[repr(transparent)]
|
||||
|
|
@ -68,8 +68,8 @@ pub struct Point {
|
|||
pub column: usize,
|
||||
}
|
||||
|
||||
/// A range of positions in a multi-line text document, both in terms of bytes and of
|
||||
/// rows and columns.
|
||||
/// A range of positions in a multi-line text document, both in terms of bytes
|
||||
/// and of rows and columns.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Range {
|
||||
pub start_byte: usize,
|
||||
|
|
@ -95,11 +95,13 @@ pub struct InputEdit {
|
|||
#[repr(transparent)]
|
||||
pub struct Node<'tree>(ffi::TSNode, PhantomData<&'tree ()>);
|
||||
|
||||
/// A stateful object that this is used to produce a [`Tree`] based on some source code.
|
||||
/// A stateful object that this is used to produce a [`Tree`] based on some
|
||||
/// source code.
|
||||
#[doc(alias = "TSParser")]
|
||||
pub struct Parser(NonNull<ffi::TSParser>);
|
||||
|
||||
/// A stateful object that is used to look up symbols valid in a specific parse state
|
||||
/// A stateful object that is used to look up symbols valid in a specific parse
|
||||
/// state
|
||||
#[doc(alias = "TSLookaheadIterator")]
|
||||
pub struct LookaheadIterator(NonNull<ffi::TSLookaheadIterator>);
|
||||
struct LookaheadNamesIterator<'a>(&'a mut LookaheadIterator);
|
||||
|
|
@ -220,7 +222,8 @@ where
|
|||
fn text(&mut self, node: Node) -> Self::I;
|
||||
}
|
||||
|
||||
/// A particular [`Node`] that has been captured with a particular name within a [`Query`].
|
||||
/// A particular [`Node`] that has been captured with a particular name within a
|
||||
/// [`Query`].
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct QueryCapture<'tree> {
|
||||
|
|
@ -228,7 +231,8 @@ pub struct QueryCapture<'tree> {
|
|||
pub index: u32,
|
||||
}
|
||||
|
||||
/// An error that occurred when trying to assign an incompatible [`Language`] to a [`Parser`].
|
||||
/// An error that occurred when trying to assign an incompatible [`Language`] to
|
||||
/// a [`Parser`].
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct LanguageError {
|
||||
version: usize,
|
||||
|
|
@ -280,8 +284,8 @@ pub struct LossyUtf8<'a> {
|
|||
}
|
||||
|
||||
impl Language {
|
||||
/// Get the ABI version number that indicates which version of the Tree-sitter CLI
|
||||
/// that was used to generate this [`Language`].
|
||||
/// Get the ABI version number that indicates which version of the
|
||||
/// Tree-sitter CLI that was used to generate this [`Language`].
|
||||
#[doc(alias = "ts_language_version")]
|
||||
#[must_use]
|
||||
pub fn version(&self) -> usize {
|
||||
|
|
@ -442,11 +446,13 @@ impl Parser {
|
|||
/// Set the language that the parser should use for parsing.
|
||||
///
|
||||
/// Returns a Result indicating whether or not the language was successfully
|
||||
/// assigned. True means assignment succeeded. False means there was a version
|
||||
/// mismatch: the language was generated with an incompatible version of the
|
||||
/// Tree-sitter CLI. Check the language's version using [`Language::version`]
|
||||
/// and compare it to this library's [`LANGUAGE_VERSION`](LANGUAGE_VERSION) and
|
||||
/// [`MIN_COMPATIBLE_LANGUAGE_VERSION`](MIN_COMPATIBLE_LANGUAGE_VERSION) constants.
|
||||
/// assigned. True means assignment succeeded. False means there was a
|
||||
/// version mismatch: the language was generated with an incompatible
|
||||
/// version of the Tree-sitter CLI. Check the language's version using
|
||||
/// [`Language::version`] 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> {
|
||||
let version = language.version();
|
||||
|
|
@ -521,9 +527,9 @@ impl Parser {
|
|||
}
|
||||
|
||||
/// Set the destination to which the parser should write debugging graphs
|
||||
/// during parsing. The graphs are formatted in the DOT language. You may want
|
||||
/// to pipe these graphs directly to a `dot(1)` process in order to generate
|
||||
/// SVG output.
|
||||
/// during parsing. The graphs are formatted in the DOT language. You may
|
||||
/// want to pipe these graphs directly to a `dot(1)` process in order to
|
||||
/// generate SVG output.
|
||||
#[doc(alias = "ts_parser_print_dot_graphs")]
|
||||
pub fn print_dot_graphs(
|
||||
&mut self,
|
||||
|
|
@ -557,10 +563,9 @@ impl Parser {
|
|||
///
|
||||
/// # Arguments:
|
||||
/// * `text` The UTF8-encoded text to parse.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document.
|
||||
/// If the text of the document has changed since `old_tree` was
|
||||
/// created, then you must edit `old_tree` to match the new text using
|
||||
/// [`Tree::edit`].
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [`Tree::edit`].
|
||||
///
|
||||
/// Returns a [`Tree`] if parsing succeeded, or `None` if:
|
||||
/// * The parser has not yet had a language assigned with [`Parser::set_language`]
|
||||
|
|
@ -580,10 +585,9 @@ impl Parser {
|
|||
///
|
||||
/// # Arguments:
|
||||
/// * `text` The UTF16-encoded text to parse.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document.
|
||||
/// If the text of the document has changed since `old_tree` was
|
||||
/// created, then you must edit `old_tree` to match the new text using
|
||||
/// [`Tree::edit`].
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16(
|
||||
&mut self,
|
||||
input: impl AsRef<[u16]>,
|
||||
|
|
@ -600,14 +604,13 @@ impl Parser {
|
|||
/// Parse UTF8 text provided in chunks by a callback.
|
||||
///
|
||||
/// # Arguments:
|
||||
/// * `callback` A function that takes a byte offset and position and
|
||||
/// returns a slice of UTF8-encoded text starting at that byte offset
|
||||
/// and position. The slices can be of any length. If the given position
|
||||
/// is at the end of the text, the callback should return an empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document.
|
||||
/// If the text of the document has changed since `old_tree` was
|
||||
/// created, then you must edit `old_tree` to match the new text using
|
||||
/// [`Tree::edit`].
|
||||
/// * `callback` A function that takes a byte offset and position and returns a slice of
|
||||
/// UTF8-encoded text starting at that byte offset and position. The slices can be of any
|
||||
/// length. If the given position is at the end of the text, the callback should return an
|
||||
/// empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_with<T: AsRef<[u8]>, F: FnMut(usize, Point) -> T>(
|
||||
&mut self,
|
||||
callback: &mut F,
|
||||
|
|
@ -616,8 +619,8 @@ impl Parser {
|
|||
// A pointer to this payload is passed on every call to the `read` C function.
|
||||
// The payload contains two things:
|
||||
// 1. A reference to the rust `callback`.
|
||||
// 2. The text that was returned from the previous call to `callback`.
|
||||
// This allows the callback to return owned values like vectors.
|
||||
// 2. The text that was returned from the previous call to `callback`. This allows the
|
||||
// callback to return owned values like vectors.
|
||||
let mut payload: (&mut F, Option<T>) = (callback, None);
|
||||
|
||||
// This C function is passed to Tree-sitter as the input callback.
|
||||
|
|
@ -650,14 +653,13 @@ impl Parser {
|
|||
/// Parse UTF16 text provided in chunks by a callback.
|
||||
///
|
||||
/// # Arguments:
|
||||
/// * `callback` A function that takes a code point offset and position and
|
||||
/// returns a slice of UTF16-encoded text starting at that byte offset
|
||||
/// and position. The slices can be of any length. If the given position
|
||||
/// is at the end of the text, the callback should return an empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document.
|
||||
/// If the text of the document has changed since `old_tree` was
|
||||
/// created, then you must edit `old_tree` to match the new text using
|
||||
/// [`Tree::edit`].
|
||||
/// * `callback` A function that takes a code point offset and position and returns a slice of
|
||||
/// UTF16-encoded text starting at that byte offset and position. The slices can be of any
|
||||
/// length. If the given position is at the end of the text, the callback should return an
|
||||
/// empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16_with<T: AsRef<[u16]>, F: FnMut(usize, Point) -> T>(
|
||||
&mut self,
|
||||
callback: &mut F,
|
||||
|
|
@ -666,8 +668,8 @@ impl Parser {
|
|||
// A pointer to this payload is passed on every call to the `read` C function.
|
||||
// The payload contains two things:
|
||||
// 1. A reference to the rust `callback`.
|
||||
// 2. The text that was returned from the previous call to `callback`.
|
||||
// This allows the callback to return owned values like vectors.
|
||||
// 2. The text that was returned from the previous call to `callback`. This allows the
|
||||
// callback to return owned values like vectors.
|
||||
let mut payload: (&mut F, Option<T>) = (callback, None);
|
||||
|
||||
// This C function is passed to Tree-sitter as the input callback.
|
||||
|
|
@ -705,9 +707,10 @@ impl Parser {
|
|||
|
||||
/// Instruct the parser to start the next parse from the beginning.
|
||||
///
|
||||
/// If the parser previously failed because of a timeout or a cancellation, then by default, it
|
||||
/// will resume where it left off on the next call to [`parse`](Parser::parse) or other parsing
|
||||
/// functions. If you don't want to resume, and instead intend to use this parser to parse some
|
||||
/// If the parser previously failed because of a timeout or a cancellation,
|
||||
/// then by default, it will resume where it left off on the next call
|
||||
/// to [`parse`](Parser::parse) or other parsing functions. If you don't
|
||||
/// want to resume, and instead intend to use this parser to parse some
|
||||
/// other document, you must call `reset` first.
|
||||
#[doc(alias = "ts_parser_reset")]
|
||||
pub fn reset(&mut self) {
|
||||
|
|
@ -723,8 +726,8 @@ impl Parser {
|
|||
unsafe { ffi::ts_parser_timeout_micros(self.0.as_ptr()) }
|
||||
}
|
||||
|
||||
/// Set the maximum duration in microseconds that parsing should be allowed to
|
||||
/// take before halting.
|
||||
/// Set the maximum duration in microseconds that parsing should be allowed
|
||||
/// to take before halting.
|
||||
///
|
||||
/// If parsing takes longer than this, it will halt early, returning `None`.
|
||||
/// See [`parse`](Parser::parse) for more information.
|
||||
|
|
@ -735,20 +738,21 @@ impl Parser {
|
|||
|
||||
/// Set the ranges of text that the parser should include when parsing.
|
||||
///
|
||||
/// By default, the parser will always include entire documents. This function
|
||||
/// allows you to parse only a *portion* of a document but still return a syntax
|
||||
/// tree whose ranges match up with the document as a whole. You can also pass
|
||||
/// multiple disjoint ranges.
|
||||
/// By default, the parser will always include entire documents. This
|
||||
/// function allows you to parse only a *portion* of a document but
|
||||
/// still return a syntax tree whose ranges match up with the document
|
||||
/// as a whole. You can also pass multiple disjoint ranges.
|
||||
///
|
||||
/// If `ranges` is empty, then the entire document will be parsed. Otherwise,
|
||||
/// the given ranges must be ordered from earliest to latest in the document,
|
||||
/// and they must not overlap. That is, the following must hold for all
|
||||
/// `i` < `length - 1`:
|
||||
/// If `ranges` is empty, then the entire document will be parsed.
|
||||
/// Otherwise, the given ranges must be ordered from earliest to latest
|
||||
/// in the document, and they must not overlap. That is, the following
|
||||
/// must hold for all `i` < `length - 1`:
|
||||
/// ```text
|
||||
/// ranges[i].end_byte <= ranges[i + 1].start_byte
|
||||
/// ```
|
||||
/// If this requirement is not satisfied, method will return [`IncludedRangesError`]
|
||||
/// error with an offset in the passed ranges slice pointing to a first incorrect range.
|
||||
/// If this requirement is not satisfied, method will return
|
||||
/// [`IncludedRangesError`] error with an offset in the passed ranges
|
||||
/// slice pointing to a first incorrect range.
|
||||
#[doc(alias = "ts_parser_set_included_ranges")]
|
||||
pub fn set_included_ranges(&mut self, ranges: &[Range]) -> Result<(), IncludedRangesError> {
|
||||
let ts_ranges = ranges
|
||||
|
|
@ -812,8 +816,9 @@ impl Parser {
|
|||
/// Set the parser's current cancellation flag pointer.
|
||||
///
|
||||
/// If a pointer is assigned, then the parser will periodically read from
|
||||
/// this pointer during parsing. If it reads a non-zero value, it will halt early,
|
||||
/// returning `None`. See [`parse`](Parser::parse) for more information.
|
||||
/// this pointer during parsing. If it reads a non-zero value, it will halt
|
||||
/// early, returning `None`. See [`parse`](Parser::parse) for more
|
||||
/// information.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
|
|
@ -889,13 +894,15 @@ impl Tree {
|
|||
self.root_node().walk()
|
||||
}
|
||||
|
||||
/// Compare this old edited syntax tree to a new syntax tree representing the same
|
||||
/// document, returning a sequence of ranges whose syntactic structure has changed.
|
||||
/// Compare this old edited syntax tree to a new syntax tree representing
|
||||
/// the same document, returning a sequence of ranges whose syntactic
|
||||
/// structure has changed.
|
||||
///
|
||||
/// For this to work correctly, this syntax tree must have been edited such that its
|
||||
/// ranges match up to the new tree. Generally, you'll want to call this method right
|
||||
/// after calling one of the [`Parser::parse`] functions. Call it on the old tree that
|
||||
/// was passed to parse, and pass the new tree that was returned from `parse`.
|
||||
/// For this to work correctly, this syntax tree must have been edited such
|
||||
/// that its ranges match up to the new tree. Generally, you'll want to
|
||||
/// call this method right after calling one of the [`Parser::parse`]
|
||||
/// functions. Call it on the old tree that was passed to parse, and
|
||||
/// pass the new tree that was returned from `parse`.
|
||||
#[doc(alias = "ts_tree_get_changed_ranges")]
|
||||
#[must_use]
|
||||
pub fn changed_ranges(&self, other: &Self) -> impl ExactSizeIterator<Item = Range> {
|
||||
|
|
@ -929,8 +936,9 @@ impl Tree {
|
|||
}
|
||||
|
||||
/// Print a graph of the tree to the given file descriptor.
|
||||
/// The graph is formatted in the DOT language. You may want to pipe this graph
|
||||
/// directly to a `dot(1)` process in order to generate SVG output.
|
||||
/// The graph is formatted in the DOT language. You may want to pipe this
|
||||
/// graph directly to a `dot(1)` process in order to generate SVG
|
||||
/// output.
|
||||
#[doc(alias = "ts_tree_print_dot_graph")]
|
||||
pub fn print_dot_graph(
|
||||
&self,
|
||||
|
|
@ -1028,8 +1036,8 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Check if this node is *named*.
|
||||
///
|
||||
/// Named nodes correspond to named rules in the grammar, whereas *anonymous* nodes
|
||||
/// correspond to string literals in the grammar.
|
||||
/// Named nodes correspond to named rules in the grammar, whereas
|
||||
/// *anonymous* nodes correspond to string literals in the grammar.
|
||||
#[doc(alias = "ts_node_is_named")]
|
||||
#[must_use]
|
||||
pub fn is_named(&self) -> bool {
|
||||
|
|
@ -1038,8 +1046,8 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Check if this node is *extra*.
|
||||
///
|
||||
/// Extra nodes represent things like comments, which are not required the grammar,
|
||||
/// but can appear anywhere.
|
||||
/// Extra nodes represent things like comments, which are not required the
|
||||
/// grammar, but can appear anywhere.
|
||||
#[doc(alias = "ts_node_is_extra")]
|
||||
#[must_use]
|
||||
pub fn is_extra(&self) -> bool {
|
||||
|
|
@ -1053,8 +1061,8 @@ impl<'tree> Node<'tree> {
|
|||
unsafe { ffi::ts_node_has_changes(self.0) }
|
||||
}
|
||||
|
||||
/// Check if this node represents a syntax error or contains any syntax errors anywhere
|
||||
/// within it.
|
||||
/// Check if this node represents a syntax error or contains any syntax
|
||||
/// errors anywhere within it.
|
||||
#[doc(alias = "ts_node_has_error")]
|
||||
#[must_use]
|
||||
pub fn has_error(&self) -> bool {
|
||||
|
|
@ -1063,8 +1071,8 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Check if this node represents a syntax error.
|
||||
///
|
||||
/// Syntax errors represent parts of the code that could not be incorporated into a
|
||||
/// valid syntax tree.
|
||||
/// Syntax errors represent parts of the code that could not be incorporated
|
||||
/// into a valid syntax tree.
|
||||
#[doc(alias = "ts_node_is_error")]
|
||||
#[must_use]
|
||||
pub fn is_error(&self) -> bool {
|
||||
|
|
@ -1087,8 +1095,8 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Check if this node is *missing*.
|
||||
///
|
||||
/// Missing nodes are inserted by the parser in order to recover from certain kinds of
|
||||
/// syntax errors.
|
||||
/// Missing nodes are inserted by the parser in order to recover from
|
||||
/// certain kinds of syntax errors.
|
||||
#[doc(alias = "ts_node_is_missing")]
|
||||
#[must_use]
|
||||
pub fn is_missing(&self) -> bool {
|
||||
|
|
@ -1115,8 +1123,8 @@ impl<'tree> Node<'tree> {
|
|||
self.start_byte()..self.end_byte()
|
||||
}
|
||||
|
||||
/// Get the range of source code that this node represents, both in terms of raw bytes
|
||||
/// and of row/column coordinates.
|
||||
/// Get the range of source code that this node represents, both in terms of
|
||||
/// raw bytes and of row/column coordinates.
|
||||
#[must_use]
|
||||
pub fn range(&self) -> Range {
|
||||
Range {
|
||||
|
|
@ -1202,8 +1210,8 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Get this node's child with the given numerical field id.
|
||||
///
|
||||
/// See also [`child_by_field_name`](Node::child_by_field_name). You can convert a field name to
|
||||
/// an id using [`Language::field_id_for_name`].
|
||||
/// See also [`child_by_field_name`](Node::child_by_field_name). You can
|
||||
/// convert a field name to an id using [`Language::field_id_for_name`].
|
||||
#[doc(alias = "ts_node_child_by_field_id")]
|
||||
#[must_use]
|
||||
pub fn child_by_field_id(&self, field_id: u16) -> Option<Self> {
|
||||
|
|
@ -1223,12 +1231,12 @@ impl<'tree> Node<'tree> {
|
|||
/// Iterate over this node's children.
|
||||
///
|
||||
/// A [`TreeCursor`] is used to retrieve the children efficiently. Obtain
|
||||
/// a [`TreeCursor`] by calling [`Tree::walk`] or [`Node::walk`]. To avoid unnecessary
|
||||
/// allocations, you should reuse the same cursor for subsequent calls to
|
||||
/// this method.
|
||||
/// a [`TreeCursor`] by calling [`Tree::walk`] or [`Node::walk`]. To avoid
|
||||
/// unnecessary allocations, you should reuse the same cursor for
|
||||
/// subsequent calls to this method.
|
||||
///
|
||||
/// If you're walking the tree recursively, you may want to use the [`TreeCursor`]
|
||||
/// APIs directly instead.
|
||||
/// If you're walking the tree recursively, you may want to use the
|
||||
/// [`TreeCursor`] APIs directly instead.
|
||||
pub fn children<'cursor>(
|
||||
&self,
|
||||
cursor: &'cursor mut TreeCursor<'tree>,
|
||||
|
|
@ -1430,11 +1438,11 @@ impl<'tree> Node<'tree> {
|
|||
|
||||
/// Edit this node to keep it in-sync with source code that has been edited.
|
||||
///
|
||||
/// This function is only rarely needed. When you edit a syntax tree with the
|
||||
/// [`Tree::edit`] method, all of the nodes that you retrieve from the tree
|
||||
/// afterward will already reflect the edit. You only need to use [`Node::edit`]
|
||||
/// when you have a specific [`Node`] instance that you want to keep and continue
|
||||
/// to use after an edit.
|
||||
/// This function is only rarely needed. When you edit a syntax tree with
|
||||
/// the [`Tree::edit`] method, all of the nodes that you retrieve from
|
||||
/// the tree afterward will already reflect the edit. You only need to
|
||||
/// use [`Node::edit`] when you have a specific [`Node`] instance that
|
||||
/// you want to keep and continue to use after an edit.
|
||||
#[doc(alias = "ts_node_edit")]
|
||||
pub fn edit(&mut self, edit: &InputEdit) {
|
||||
let edit = edit.into();
|
||||
|
|
@ -1535,8 +1543,8 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
|
||||
/// Move this cursor to the first child of its current node.
|
||||
///
|
||||
/// This returns `true` if the cursor successfully moved, and returns `false`
|
||||
/// if there were no children.
|
||||
/// This returns `true` if the cursor successfully moved, and returns
|
||||
/// `false` if there were no children.
|
||||
#[doc(alias = "ts_tree_cursor_goto_first_child")]
|
||||
pub fn goto_first_child(&mut self) -> bool {
|
||||
unsafe { ffi::ts_tree_cursor_goto_first_child(&mut self.0) }
|
||||
|
|
@ -1557,8 +1565,9 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
|
||||
/// Move this cursor to the parent of its current node.
|
||||
///
|
||||
/// This returns `true` if the cursor successfully moved, and returns `false`
|
||||
/// if there was no parent node (the cursor was already on the root node).
|
||||
/// This returns `true` if the cursor successfully moved, and returns
|
||||
/// `false` if there was no parent node (the cursor was already on the
|
||||
/// root node).
|
||||
#[doc(alias = "ts_tree_cursor_goto_parent")]
|
||||
pub fn goto_parent(&mut self) -> bool {
|
||||
unsafe { ffi::ts_tree_cursor_goto_parent(&mut self.0) }
|
||||
|
|
@ -1566,8 +1575,8 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
|
||||
/// Move this cursor to the next sibling of its current node.
|
||||
///
|
||||
/// This returns `true` if the cursor successfully moved, and returns `false`
|
||||
/// if there was no next sibling node.
|
||||
/// This returns `true` if the cursor successfully moved, and returns
|
||||
/// `false` if there was no next sibling node.
|
||||
#[doc(alias = "ts_tree_cursor_goto_next_sibling")]
|
||||
pub fn goto_next_sibling(&mut self) -> bool {
|
||||
unsafe { ffi::ts_tree_cursor_goto_next_sibling(&mut self.0) }
|
||||
|
|
@ -1596,11 +1605,11 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
unsafe { ffi::ts_tree_cursor_goto_previous_sibling(&mut self.0) }
|
||||
}
|
||||
|
||||
/// Move this cursor to the first child of its current node that extends beyond
|
||||
/// the given byte offset.
|
||||
/// Move this cursor to the first child of its current node that extends
|
||||
/// beyond the given byte offset.
|
||||
///
|
||||
/// This returns the index of the child node if one was found, and returns `None`
|
||||
/// if no such child was found.
|
||||
/// This returns the index of the child node if one was found, and returns
|
||||
/// `None` if no such child was found.
|
||||
#[doc(alias = "ts_tree_cursor_goto_first_child_for_byte")]
|
||||
pub fn goto_first_child_for_byte(&mut self, index: usize) -> Option<usize> {
|
||||
let result =
|
||||
|
|
@ -1608,11 +1617,11 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
(result >= 0).then_some(result as usize)
|
||||
}
|
||||
|
||||
/// Move this cursor to the first child of its current node that extends beyond
|
||||
/// the given byte offset.
|
||||
/// Move this cursor to the first child of its current node that extends
|
||||
/// beyond the given byte offset.
|
||||
///
|
||||
/// This returns the index of the child node if one was found, and returns `None`
|
||||
/// if no such child was found.
|
||||
/// This returns the index of the child node if one was found, and returns
|
||||
/// `None` if no such child was found.
|
||||
#[doc(alias = "ts_tree_cursor_goto_first_child_for_point")]
|
||||
pub fn goto_first_child_for_point(&mut self, point: Point) -> Option<usize> {
|
||||
let result =
|
||||
|
|
@ -1628,10 +1637,10 @@ impl<'cursor> TreeCursor<'cursor> {
|
|||
|
||||
/// Re-initialize a tree cursor to the same position as another cursor.
|
||||
///
|
||||
/// Unlike [`reset`](TreeCursor::reset), this will not lose parent information and
|
||||
/// allows reusing already created cursors.
|
||||
/// Unlike [`reset`](TreeCursor::reset), this will not lose parent
|
||||
/// information and allows reusing already created cursors.
|
||||
#[doc(alias = "ts_tree_cursor_reset_to")]
|
||||
pub fn reset_to(&mut self, cursor: &TreeCursor<'cursor>) {
|
||||
pub fn reset_to(&mut self, cursor: &Self) {
|
||||
unsafe { ffi::ts_tree_cursor_reset_to(&mut self.0, &cursor.0) };
|
||||
}
|
||||
}
|
||||
|
|
@ -1690,8 +1699,8 @@ impl LookaheadIterator {
|
|||
|
||||
/// Reset the lookahead iterator to another state.
|
||||
///
|
||||
/// This returns `true` if the iterator was reset to the given state and `false`
|
||||
/// otherwise.
|
||||
/// This returns `true` if the iterator was reset to the given state and
|
||||
/// `false` otherwise.
|
||||
#[doc(alias = "ts_lookahead_iterator_reset_state")]
|
||||
pub fn reset_state(&mut self, state: u16) -> bool {
|
||||
unsafe { ffi::ts_lookahead_iterator_reset_state(self.0.as_ptr(), state) }
|
||||
|
|
@ -2107,7 +2116,8 @@ impl Query {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
/// Get the byte offset where the given pattern starts in the query's source.
|
||||
/// Get the byte offset where the given pattern starts in the query's
|
||||
/// source.
|
||||
#[doc(alias = "ts_query_start_byte_for_pattern")]
|
||||
#[must_use]
|
||||
pub fn start_byte_for_pattern(&self, pattern_index: usize) -> usize {
|
||||
|
|
@ -2179,8 +2189,8 @@ impl Query {
|
|||
|
||||
/// Disable a certain capture within a query.
|
||||
///
|
||||
/// This prevents the capture from being returned in matches, and also avoids any
|
||||
/// resource usage associated with recording the capture.
|
||||
/// This prevents the capture from being returned in matches, and also
|
||||
/// avoids any resource usage associated with recording the capture.
|
||||
#[doc(alias = "ts_query_disable_capture")]
|
||||
pub fn disable_capture(&mut self, name: &str) {
|
||||
unsafe {
|
||||
|
|
@ -2194,8 +2204,8 @@ impl Query {
|
|||
|
||||
/// Disable a certain pattern within a query.
|
||||
///
|
||||
/// This prevents the pattern from matching, and also avoids any resource usage
|
||||
/// associated with the pattern.
|
||||
/// This prevents the pattern from matching, and also avoids any resource
|
||||
/// usage associated with the pattern.
|
||||
#[doc(alias = "ts_query_disable_pattern")]
|
||||
pub fn disable_pattern(&mut self, index: usize) {
|
||||
unsafe { ffi::ts_query_disable_pattern(self.ptr.as_ptr(), index as u32) }
|
||||
|
|
@ -2217,8 +2227,8 @@ impl Query {
|
|||
|
||||
/// Check if a given step in a query is 'definite'.
|
||||
///
|
||||
/// A query step is 'definite' if its parent pattern will be guaranteed to match
|
||||
/// successfully once it reaches the step.
|
||||
/// A query step is 'definite' if its parent pattern will be guaranteed to
|
||||
/// match successfully once it reaches the step.
|
||||
#[doc(alias = "ts_query_is_pattern_guaranteed_at_step")]
|
||||
#[must_use]
|
||||
pub fn is_pattern_guaranteed_at_step(&self, byte_offset: usize) -> bool {
|
||||
|
|
@ -2295,7 +2305,8 @@ impl Default for QueryCursor {
|
|||
impl QueryCursor {
|
||||
/// Create a new cursor for executing a given query.
|
||||
///
|
||||
/// The cursor stores the state that is needed to iteratively search for matches.
|
||||
/// The cursor stores the state that is needed to iteratively search for
|
||||
/// matches.
|
||||
#[doc(alias = "ts_query_cursor_new")]
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -2311,8 +2322,8 @@ impl QueryCursor {
|
|||
unsafe { ffi::ts_query_cursor_match_limit(self.ptr.as_ptr()) }
|
||||
}
|
||||
|
||||
/// Set the maximum number of in-progress matches for this cursor. The limit must be > 0 and
|
||||
/// <= 65536.
|
||||
/// Set the maximum number of in-progress matches for this cursor. The
|
||||
/// limit must be > 0 and <= 65536.
|
||||
#[doc(alias = "ts_query_cursor_set_match_limit")]
|
||||
pub fn set_match_limit(&mut self, limit: u32) {
|
||||
unsafe {
|
||||
|
|
@ -2320,8 +2331,8 @@ impl QueryCursor {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check if, on its last execution, this cursor exceeded its maximum number of
|
||||
/// in-progress matches.
|
||||
/// Check if, on its last execution, this cursor exceeded its maximum number
|
||||
/// of in-progress matches.
|
||||
#[doc(alias = "ts_query_cursor_did_exceed_match_limit")]
|
||||
#[must_use]
|
||||
pub fn did_exceed_match_limit(&self) -> bool {
|
||||
|
|
@ -2330,9 +2341,10 @@ impl QueryCursor {
|
|||
|
||||
/// Iterate over all of the matches in the order that they were found.
|
||||
///
|
||||
/// Each match contains the index of the pattern that matched, and a list of captures.
|
||||
/// Because multiple patterns can match the same set of nodes, one match may contain
|
||||
/// captures that appear *before* some of the captures from a previous match.
|
||||
/// Each match contains the index of the pattern that matched, and a list of
|
||||
/// captures. Because multiple patterns can match the same set of nodes,
|
||||
/// one match may contain captures that appear *before* some of the
|
||||
/// captures from a previous match.
|
||||
#[doc(alias = "ts_query_cursor_exec")]
|
||||
pub fn matches<'query, 'cursor: 'query, 'tree, T: TextProvider<I>, I: AsRef<[u8]>>(
|
||||
&'cursor mut self,
|
||||
|
|
@ -2352,10 +2364,11 @@ impl QueryCursor {
|
|||
}
|
||||
}
|
||||
|
||||
/// Iterate over all of the individual captures in the order that they appear.
|
||||
/// Iterate over all of the individual captures in the order that they
|
||||
/// appear.
|
||||
///
|
||||
/// This is useful if you don't care about which pattern matched, and just want a single,
|
||||
/// ordered sequence of captures.
|
||||
/// This is useful if you don't care about which pattern matched, and just
|
||||
/// want a single, ordered sequence of captures.
|
||||
#[doc(alias = "ts_query_cursor_exec")]
|
||||
pub fn captures<'query, 'cursor: 'query, 'tree, T: TextProvider<I>, I: AsRef<[u8]>>(
|
||||
&'cursor mut self,
|
||||
|
|
@ -2375,7 +2388,8 @@ impl QueryCursor {
|
|||
}
|
||||
}
|
||||
|
||||
/// Set the range in which the query will be executed, in terms of byte offsets.
|
||||
/// Set the range in which the query will be executed, in terms of byte
|
||||
/// offsets.
|
||||
#[doc(alias = "ts_query_cursor_set_byte_range")]
|
||||
pub fn set_byte_range(&mut self, range: ops::Range<usize>) -> &mut Self {
|
||||
unsafe {
|
||||
|
|
@ -2388,7 +2402,8 @@ impl QueryCursor {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set the range in which the query will be executed, in terms of rows and columns.
|
||||
/// Set the range in which the query will be executed, in terms of rows and
|
||||
/// columns.
|
||||
#[doc(alias = "ts_query_cursor_set_point_range")]
|
||||
pub fn set_point_range(&mut self, range: ops::Range<Point>) -> &mut Self {
|
||||
unsafe {
|
||||
|
|
@ -2404,13 +2419,15 @@ impl QueryCursor {
|
|||
/// Set the maximum start depth for a query cursor.
|
||||
///
|
||||
/// This prevents cursors from exploring children nodes at a certain depth.
|
||||
/// Note if a pattern includes many children, then they will still be checked.
|
||||
/// Note if a pattern includes many children, then they will still be
|
||||
/// checked.
|
||||
///
|
||||
/// The zero max start depth value can be used as a special behavior and
|
||||
/// it helps to destructure a subtree by staying on a node and using captures
|
||||
/// for interested parts. Note that the zero max start depth only limit a search
|
||||
/// depth for a pattern's root node but other nodes that are parts of the pattern
|
||||
/// may be searched at any depth what defined by the pattern structure.
|
||||
/// it helps to destructure a subtree by staying on a node and using
|
||||
/// captures for interested parts. Note that the zero max start depth
|
||||
/// only limit a search depth for a pattern's root node but other nodes
|
||||
/// that are parts of the pattern may be searched at any depth what
|
||||
/// defined by the pattern structure.
|
||||
///
|
||||
/// Set to `None` to remove the maximum start depth.
|
||||
#[doc(alias = "ts_query_cursor_set_max_start_depth")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue