Expand description
§tree-sitter-language-pack
Pre-compiled tree-sitter grammars for 305 programming languages with a unified API for parsing, analysis, and intelligent code chunking.
§Quick Start
use tree_sitter_language_pack::{ProcessConfig, available_languages, has_language, process};
// Check available languages
let langs = available_languages();
assert!(has_language("python"));
// Process source code
let config = ProcessConfig::new("python").all();
let result = process("def hello(): pass", &config).unwrap();
println!("Language: {}", result.language);
println!("Functions: {}", result.structure.len());§Modules
registry- Thread-safe language registry for parser lookup- [
intel] - Source code intelligence extraction (structure, imports, exports, etc.) - [
parse] - Low-level tree-sitter parsing utilities - [
node] - Tree node traversal and information extraction - [
query] - Tree-sitter query execution - [
text_splitter] - Syntax-aware code chunking process_config- Configuration for theprocesspipelinepack_config- Configuration for the language pack (cache dir, languages to download)error- Error types
Re-exports§
pub use error::Error;pub use pack_config::PackConfig;pub use process_config::ProcessConfig;pub use registry::LanguageRegistry;pub use download::DownloadManager;
Modules§
Structs§
- Capture
Result - A single captured node within a match.
- Chunk
Context - Metadata for a single chunk of source code.
- Code
Chunk - A chunk of source code with rich metadata.
- Comment
Info - A comment extracted from source code.
- Diagnostic
- A diagnostic (syntax error, missing node, etc.) from parsing.
- DocSection
- A section within a docstring (e.g., Args, Returns, Raises).
- Docstring
Info - A docstring extracted from source code.
- Export
Info - An export statement extracted from source code.
- Extraction
Config - Configuration for an extraction run against a single language.
- Extraction
Pattern - Defines a single extraction pattern and its configuration.
- Extraction
Result - Complete extraction results for all patterns.
- File
Metrics - Aggregate metrics for a source file.
- Import
Info - An import statement extracted from source code.
- Language
- An opaque object that defines how to parse a particular language. The code
for each
Languageis generated by the Tree-sitter CLI. - Match
Result - A single query match containing one or more captures.
- Node
Info - Lightweight snapshot of a tree-sitter node’s properties.
- Parser
- A stateful object that this is used to produce a
Treebased on some source code. - Pattern
Result - Results for a single named pattern.
- Pattern
Validation - Validation information for a single pattern.
- Process
Result - Complete analysis result from processing a source file.
- Query
Match - A single match from a tree-sitter query, with captured nodes.
- Span
- Byte and line/column range in source code.
- Structure
Item - A structural item (function, class, struct, etc.) in source code.
- Symbol
Info - A symbol (variable, function, type, etc.) extracted from source code.
- Tree
- A tree that represents the syntactic structure of a source code file.
- Validation
Result - Validation results for an entire extraction config.
Enums§
- Capture
Output - Controls what data is captured for each query match.
- Comment
Kind - The kind of a comment found in source code.
- Diagnostic
Severity - Severity level of a diagnostic produced during parsing.
- Docstring
Format - The format of a docstring extracted from source code.
- Export
Kind - The kind of an export statement found in source code.
- Structure
Kind - The kind of structural item found in source code.
- Symbol
Kind - The kind of a symbol definition found in source code.
Functions§
- available_
languages - List all available language names (sorted, deduplicated, includes aliases).
- cache_
dir - Return the effective cache directory path.
- clean_
cache - Delete all cached parser shared libraries.
- configure
- Apply download configuration without downloading anything.
- detect_
language_ from_ content - Detect language name from file content using the shebang line (
#!). - detect_
language_ from_ extension - Detect language name from a file extension (without leading dot).
- detect_
language_ from_ path - Detect language name from a file path.
- download
- Download specific languages to the local cache.
- download_
all - Download all available languages from the remote manifest.
- downloaded_
languages - Return languages that are already downloaded and cached locally.
- extract_
patterns - Run extraction patterns against source code.
- find_
nodes_ by_ type - Find all nodes matching the given type name, returning their
NodeInfo. - get_
highlights_ query - Get the highlights query for a language, if bundled.
- get_
injections_ query - Get the injections query for a language, if bundled.
- get_
language - Get a tree-sitter
Languageby name using the global registry. - get_
locals_ query - Get the locals query for a language, if bundled.
- get_
parser - Get a tree-sitter
Parserpre-configured for the given language. - has_
language - Check if a language is available by name or alias.
- init
- Initialize the language pack with the given configuration.
- language_
count - Return the number of available languages.
- manifest_
languages - Return all language names available in the remote manifest (305).
- named_
children_ info - Get
NodeInfofor all named children of the root node. - parse_
string - Parse source code with the named language, returning the syntax tree.
- process
- Process source code and extract file intelligence using the global registry.
- root_
node_ info - Get a
NodeInfosnapshot of the root node. - run_
query - Execute a tree-sitter query pattern against a parsed tree.
- tree_
contains_ node_ type - Check whether any node in the tree matches the given type name.
- tree_
error_ count - Count the number of ERROR and MISSING nodes in the tree.
- tree_
has_ error_ nodes - Check whether the tree contains any ERROR or MISSING nodes.
- tree_
to_ sexp - Return the S-expression representation of the entire tree.
- validate_
extraction - Validate extraction patterns without running them.