### Get tree-sitter-rust Syntax Highlighting Query Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `HIGHLIGHTS_QUERY` constant, which contains the syntax highlighting query for the Rust language grammar. This query is used by tree-sitter to apply syntax highlighting to Rust code. ```Rust /// The syntax highlighting query for this language. pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); ``` -------------------------------- ### GET /grammar/macro_invocation Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=u32+-%3E+bool Retrieves the structure definition for a Rust macro invocation node. ```APIDOC ## GET /grammar/macro_invocation ### Description Defines the structure of a macro invocation in Rust, requiring a macro identifier and token tree children. ### Method GET ### Endpoint /grammar/macro_invocation ### Parameters #### Request Body - **macro** (identifier/scoped_identifier) - Required - The name of the macro being invoked. - **children** (token_tree) - Required - The arguments passed to the macro. ### Request Example { "macro": "println!", "children": "token_tree_data" } ### Response #### Success Response (200) - **type** (string) - "macro_invocation" #### Response Example { "type": "macro_invocation", "named": true } ``` -------------------------------- ### GET /grammar/enum_item Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=u32+-%3E+bool Retrieves the structural definition for a Rust enum item. ```APIDOC ## GET /grammar/enum_item ### Description Returns the schema definition for an 'enum_item' node, including its required name, body, and optional type parameters. ### Method GET ### Endpoint /grammar/enum_item ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **type** (string) - The node type identifier - **fields** (object) - The fields associated with the enum (name, body, type_parameters) #### Response Example { "type": "enum_item", "named": true, "fields": { "body": { "required": true, "types": [{"type": "enum_variant_list"}] }, "name": { "required": true, "types": [{"type": "type_identifier"}] } } } ``` -------------------------------- ### GET /syntax/field_initializer Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=std%3A%3Avec Retrieves the schema definition for field initializers used in struct instantiation. ```APIDOC ## GET /syntax/field_initializer ### Description Defines the structure for initializing a field in a struct, mapping a field identifier to an expression. ### Method GET ### Endpoint /syntax/field_initializer ### Parameters #### Request Body - **field** (field_identifier/integer_literal) - Required - The field being initialized. - **value** (_expression) - Required - The value assigned to the field. ### Request Example { "type": "field_initializer", "named": true } ### Response #### Success Response (200) - **fields** (object) - Contains field and value mappings. - **children** (object) - Contains optional attribute_item. #### Response Example { "type": "field_initializer", "fields": { "field": { "required": true, "types": [{"type": "field_identifier"}] }, "value": { "required": true, "types": [{"type": "_expression"}] } } } ``` -------------------------------- ### GET /tree_sitter_rust/LANGUAGE Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.LANGUAGE.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the LanguageFn constant required to initialize the Rust grammar parser in tree-sitter. ```APIDOC ## GET /tree_sitter_rust/LANGUAGE ### Description Returns the `LanguageFn` constant for the Rust grammar. This is the entry point for using the tree-sitter-rust parser. ### Method GET ### Endpoint `tree_sitter_rust::LANGUAGE` ### Parameters None ### Request Example N/A (Rust constant access) ### Response #### Success Response (200) - **LANGUAGE** (LanguageFn) - The tree-sitter Language function for the Rust grammar. #### Response Example ```rust use tree_sitter::Parser; let mut parser = Parser::new(); parser.set_language(&tree_sitter_rust::LANGUAGE).expect("Error loading Rust grammar"); ``` ``` -------------------------------- ### GET /grammar/extern_crate_declaration Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= Retrieves the schema definition for an extern crate declaration node. ```APIDOC ## GET /grammar/extern_crate_declaration ### Description Returns the structure of an extern_crate_declaration node, representing the import of an external crate. ### Method GET ### Endpoint /grammar/extern_crate_declaration ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **name** (identifier) - Required - The name of the crate. - **alias** (identifier) - Optional - An optional alias for the crate. #### Response Example { "type": "extern_crate_declaration", "named": true, "fields": { "name": {"required": true, "types": [{"type": "identifier"}]}, "alias": {"required": false, "types": [{"type": "identifier"}]} } } ``` -------------------------------- ### GET /grammar/nodes/assignment_expression Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html Retrieves the structural definition for an assignment expression in Rust. ```APIDOC ## GET /grammar/nodes/assignment_expression ### Description Returns the schema definition for an assignment expression node, which includes the left-hand side and right-hand side expressions. ### Method GET ### Endpoint /grammar/nodes/assignment_expression ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **type** (string) - The node type name - **fields** (object) - Definition of child fields 'left' and 'right' #### Response Example { "type": "assignment_expression", "named": true, "fields": { "left": { "multiple": false, "required": true, "types": [{"type": "_expression", "named": true}] }, "right": { "multiple": false, "required": true, "types": [{"type": "_expression", "named": true}] } } } ``` -------------------------------- ### GET /grammar/field_declaration Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= Retrieves the schema definition for a Rust field declaration node. ```APIDOC ## GET /grammar/field_declaration ### Description Returns the structure of a field_declaration node, which includes the field name and its associated type. ### Method GET ### Endpoint /grammar/field_declaration ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **name** (field_identifier) - Required - The identifier of the field. - **type** (_type) - Required - The type definition of the field. - **visibility_modifier** (visibility_modifier) - Optional - The visibility scope of the field. #### Response Example { "type": "field_declaration", "named": true, "fields": { "name": {"required": true, "types": [{"type": "field_identifier"}]}, "type": {"required": true, "types": [{"type": "_type"}]} } } ``` -------------------------------- ### GET /grammar/node-types Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the structural definitions for Rust language nodes such as array expressions, assignments, and associated types. ```APIDOC ## GET /grammar/node-types ### Description Returns the schema definitions for specific Rust syntax nodes, detailing their fields and child node requirements. ### Method GET ### Endpoint /grammar/node-types ### Parameters #### Query Parameters - **type** (string) - Optional - Filter by specific node type (e.g., 'array_expression', 'assignment_expression') ### Request Example { "type": "assignment_expression" } ### Response #### Success Response (200) - **type** (string) - The name of the node type - **fields** (object) - Map of field names to their structural requirements - **children** (object) - Requirements for child nodes #### Response Example { "type": "assignment_expression", "named": true, "fields": { "left": { "required": true, "types": [{"type": "_expression"}] }, "right": { "required": true, "types": [{"type": "_expression"}] } } } ``` -------------------------------- ### GET /syntax/field_declaration Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=std%3A%3Avec Retrieves the schema definition for a field declaration node in a Rust struct. ```APIDOC ## GET /syntax/field_declaration ### Description Defines the structure of a field declaration within a struct or union, including visibility modifiers and type annotations. ### Method GET ### Endpoint /syntax/field_declaration ### Parameters #### Request Body - **name** (field_identifier) - Required - The name of the field. - **type** (_type) - Required - The data type of the field. ### Request Example { "type": "field_declaration", "named": true } ### Response #### Success Response (200) - **fields** (object) - Contains name and type definitions. - **children** (object) - Contains optional visibility_modifier. #### Response Example { "type": "field_declaration", "fields": { "name": { "required": true, "types": [{"type": "field_identifier"}] }, "type": { "required": true, "types": [{"type": "_type"}] } } } ``` -------------------------------- ### Get tree-sitter-rust Tags Query Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `TAGS_QUERY` constant, which contains the symbol tagging query for the Rust language grammar. This query is used by tree-sitter to identify and tag symbols within Rust code, useful for features like code navigation. ```Rust /// The symbol tagging query for this language. pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); ``` -------------------------------- ### GET /grammar/node-types Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= Retrieves the structural definition of a specific Rust syntax node type, including its fields and child requirements. ```APIDOC ## GET /grammar/node-types ### Description Retrieves the schema definition for a specific node type in the Rust grammar. This allows developers to understand the expected fields and child nodes for a given syntax element. ### Method GET ### Endpoint /grammar/node-types ### Parameters #### Query Parameters - **type** (string) - Required - The name of the node type to retrieve (e.g., 'scoped_identifier', 'reference_type'). ### Request Example GET /grammar/node-types?type=scoped_identifier ### Response #### Success Response (200) - **type** (string) - The name of the node type. - **fields** (object) - A map of field names to their structural requirements. - **children** (object) - A map defining allowed child node types and their multiplicity. #### Response Example { "type": "scoped_identifier", "named": true, "fields": { "name": { "multiple": false, "required": true, "types": [{"type": "identifier", "named": true}] } } } ``` -------------------------------- ### Get tree-sitter-rust Injections Query Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `INJECTIONS_QUERY` constant, which contains the injections query for the Rust language grammar. This query is used by tree-sitter to handle code injections within Rust code, such as embedded languages. ```Rust /// The injections query for this language. pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); ``` -------------------------------- ### GET /grammar/node-types Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the structural definition of Rust language nodes, including fields and child requirements for constructs like pointer_type, range_expression, and ref_pattern. ```APIDOC ## GET /grammar/node-types ### Description Returns the schema definitions for various Rust syntax nodes. This allows consumers to understand the expected structure, fields, and child node types for specific language constructs. ### Method GET ### Endpoint /grammar/node-types ### Parameters None ### Request Example GET /grammar/node-types ### Response #### Success Response (200) - **node_types** (array) - A list of node definitions including type, named status, fields, and children requirements. #### Response Example { "type": "pointer_type", "named": true, "fields": { "type": { "multiple": false, "required": true, "types": [{"type": "_type", "named": true}] } }, "children": { "multiple": false, "required": false, "types": [{"type": "mutable_specifier", "named": true}] } } ``` -------------------------------- ### Using tree_sitter_rust::LANGUAGE Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/index.html How to initialize a tree-sitter parser with the Rust language grammar to parse source code. ```APIDOC ## Rust Integration: Parsing Code ### Description This example demonstrates how to load the Rust language grammar into a tree-sitter Parser and parse a snippet of Rust code. ### Method N/A (Library Usage) ### Endpoint tree_sitter_rust::LANGUAGE ### Parameters #### Request Body - **code** (string) - Required - The Rust source code string to be parsed. ### Request Example let code = r#"fn double(x: i32) -> i32 { x * 2 }"#; ### Response #### Success Response (200) - **tree** (tree_sitter::Tree) - The resulting syntax tree object. #### Response Example let tree = parser.parse(code, None).unwrap(); assert!(!tree.root_node().has_error()); ``` -------------------------------- ### GET /grammar/enum_variant Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=u32+-%3E+bool Retrieves the structural definition for a Rust enum variant. ```APIDOC ## GET /grammar/enum_variant ### Description Returns the schema definition for an 'enum_variant' node, detailing its name, optional body, and optional value. ### Method GET ### Endpoint /grammar/enum_variant ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **type** (string) - The node type identifier - **fields** (object) - The fields associated with the variant (name, body, value) #### Response Example { "type": "enum_variant", "named": true, "fields": { "name": { "required": true, "types": [{"type": "identifier"}] }, "body": { "required": false, "types": [{"type": "field_declaration_list"}] } } } ``` -------------------------------- ### Parse Rust code using tree-sitter Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html Demonstrates how to initialize a tree-sitter parser with the Rust language grammar and parse a snippet of Rust source code. It verifies that the resulting tree contains no parsing errors. ```rust use tree_sitter::Parser; let code = r#" fn double(x: i32) -> i32 { x * 2 } "#; let mut parser = Parser::new(); let language = tree_sitter_rust::LANGUAGE; parser .set_language(&language.into()) .expect("Error loading Rust parser"); let tree = parser.parse(code, None).unwrap(); assert!(!tree.root_node().has_error()); ``` -------------------------------- ### GET /grammar/nodes/array_type Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html Retrieves the structural definition for an array type in Rust. ```APIDOC ## GET /grammar/nodes/array_type ### Description Returns the schema definition for an array type node, detailing the element type and optional length expression. ### Method GET ### Endpoint /grammar/nodes/array_type ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **type** (string) - The node type name - **fields** (object) - Definition of 'element' and 'length' fields #### Response Example { "type": "array_type", "named": true, "fields": { "element": { "multiple": false, "required": true, "types": [{"type": "_type", "named": true}] }, "length": { "multiple": false, "required": false, "types": [{"type": "_expression", "named": true}] } } } ``` -------------------------------- ### Rust Language Support for Tree-sitter Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search= This snippet demonstrates how to use the tree-sitter-rust crate to parse Rust code. It shows initializing a tree-sitter parser with the Rust language and parsing a sample Rust code string. ```APIDOC ## Initialize and Parse Rust Code ### Description This example shows how to initialize a `tree-sitter::Parser` with the Rust language provided by the `tree-sitter-rust` crate and then parse a Rust code snippet. ### Method Not applicable (this is a library usage example) ### Endpoint Not applicable ### Parameters Not applicable ### Request Example ```rust use tree_sitter::Parser; let code = r#"fn double(x: i32) -> i32 { x * 2 }"#; let mut parser = Parser::new(); let language = tree_sitter_rust::LANGUAGE; parser .set_language(&language.into()) .expect("Error loading Rust parser"); let tree = parser.parse(code, None).unwrap(); assert!(!tree.root_node().has_error()); ``` ### Response #### Success Response (200) Not applicable (this is a library usage example) #### Response Example Not applicable ``` -------------------------------- ### Grammar Constants Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust?search= Overview of the available constants provided by the crate for syntax highlighting, injections, and node types. ```APIDOC ## Grammar Constants ### HIGHLIGHTS_QUERY - **Type**: &str - **Description**: The syntax highlighting query for Rust. ### INJECTIONS_QUERY - **Type**: &str - **Description**: The injections query for Rust. ### NODE_TYPES - **Type**: &str - **Description**: The content of the node-types.json file for this grammar. ### TAGS_QUERY - **Type**: &str - **Description**: The symbol tagging query for this language. ``` -------------------------------- ### tree-sitter-rust Constants Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search= This section details the constants provided by the tree-sitter-rust crate, including the `LANGUAGE` constant for parser initialization and constants for node types and syntax highlighting queries. ```APIDOC ## tree-sitter-rust Constants ### Description Provides access to essential components of the `tree-sitter-rust` grammar, including the language definition, node types, and various query files for syntax analysis. ### Method Not applicable (these are constants) ### Endpoint Not applicable ### Parameters Not applicable ### Request Example ```rust // Get the language constant for parser initialization let language = tree_sitter_rust::LANGUAGE; // Access the node-types.json content let node_types_content = tree_sitter_rust::NODE_TYPES; // Access the highlights query let highlights_query = tree_sitter_rust::HIGHLIGHTS_QUERY; // Access the injections query let injections_query = tree_sitter_rust::INJECTIONS_QUERY; // Access the tags query let tags_query = tree_sitter_rust::TAGS_QUERY; ``` ### Response #### Success Response (200) Not applicable (these are constants) #### Response Example Not applicable ``` -------------------------------- ### GET /syntax/call_expression Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= Retrieves the structural definition of a Rust call expression node. ```APIDOC ## GET /syntax/call_expression ### Description Defines the structure of a function call expression, including the function being called and its associated arguments. ### Method GET ### Endpoint /syntax/call_expression ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **arguments** (object) - The arguments passed to the function. - **function** (object) - The expression representing the function being called. #### Response Example { "type": "call_expression", "fields": { "arguments": { "required": true, "type": "arguments" }, "function": { "required": true, "type": "_literal" } } } ``` -------------------------------- ### Load tree-sitter Rust grammar Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html Shows the internal implementation for exposing the Rust grammar as a LanguageFn and loading it into a parser instance for testing. ```rust pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_rust) }; #[test] fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser .set_language(&super::LANGUAGE.into()) .expect("Error loading Rust parser"); } ``` -------------------------------- ### GET /grammar/loop_expression Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=u32+-%3E+bool Retrieves the structure definition for a Rust loop expression node. ```APIDOC ## GET /grammar/loop_expression ### Description Defines the structure of a loop expression, which contains a block body and an optional label. ### Method GET ### Endpoint /grammar/loop_expression ### Parameters #### Request Body - **body** (block) - Required - The code block to be executed in the loop. - **label** (label) - Optional - An optional loop label. ### Request Example { "body": "{ ... }", "label": "'label" } ### Response #### Success Response (200) - **type** (string) - "loop_expression" #### Response Example { "type": "loop_expression", "named": true } ``` -------------------------------- ### Type Definitions and Bindings Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Details on how types, type parameters, and type bindings are represented in the grammar. ```APIDOC ## Type Definitions and Bindings ### Description This section covers the grammar rules for defining and referencing types in Rust, including type parameters and bindings. ### Method N/A (Grammar Definition) ### Endpoint N/A (Grammar Definition) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) N/A #### Response Example N/A ## Type Binding ### Description Represents a type binding, which associates a name with a type, potentially with type arguments. ### Fields - **name** (type_identifier) - Required - The identifier for the type binding. - **type** (_type) - Required - The type associated with the binding. - **type_arguments** (type_arguments) - Optional - Type arguments for generic bindings. ## Type Cast Expression ### Description Represents an expression that casts a value to a different type. ### Fields - **type** (_type) - Required - The target type for the cast. - **value** (_expression) - Required - The expression whose value is being cast. ## Type Item ### Description Represents a type definition item, such as a struct, enum, or trait. ### Fields - **name** (type_identifier) - Required - The name of the type item. - **type** (_type) - Required - The underlying type definition. - **type_parameters** (type_parameters) - Optional - Type parameters for generic type items. ### Children - **visibility_modifier** (visibility_modifier) - Optional - Specifies the visibility of the type item. - **where_clause** (where_clause) - Optional - Adds a where clause to the type item. ## Type Parameter ### Description Represents a generic type parameter in a type definition or function signature. ### Fields - **bounds** (trait_bounds) - Optional - Trait bounds for the type parameter. - **default_type** (_type) - Optional - The default type for the parameter if not specified. - **name** (type_identifier) - Required - The name of the type parameter. ## Type Parameters ### Description Represents a list of generic type parameters. ### Children - **attribute_item** (attribute_item) - Optional - An attribute applied to the type parameters. - **const_parameter** (const_parameter) - Optional - A const parameter. - **lifetime_parameter** (lifetime_parameter) - Optional - A lifetime parameter. - **metavariable** (metavariable) - Optional - A metavariable. - **type_parameter** (type_parameter) - Optional - A type parameter. ``` -------------------------------- ### tree-sitter-rust Constants Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/all.html?search= Accessing the predefined query constants for the tree-sitter-rust language grammar. ```APIDOC ## Constants Overview ### Description The tree-sitter-rust crate provides several constants that define the grammar and query patterns for Rust source code analysis. ### Constants List - **HIGHLIGHTS_QUERY** (String) - Query string used for syntax highlighting. - **INJECTIONS_QUERY** (String) - Query string used for identifying injected languages. - **LANGUAGE** (Language) - The tree-sitter language object for Rust. - **NODE_TYPES** (String) - JSON string representing the node types of the grammar. - **TAGS_QUERY** (String) - Query string used for code navigation and symbol tagging. ### Usage Example ```rust use tree_sitter_rust; let language = tree_sitter_rust::LANGUAGE; let highlights = tree_sitter_rust::HIGHLIGHTS_QUERY; ``` ``` -------------------------------- ### GET /syntax/break_expression Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= Retrieves the structural definition of a Rust break expression node. ```APIDOC ## GET /syntax/break_expression ### Description Defines the structure of a break expression, which may optionally include a label and an expression. ### Method GET ### Endpoint /syntax/break_expression ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **children** (array) - List of allowed child types including _expression and label. #### Response Example { "type": "break_expression", "named": true, "children": { "multiple": true, "required": false, "types": [{"type": "_expression"}, {"type": "label"}] } } ``` -------------------------------- ### Retrieving Grammar Metadata Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=u32+-%3E+bool Accessing static analysis resources like node types and syntax highlighting queries. ```APIDOC ## GET /tree_sitter_rust/METADATA ### Description Retrieves static metadata including node types, syntax highlighting queries, injection queries, and symbol tagging queries. ### Method GET ### Endpoint tree_sitter_rust::NODE_TYPES, HIGHLIGHTS_QUERY, INJECTIONS_QUERY, TAGS_QUERY ### Parameters None ### Request Example N/A (Rust constant access) ### Response #### Success Response (200) - **NODE_TYPES** (String) - JSON representation of the grammar node types. - **HIGHLIGHTS_QUERY** (String) - S-expression query for syntax highlighting. - **INJECTIONS_QUERY** (String) - S-expression query for code injections. - **TAGS_QUERY** (String) - S-expression query for symbol tagging. #### Response Example let highlights = tree_sitter_rust::HIGHLIGHTS_QUERY; ``` -------------------------------- ### Rust Grammar - Declarations and Types Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Details the structure for declaration lists, dynamic types, else clauses, empty statements, enum items, and enum variants. ```APIDOC ## declaration_list ### Description Represents a list of declarations. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## _declaration_statement (child of declaration_list) ### Description Represents a single declaration statement within a list. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## dynamic_type ### Description Defines a dynamic type, which includes a required trait. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters #### Fields - **trait** (function_type | generic_type | higher_ranked_trait_bound | scoped_type_identifier | tuple_type | type_identifier) - Required - The trait associated with the dynamic type. ### Request Example N/A ### Response N/A ## else_clause ### Description Represents an `else` clause, which can contain a block or an if expression. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters #### Children - **block** | **if_expression** - Required - The content of the else clause. ### Request Example N/A ### Response N/A ## empty_statement ### Description Represents an empty statement, typically a semicolon. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## enum_item ### Description Defines an enum item, including its name, optional type parameters, and body. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters #### Fields - **name** (type_identifier) - Required - The name of the enum. - **body** (enum_variant_list) - Required - The list of variants for the enum. - **type_parameters** (type_parameters) - Optional - Type parameters for the enum. #### Children - **visibility_modifier** - Optional - **where_clause** - Optional ### Request Example N/A ### Response N/A ## enum_variant ### Description Represents a variant within an enum, with an optional body and value. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters #### Fields - **name** (identifier) - Required - The name of the enum variant. - **body** (field_declaration_list | ordered_field_declaration_list) - Optional - The fields or structure of the variant. - **value** (_expression) - Optional - An explicit value assigned to the variant. #### Children - **visibility_modifier** - Optional ### Request Example N/A ### Response N/A ## enum_variant_list ### Description Contains a list of enum variants, potentially preceded by attributes. ### Method N/A (Grammar Definition) ### Endpoint N/A ### Parameters #### Children - **attribute_item** - Optional - **enum_variant** - Required (multiple) ### Request Example N/A ### Response N/A ``` -------------------------------- ### Rust Grammar Rules Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html This section outlines specific grammar rules for Rust, including expressions, match blocks, module items, and more. ```APIDOC ## Match Block ### Description Represents a `match` block in Rust, which can contain multiple `match_arm` elements. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Children - **match_arm** (named, true) - Represents an arm within the match block. ## Match Expression ### Description Defines a `match` expression in Rust, consisting of a value to be matched and a body containing the match arms. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Fields - **value** (_expression, true) - The expression whose value will be matched. - **body** (match_block, true) - The block containing the match arms. ## Match Pattern ### Description Represents a pattern used within a `match` arm, optionally including a condition. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Fields - **condition** (_expression | let_chain | let_condition, false) - An optional condition for the pattern. #### Children - **_pattern** (named, true) - The pattern itself. ## Mod Item ### Description Defines a module item in Rust, which can have a name, an optional body, and visibility modifiers. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Fields - **name** (identifier, true) - The name of the module. - **body** (declaration_list, false) - An optional list of declarations within the module. #### Children - **visibility_modifier** (named, false) - Optional visibility modifier for the module. ## Mut Pattern ### Description Represents a mutable pattern in Rust, typically used in `let` bindings or function parameters. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Children - **_pattern** (named, true) - The pattern being made mutable. - **mutable_specifier** (named, true) - The specifier indicating mutability. ## Negative Literal ### Description Represents a negative literal, such as a negative integer or float. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Children - **float_literal** (named, true) - A negative floating-point literal. - **integer_literal** (named, true) - A negative integer literal. ## Never Type ### Description Represents the never type `!`, which indicates a function that never returns. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters None ## Or Pattern ### Description Represents an `or` pattern, allowing multiple patterns to match a single value. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Children - **_pattern** (named, true) - One of the patterns in the `or` combination. ## Ordered Field Declaration List ### Description Defines a list of fields in a struct or tuple struct where the order matters. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Fields - **type** (_type, false) - The type of the ordered field. #### Children - **attribute_item** (named, true) - An attribute applied to the field declaration. - **visibility_modifier** (named, true) - Visibility modifier for the field. ## Outer Doc Comment Marker ### Description Marks the beginning of an outer documentation comment. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters None ## Parameter ### Description Represents a function parameter, including its pattern and type. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Fields - **pattern** (_pattern | self, true) - The pattern used for the parameter (e.g., variable name, destructuring). - **type** (_type, true) - The type annotation for the parameter. ``` -------------------------------- ### Test tree-sitter-rust Grammar Loading Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A unit test to verify that the Rust language grammar can be successfully loaded into a tree-sitter Parser. It initializes a parser and sets the Rust language, expecting no errors during the process. ```Rust #[cfg(test)] mod tests { #[test] fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser .set_language(&super::LANGUAGE.into()) .expect("Error loading Rust parser"); } } ``` -------------------------------- ### GET /node_types Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the schema definition of node types and their associated subtypes for the Rust grammar. ```APIDOC ## GET /node_types ### Description Returns the JSON structure defining all valid node types, their naming status, and hierarchical subtypes for the Rust parser. ### Method GET ### Endpoint /node_types ### Parameters None ### Request Example GET /node_types ### Response #### Success Response (200) - **body** (array) - A list of node type objects containing type, named, and subtypes fields. #### Response Example [ { "type": "_declaration_statement", "named": true, "subtypes": [ { "type": "function_item", "named": true }, { "type": "struct_item", "named": true } ] } ] ``` -------------------------------- ### Load Tree-sitter Rust Grammar Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=std%3A%3Avec Shows the internal implementation for exposing the Rust grammar constant and accessing static metadata files like node types and query files. ```rust use tree_sitter_language::LanguageFn; extern "C" { fn tree_sitter_rust() -> *const (); } pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_rust) }; pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); ``` -------------------------------- ### Initialize Rust Language Parser for tree-sitter Source: https://docs.rs/tree-sitter-rust/latest/src/tree_sitter_rust/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `LANGUAGE` constant which represents the tree-sitter language for Rust. This constant is used to configure the tree-sitter parser for Rust code. It relies on the `tree-sitter-language` crate and an external C function `tree_sitter_rust`. ```Rust use tree_sitter_language::LanguageFn; extern "C" { fn tree_sitter_rust() -> *const (); } /// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar. /// /// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_rust) }; ``` -------------------------------- ### Grammar Metadata Constants Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust Accessing query and node type metadata for the Rust grammar. ```APIDOC ## GET Grammar Metadata ### Description Access various metadata constants provided by the crate for syntax highlighting, injections, and node types. ### Constants - **HIGHLIGHTS_QUERY** (string) - The syntax highlighting query for Rust. - **INJECTIONS_QUERY** (string) - The injections query for Rust. - **NODE_TYPES** (string) - The content of the node-types.json file. - **TAGS_QUERY** (string) - The symbol tagging query for Rust. ### Response Example ```json { "HIGHLIGHTS_QUERY": "(function_item name: (identifier) @function)", "NODE_TYPES": "[...]" } ``` ``` -------------------------------- ### GET /constants/INJECTIONS_QUERY Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.INJECTIONS_QUERY.html Retrieves the S-expression query string used for identifying and injecting Rust code within macro invocations and macro rules. ```APIDOC ## GET /constants/INJECTIONS_QUERY ### Description Retrieves the constant string containing the tree-sitter injection query. This query is used to identify macro invocations and macro rules to ensure they are parsed as Rust code. ### Method GET ### Endpoint /constants/INJECTIONS_QUERY ### Parameters None ### Request Example GET /constants/INJECTIONS_QUERY ### Response #### Success Response (200) - **data** (string) - The S-expression query string for language injections. #### Response Example { "INJECTIONS_QUERY": "((macro_invocation\n (token_tree) @injection.content)\n (#set! injection.language \"rust\")\n (#set! injection.include-children))\n\n((macro_rule\n (token_tree) @injection.content)\n (#set! injection.language \"rust\")\n (#set! injection.include-children))\n" } ``` -------------------------------- ### Rust Grammar Components Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=u32+-%3E+bool This snippet details various components of the Rust language as parsed by tree-sitter, including function types, generic constructs, and blocks. ```APIDOC ## Function Type Definition ### Description Represents the type signature of a function, including parameters, return type, and trait bounds. ### Fields - **parameters** (parameters) - Required - The parameters of the function. - **return_type** (_type) - Optional - The return type of the function. - **trait** (scoped_type_identifier | type_identifier) - Optional - The trait bound associated with the function type. ### Children - **for_lifetimes** (for_lifetimes) - Optional - Lifetime parameters for the function. - **function_modifiers** (function_modifiers) - Optional - Modifiers applied to the function. ## Gen Block ### Description Represents a generic block of code. ### Fields (No specific fields defined for `gen_block` itself) ### Children - **block** (block) - Required - The actual code block. ## Generic Function ### Description Represents a function that can operate on generic types. ### Fields - **function** (field_expression | identifier | scoped_identifier) - Required - The identifier or expression for the function. - **type_arguments** (type_arguments) - Required - The type arguments provided to the generic function. ## Generic Pattern ### Description Represents a pattern that can be used with generic types. ### Fields - **type_arguments** (type_arguments) - Required - The type arguments for the generic pattern. ### Children - **identifier** (identifier) - Required - The identifier for the pattern. - **scoped_identifier** (scoped_identifier) - Required - The scoped identifier for the pattern. ## Generic Type ### Description Represents a generic type. ### Fields - **type** (identifier | scoped_identifier | scoped_type_identifier | type_identifier) - Required - The base type. - **type_arguments** (type_arguments) - Required - The type arguments for the generic type. ## Generic Type with Turbofish ### Description Represents a generic type specified using the turbofish syntax (::<>). ### Fields - **type** (scoped_identifier | type_identifier) - Required - The base type. - **type_arguments** (type_arguments) - Required - The type arguments provided via turbofish. ## Higher-Ranked Trait ### Description Represents a higher-ranked trait bound. ### (No specific fields or children defined in the provided snippet for this element.) ``` -------------------------------- ### Rust Tree-sitter Grammar Structures Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This section outlines specific grammar rules for Rust, such as for_expression, for_lifetimes, foreign_mod_item, function_item, and function_signature_item. ```APIDOC ## for_expression ### Description Represents a for loop expression in Rust. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## for_lifetimes ### Description Represents for loop lifetimes in Rust. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## foreign_mod_item ### Description Represents a foreign module item in Rust, used for FFI. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## function_item ### Description Represents a function definition in Rust. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## function_signature_item ### Description Represents a function signature in Rust, often used in trait definitions or extern blocks. ### Method N/A (Grammar Rule) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Rust Grammar Node Definitions Source: https://docs.rs/tree-sitter-rust/latest/tree_sitter_rust/constant.NODE_TYPES.html?search= This section provides definitions for various Rust grammar nodes as parsed by tree-sitter. It includes details on fields, children, and type information for each node. ```APIDOC ## Rust Grammar Node Definitions This document outlines the structure of Rust code as parsed by the tree-sitter parser. Each entry describes a specific grammar node, its fields, and its children. ### Lifetime Represents a lifetime in Rust. - **Fields**: None - **Children**: Requires an `identifier`. ### Lifetime Parameter Represents a lifetime parameter in a function or struct definition. - **Fields**: - `name` (lifetime) - Required - The name of the lifetime. - `bounds` (trait_bounds) - Optional - The bounds associated with the lifetime. ### Line Comment Represents a single-line comment. - **Fields**: - `doc` (doc_comment) - Optional - If the comment is a documentation comment. - `inner` (inner_doc_comment_marker) - Optional - Marker for an inner documentation comment. - `outer` (outer_doc_comment_marker) - Optional - Marker for an outer documentation comment. - **Extra**: True ### Loop Expression Represents a loop construct (e.g., `loop`, `while`, `for`). - **Fields**: - `body` (block) - Required - The block of code within the loop. - **Children**: Can have an optional `label`. ### Macro Definition Defines a new macro. - **Fields**: - `name` (identifier) - Required - The name of the macro. - **Children**: Contains one or more `macro_rule` definitions. ### Macro Invocation Invokes an existing macro. - **Fields**: - `macro` (identifier | scoped_identifier) - Required - The name of the macro to invoke. - **Children**: Requires a `token_tree`. ### Macro Rule Defines the pattern and replacement for a macro rule. - **Fields**: - `left` (token_tree_pattern) - Required - The pattern to match. - `right` (token_tree) - Required - The replacement token tree. ### Match Arm Represents a single arm within a `match` expression. - **Fields**: - `pattern` (match_pattern) - Required - The pattern to match against. - `value` (expression) - Required - The expression to evaluate if the pattern matches. ```