diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 4f5bef19..6d240c52 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -62,8 +62,8 @@ impl Config { /// /// - Location specified by the path parameter if provided /// - `$TREE_SITTER_DIR/config.json`, if the `TREE_SITTER_DIR` environment variable is set - /// - `tree-sitter/config.json` in your default user configuration directory, as determined - /// by [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html) + /// - `tree-sitter/config.json` in your default user configuration directory, as determined by + /// [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html) /// - `$HOME/.tree-sitter/config.json` as a fallback from where tree-sitter _used_ to store /// its configuration pub fn load(path: Option) -> Result { diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 52c89387..9d36d9e3 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -503,7 +503,8 @@ impl Loader { if let Ok(lock_file) = fs::OpenOptions::new().write(true).open(&lock_path) { recompile = false; if lock_file.try_lock_exclusive().is_err() { - // if we can't acquire the lock, another process is compiling the parser, wait for it and don't recompile + // if we can't acquire the lock, another process is compiling the parser, wait for + // it and don't recompile lock_file.lock_exclusive()?; recompile = false; } else { diff --git a/cli/src/generate/build_tables/item_set_builder.rs b/cli/src/generate/build_tables/item_set_builder.rs index 13cf2847..ff0323c5 100644 --- a/cli/src/generate/build_tables/item_set_builder.rs +++ b/cli/src/generate/build_tables/item_set_builder.rs @@ -75,8 +75,8 @@ impl<'a> ParseItemSetBuilder<'a> { // The FIRST set of a non-terminal `i` is the union of the following sets: // * the set of all terminals that appear at the beginnings of i's productions - // * the FIRST sets of all the non-terminals that appear at the beginnings - // of i's productions + // * the FIRST sets of all the non-terminals that appear at the beginnings of i's + // productions // // Rather than computing these sets using recursion, we use an explicit stack // called `symbols_to_process`. @@ -135,11 +135,11 @@ impl<'a> ParseItemSetBuilder<'a> { // item set when `i` occurs as the next symbol in one if its core items. The // structure of an *addition* is as follows: // * `item` - the new item that must be added as part of the expansion of `i` - // * `lookaheads` - lookahead tokens that can always come after that item in - // the expansion of `i` - // * `propagates_lookaheads` - a boolean indicating whether or not `item` can - // occur at the *end* of the expansion of `i`, so that i's own current - // lookahead tokens can occur after `item`. + // * `lookaheads` - lookahead tokens that can always come after that item in the expansion + // of `i` + // * `propagates_lookaheads` - a boolean indicating whether or not `item` can occur at the + // *end* of the expansion of `i`, so that i's own current lookahead tokens can occur + // after `item`. // // Again, rather than computing these additions recursively, we use an explicit // stack called `entries_to_process`. diff --git a/cli/src/generate/node_types.rs b/cli/src/generate/node_types.rs index 114bf900..25353e8c 100644 --- a/cli/src/generate/node_types.rs +++ b/cli/src/generate/node_types.rs @@ -140,18 +140,17 @@ impl ChildQuantity { /// * `types` - The types of visible children the field can contain. /// * `optional` - Do `N` nodes always have this field? /// * `multiple` - Can `N` nodes have multiple children for this field? -/// 3. `children_without_fields` - The *other* named children of `N` that are -/// not associated with fields. Data regarding these children: +/// 3. `children_without_fields` - The *other* named children of `N` that are not associated with +/// fields. Data regarding these children: /// * `types` - The types of named children with no field. /// * `optional` - Do `N` nodes always have at least one named child with no field? /// * `multiple` - Can `N` nodes have multiple named children with no field? /// /// Each summary must account for some indirect factors: -/// 1. hidden nodes. When a parent node `N` has a hidden child `C`, the visible -/// children of `C` *appear* to be direct children of `N`. -/// 2. aliases. If a parent node type `M` is aliased as some other type `N`, -/// then nodes which *appear* to have type `N` may have internal structure based -/// on `M`. +/// 1. hidden nodes. When a parent node `N` has a hidden child `C`, the visible children of `C` +/// *appear* to be direct children of `N`. +/// 2. aliases. If a parent node type `M` is aliased as some other type `N`, then nodes which +/// *appear* to have type `N` may have internal structure based on `M`. pub fn get_variable_info( syntax_grammar: &SyntaxGrammar, lexical_grammar: &LexicalGrammar, @@ -224,7 +223,8 @@ pub fn get_variable_info( .entry(field_name) .or_insert_with(ChildQuantity::zero); - // Inherit the types and quantities of hidden children associated with fields. + // Inherit the types and quantities of hidden children associated with + // fields. if child_is_hidden && child_symbol.is_non_terminal() { let child_variable_info = &result[child_symbol.index]; did_change |= extend_sorted( @@ -529,8 +529,8 @@ pub fn generate_node_types_json( let fields_json = node_type_json.fields.as_mut().unwrap(); for (new_field, field_info) in &info.fields { let field_json = fields_json.entry(new_field.clone()).or_insert_with(|| { - // If another rule is aliased with the same name, and does *not* have this field, - // then this field cannot be required. + // If another rule is aliased with the same name, and does *not* have this + // field, then this field cannot be required. let mut field_json = FieldInfoJSON::default(); if node_type_existed { field_json.required = false; @@ -540,8 +540,8 @@ pub fn generate_node_types_json( populate_field_info_json(field_json, field_info); } - // If another rule is aliased with the same name, any fields that aren't present in this - // cannot be required. + // If another rule is aliased with the same name, any fields that aren't present in + // this cannot be required. for (existing_field, field_json) in fields_json.iter_mut() { if !info.fields.contains_key(existing_field) { field_json.required = false; diff --git a/cli/src/generate/prepare_grammar/extract_default_aliases.rs b/cli/src/generate/prepare_grammar/extract_default_aliases.rs index b08761d5..68317913 100644 --- a/cli/src/generate/prepare_grammar/extract_default_aliases.rs +++ b/cli/src/generate/prepare_grammar/extract_default_aliases.rs @@ -16,8 +16,8 @@ struct SymbolStatus { // This has two benefits: // * It reduces the overhead of storing production-specific alias info in the parse table. // * Within an `ERROR` node, no context-specific aliases will be applied. This transformation -// ensures that the children of an `ERROR` node have symbols that are consistent with the -// way that they would appear in a valid syntax tree. +// ensures that the children of an `ERROR` node have symbols that are consistent with the way that +// they would appear in a valid syntax tree. pub(super) fn extract_default_aliases( syntax_grammar: &mut SyntaxGrammar, lexical_grammar: &LexicalGrammar, @@ -164,10 +164,10 @@ pub(super) fn extract_default_aliases( #[cfg(test)] mod tests { use super::*; - use crate::generate::grammars::{ - LexicalVariable, Production, ProductionStep, SyntaxVariable, VariableType, + use crate::generate::{ + grammars::{LexicalVariable, Production, ProductionStep, SyntaxVariable, VariableType}, + nfa::Nfa, }; - use crate::generate::nfa::Nfa; #[test] fn test_extract_simple_aliases() { diff --git a/cli/src/generate/render.rs b/cli/src/generate/render.rs index 7d62a8ef..f119e0a4 100644 --- a/cli/src/generate/render.rs +++ b/cli/src/generate/render.rs @@ -178,8 +178,8 @@ impl Generator { } // Two anonymous tokens with different flags but the same string value // should be represented with the same symbol in the public API. Examples: - // * "<" and token(prec(1, "<")) - // * "(" and token.immediate("(") + // * "<" and token(prec(1, "<")) + // * "(" and token.immediate("(") else if symbol.is_terminal() { let metadata = self.metadata_for_symbol(*symbol); for other_symbol in &self.parse_table.symbols { @@ -225,7 +225,8 @@ impl Generator { if let Some(existing_symbol) = existing_symbol { alias_id = self.symbol_ids[&self.symbol_map[&existing_symbol]].clone(); } - // Other aliases don't match any existing symbol, and need their own identifiers. + // Other aliases don't match any existing symbol, and need their own + // identifiers. else { if let Err(i) = self.unique_aliases.binary_search(alias) { self.unique_aliases.insert(i, alias.clone()); @@ -1674,16 +1675,15 @@ impl Generator { /// * `parse_table` - The generated parse table for the language /// * `main_lex_table` - The generated lexing table for the language /// * `keyword_lex_table` - The generated keyword lexing table for the language -/// * `keyword_capture_token` - A symbol indicating which token is used -/// for keyword capture, if any. +/// * `keyword_capture_token` - A symbol indicating which token is used for keyword capture, if any. /// * `syntax_grammar` - The syntax grammar extracted from the language's grammar /// * `lexical_grammar` - The lexical grammar extracted from the language's grammar -/// * `default_aliases` - A map describing the global rename rules that should apply. -/// the keys are symbols that are *always* aliased in the same way, and the values -/// are the aliases that are applied to those symbols. -/// * `abi_version` - The language ABI version that should be generated. Usually -/// you want Tree-sitter's current version, but right after making an ABI -/// change, it may be useful to generate code with the previous ABI. +/// * `default_aliases` - A map describing the global rename rules that should apply. the keys are +/// symbols that are *always* aliased in the same way, and the values are the aliases that are +/// applied to those symbols. +/// * `abi_version` - The language ABI version that should be generated. Usually you want +/// Tree-sitter's current version, but right after making an ABI change, it may be useful to +/// generate code with the previous ABI. #[allow(clippy::too_many_arguments)] pub fn render_c_code( name: &str, diff --git a/cli/src/test.rs b/cli/src/test.rs index 2764cf22..fd03e247 100644 --- a/cli/src/test.rs +++ b/cli/src/test.rs @@ -306,13 +306,15 @@ fn run_tests( let expected_output = format_sexp(&output, 0); let actual_output = format_sexp(&actual, 0); - // Only bail early before updating if the actual is not the output, sometimes - // users want to test cases that are intended to have errors, hence why this + // Only bail early before updating if the actual is not the output, + // sometimes users want to test cases that + // are intended to have errors, hence why this // check isn't shown above if actual.contains("ERROR") || actual.contains("MISSING") { *has_parse_errors = true; - // keep the original `expected` output if the actual output has an error + // keep the original `expected` output if the actual output has an + // error corrected_entries.push(( name.clone(), input, diff --git a/cli/src/tests/node_test.rs b/cli/src/tests/node_test.rs index 5e50beaf..59010e26 100644 --- a/cli/src/tests/node_test.rs +++ b/cli/src/tests/node_test.rs @@ -850,10 +850,11 @@ fn test_node_numeric_symbols_respect_simple_aliases() { parser.set_language(&get_language("python")).unwrap(); // Example 1: - // Python argument lists can contain "splat" arguments, which are not allowed within - // other expressions. This includes `parenthesized_list_splat` nodes like `(*b)`. These - // `parenthesized_list_splat` nodes are aliased as `parenthesized_expression`. Their numeric - // `symbol`, aka `kind_id` should match that of a normal `parenthesized_expression`. + // Python argument lists can contain "splat" arguments, which are not allowed + // within other expressions. This includes `parenthesized_list_splat` nodes + // like `(*b)`. These `parenthesized_list_splat` nodes are aliased as + // `parenthesized_expression`. Their numeric `symbol`, aka `kind_id` should + // match that of a normal `parenthesized_expression`. let tree = parser.parse("(a((*b)))", None).unwrap(); let root = tree.root_node(); assert_eq!( @@ -875,9 +876,9 @@ fn test_node_numeric_symbols_respect_simple_aliases() { assert_eq!(inner_expr_node.kind_id(), outer_expr_node.kind_id()); // Example 2: - // Ruby handles the unary (negative) and binary (minus) `-` operators using two different - // tokens. One or more of these is an external token that's aliased as `-`. Their numeric - // kind ids should match. + // Ruby handles the unary (negative) and binary (minus) `-` operators using two + // different tokens. One or more of these is an external token that's + // aliased as `-`. Their numeric kind ids should match. parser.set_language(&get_language("ruby")).unwrap(); let tree = parser.parse("-a - b", None).unwrap(); let root = tree.root_node(); diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 39a4c986..82ca1b43 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -891,12 +891,12 @@ fn test_query_matches_with_immediate_siblings() { let language = get_language("python"); // The immediate child operator '.' can be used in three similar ways: - // 1. Before the first child node in a pattern, it means that there cannot be any - // named siblings before that child node. + // 1. Before the first child node in a pattern, it means that there cannot be any named + // siblings before that child node. // 2. After the last child node in a pattern, it means that there cannot be any named // sibling after that child node. - // 2. Between two child nodes in a pattern, it specifies that there cannot be any - // named siblings between those two child snodes. + // 2. Between two child nodes in a pattern, it specifies that there cannot be any named + // siblings between those two child snodes. let query = Query::new( &language, " @@ -1425,7 +1425,8 @@ fn test_query_matches_with_nested_optional_nodes() { allocations::record(|| { let language = get_language("javascript"); - // A function call, optionally containing a function call, which optionally contains a number + // A function call, optionally containing a function call, which optionally contains a + // number let query = Query::new( &language, " @@ -3269,8 +3270,8 @@ fn test_query_captures_with_too_many_nested_results() { // appearance. // 2. This pattern captures the root `call_expression`. // 3. This pattern's result also depends on the final child (the template string). - // 4. In between the `call_expression` and the possible `template_string`, there can - // be an arbitrarily deep subtree. + // 4. In between the `call_expression` and the possible `template_string`, there can be an + // arbitrarily deep subtree. // // This means that, if any patterns match *after* the initial `call_expression` is // captured, but before the final `template_string` is found, those matches must diff --git a/highlight/src/c_lib.rs b/highlight/src/c_lib.rs index 6fd385b9..bf291c98 100644 --- a/highlight/src/c_lib.rs +++ b/highlight/src/c_lib.rs @@ -72,8 +72,8 @@ pub unsafe extern "C" fn ts_highlighter_new( /// `this` must be non-null and must be a valid pointer to a [`TSHighlighter`] instance /// created by [`ts_highlighter_new`]. /// -/// The caller must ensure that any `*const c_char` (C-style string) parameters are valid for the lifetime of -/// the [`TSHighlighter`] instance, and are non-null. +/// The caller must ensure that any `*const c_char` (C-style string) parameters are valid for the +/// lifetime of the [`TSHighlighter`] instance, and are non-null. #[no_mangle] pub unsafe extern "C" fn ts_highlighter_add_language( this: *mut TSHighlighter, @@ -188,8 +188,8 @@ pub unsafe extern "C" fn ts_highlight_buffer_delete(this: *mut TSHighlightBuffer /// `this` must be non-null and must be a valid pointer to a [`TSHighlightBuffer`] instance /// created by [`ts_highlight_buffer_new`]. /// -/// The returned pointer, a C-style string, must not outlive the [`TSHighlightBuffer`] instance, else the -/// data will point to garbage. +/// The returned pointer, a C-style string, must not outlive the [`TSHighlightBuffer`] instance, +/// else the data will point to garbage. /// /// To get the length of the HTML content, use [`ts_highlight_buffer_len`]. #[no_mangle] @@ -205,8 +205,8 @@ pub unsafe extern "C" fn ts_highlight_buffer_content(this: *const TSHighlightBuf /// `this` must be non-null and must be a valid pointer to a [`TSHighlightBuffer`] instance /// created by [`ts_highlight_buffer_new`]. /// -/// The returned pointer, a C-style array of [`u32`]s, must not outlive the [`TSHighlightBuffer`] instance, else the -/// data will point to garbage. +/// The returned pointer, a C-style array of [`u32`]s, must not outlive the [`TSHighlightBuffer`] +/// instance, else the data will point to garbage. /// /// To get the length of the array, use [`ts_highlight_buffer_line_count`]. #[no_mangle] @@ -245,10 +245,11 @@ pub unsafe extern "C" fn ts_highlight_buffer_line_count(this: *const TSHighlight /// /// # Safety /// -/// The caller must ensure that `scope_name`, `source_code`, `output`, and `cancellation_flag` are valid for -/// the lifetime of the [`TSHighlighter`] instance, and are non-null. +/// The caller must ensure that `scope_name`, `source_code`, `output`, and `cancellation_flag` are +/// valid for the lifetime of the [`TSHighlighter`] instance, and are non-null. /// -/// `this` must be a non-null pointer to a [`TSHighlighter`] instance created by [`ts_highlighter_new`] +/// `this` must be a non-null pointer to a [`TSHighlighter`] instance created by +/// [`ts_highlighter_new`] #[no_mangle] pub unsafe extern "C" fn ts_highlighter_highlight( this: *const TSHighlighter, diff --git a/highlight/src/lib.rs b/highlight/src/lib.rs index 192b90d9..e7ade514 100644 --- a/highlight/src/lib.rs +++ b/highlight/src/lib.rs @@ -248,10 +248,10 @@ impl HighlightConfiguration { /// * `language` - The Tree-sitter `Language` that should be used for parsing. /// * `highlights_query` - A string containing tree patterns for syntax highlighting. This /// should be non-empty, otherwise no syntax highlights will be added. - /// * `injections_query` - A string containing tree patterns for injecting other languages - /// into the document. This can be empty if no injections are desired. - /// * `locals_query` - A string containing tree patterns for tracking local variable - /// definitions and references. This can be empty if local variable tracking is not needed. + /// * `injections_query` - A string containing tree patterns for injecting other languages into + /// the document. This can be empty if no injections are desired. + /// * `locals_query` - A string containing tree patterns for tracking local variable definitions + /// and references. This can be empty if local variable tracking is not needed. /// /// Returns a `HighlightConfiguration` that can then be used with the `highlight` method. pub fn new( @@ -401,8 +401,8 @@ impl HighlightConfiguration { } // Return the list of this configuration's capture names that are neither present in the - // list of predefined 'canonical' names nor start with an underscore (denoting 'private' captures - // used as part of capture internals). + // list of predefined 'canonical' names nor start with an underscore (denoting 'private' + // captures used as part of capture internals). #[must_use] pub fn nonconformant_capture_names(&self, capture_names: &HashSet<&str>) -> Vec<&str> { let capture_names = if capture_names.is_empty() { @@ -534,12 +534,12 @@ impl<'a> HighlightIterLayer<'a> { // Compute the ranges that should be included when parsing an injection. // This takes into account three things: // * `parent_ranges` - The ranges must all fall within the *current* layer's ranges. - // * `nodes` - Every injection takes place within a set of nodes. The injection ranges - // are the ranges of those nodes. - // * `includes_children` - For some injections, the content nodes' children should be - // excluded from the nested document, so that only the content nodes' *own* content - // is reparsed. For other injections, the content nodes' entire ranges should be - // reparsed, including the ranges of their children. + // * `nodes` - Every injection takes place within a set of nodes. The injection ranges are the + // ranges of those nodes. + // * `includes_children` - For some injections, the content nodes' children should be excluded + // from the nested document, so that only the content nodes' *own* content is reparsed. For + // other injections, the content nodes' entire ranges should be reparsed, including the ranges + // of their children. fn intersect_ranges( parent_ranges: &[Range], nodes: &[Node], diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 2928f1cd..08f466ed 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -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); -/// 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); 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, 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) = (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, 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) = (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 { @@ -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 { @@ -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 { 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 { 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: 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: 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) -> &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) -> &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")] diff --git a/tags/src/lib.rs b/tags/src/lib.rs index d8dad5c6..a1c7596a 100644 --- a/tags/src/lib.rs +++ b/tags/src/lib.rs @@ -286,8 +286,9 @@ impl TagsContext { unsafe { self.parser.set_cancellation_flag(cancellation_flag) }; let tree = self.parser.parse(source, None).ok_or(Error::Cancelled)?; - // The `matches` iterator borrows the `Tree`, which prevents it from being moved. - // But the tree is really just a pointer, so it's actually ok to move it. + // The `matches` iterator borrows the `Tree`, which prevents it from being + // moved. But the tree is really just a pointer, so it's actually ok to + // move it. let tree_ref = unsafe { mem::transmute::<_, &'static Tree>(&tree) }; let matches = self .cursor @@ -461,7 +462,8 @@ where } } - // Generate a doc string from all of the doc nodes, applying any strip regexes. + // Generate a doc string from all of the doc nodes, applying any strip + // regexes. let mut docs = None; for doc_node in &doc_nodes[docs_start_index..] { if let Ok(content) = str::from_utf8(&self.source[doc_node.byte_range()]) @@ -484,8 +486,9 @@ where let range = rng.start.min(name_range.start)..rng.end.max(name_range.end); let span = name_node.start_position()..name_node.end_position(); - // Compute tag properties that depend on the text of the containing line. If the - // previous tag occurred on the same line, then reuse results from the previous tag. + // Compute tag properties that depend on the text of the containing line. If + // the previous tag occurred on the same line, then + // reuse results from the previous tag. let line_range; let mut prev_utf16_column = 0; let mut prev_utf8_byte = name_range.start - span.start.column;