Tree Parser
A comprehensive Rust library for parsing and searching code elements across multiple programming languages using tree-sitter. This library provides powerful tools for static code analysis, code search, and AST manipulation.
Installation
Use cargo add tree-parser
to install the latest version.
Enable feature flags for desired languages:
# Enable specific language support
= { = "0.1.0", = ["python", "rust_lang", "javascript"] }
# Or enable all languages
= { = "0.1.0", = ["full"] }
Available Feature Flags
python
- Python language supportrust_lang
- Rust language supportjavascript
- JavaScript language supporttypescript
- TypeScript language supportjava
- Java language supportc
- C language supportcpp
- C++ language supportgo
- Go language supportfull
- Enable all language parsers
Features
- 🚀 Multi-language Support: Parse Python, Rust, JavaScript, TypeScript, Java, C, C++, Go, and more
- ⚡ High Performance: Concurrent parsing with async/await for maximum efficiency
- 🔍 Advanced Search: Find functions, classes, structs, interfaces with regex pattern matching
- 🎯 Flexible Filtering: Custom file filters and parsing options
- 📊 Rich Metadata: Extract detailed information about code constructs
- 🛡️ Type Safety: Full Rust type safety with comprehensive error handling
- 🔧 Configurable: Extensive configuration options for different use cases
Basic Usage
Parse a Single File
use ;
async
Parse an Entire Project
use ;
async
Search for Code Constructs
use ;
async
Supported Languages
Language | Feature Flag | File Extensions |
---|---|---|
Python | python |
.py , .pyw , .pyi |
Rust | rust_lang |
.rs |
JavaScript | javascript |
.js , .mjs , .cjs |
TypeScript | typescript |
.ts , .mts , .cts |
Java | java |
.java |
C | c |
.c , .h |
C++ | cpp |
.cpp , .cc , .cxx , .hpp |
Go | go |
.go |
Advanced Usage
Custom File Filtering
use ;
use Path;
use Arc;
async
Query-based Search
use ;
async
Configuration
Parse Options
use ;
let options = ParseOptions ;
Error Handling
The library provides comprehensive error handling:
use ;
async
Documentation
- Rust Docs - Generated API documentation
Performance
The library is designed for high performance:
- Concurrent Processing: Uses tokio for async I/O and concurrent file processing
- Memory Efficient: Streaming processing for large codebases
- Optimized Parsing: Tree-sitter's incremental parsing capabilities
- Configurable Limits: Prevent resource exhaustion with configurable limits
Performance Tips
- Use
FileFilter
to reduce processing overhead - Adjust
max_concurrent_files
based on available memory - Set appropriate
max_file_size_mb
to prevent memory issues - Enable caching for repeated operations
- Use
LanguageDetection::ByExtension
for best performance
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- tree-sitter for the excellent parsing framework
- The tree-sitter language grammar maintainers
- The Rust community for the amazing ecosystem