https://github.com/kairos-xx/tree-interval
A Python package for managing and visualizing interval tree structures with AST analysis capabilities.
https://github.com/kairos-xx/tree-interval
abstract-syntax-tree ast-analysis code-analysis debug-tools development-tools inspect introspection object-oriented-programming position python python-library rich tree-implementations tree-search tree-structure type-hints visualization
Last synced: 7 days ago
JSON representation
A Python package for managing and visualizing interval tree structures with AST analysis capabilities.
- Host: GitHub
- URL: https://github.com/kairos-xx/tree-interval
- Owner: kairos-xx
- License: mit
- Created: 2024-12-27T01:14:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-08T09:39:17.000Z (over 1 year ago)
- Last Synced: 2026-06-25T18:06:18.968Z (12 days ago)
- Topics: abstract-syntax-tree, ast-analysis, code-analysis, debug-tools, development-tools, inspect, introspection, object-oriented-programming, position, python, python-library, rich, tree-implementations, tree-search, tree-structure, type-hints, visualization
- Language: Python
- Homepage: https://replit.com/@kairos/treeinterval
- Size: 2.94 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Tree Interval
A powerful Python package for managing, analyzing, and visualizing tree structures with rich interval-based node positioning
## ✨ Features
- 🔮 **Future Class**: Powerful dynamic attribute handling with context-aware error reporting and smart chain creation
- 📍 **Position-Aware Nodes**: Track code positions with line numbers, column offsets and intervals
- 🌲 **AST Analysis**: Built-in support for Python AST traversal and node location
- 🔍 **Frame Analysis**: Runtime code inspection with frame position tracking
- 🎨 **Rich Visualization**: Multiple visualization options including ASCII trees and Rich-based pretty printing
- 💾 **JSON Serialization**: Full support for saving and loading tree structures
- 🔎 **Flexible Node Search**: Parent, child and sibling search with custom predicates
## 🚀 Quick Start
### Dynamic Attribute Handling with Future
```python
from tree_interval import Future
class Nested:
def __init__(self):
self.__dict__ = {}
def __getattr__(self, name):
return Future(name, frame=1, instance=self)
# Dynamic attribute chain creation
obj = Nested()
obj.a.b.c = 42 # Creates nested structure automatically
print(obj.a.b.c) # 42
# Smart error reporting
print(obj.x.y.z) # Raises detailed error with context
```
### Tree Operations
```python
from tree_interval import Tree, Leaf, Position
# Create a basic tree
tree = Tree("Example")
root = Leaf(Position(0, 100), "Root")
child = Leaf(Position(10, 50), "Child")
tree.root = root
tree.add_leaf(child)
# Visualize the tree
tree.visualize()
```
## 📦 Installation
```bash
pip install tree-interval
```
## 🎯 Core Components
### Position Types
```python
# Basic Position
pos = Position(0, 100)
# Line-Aware Position
pos = Position(0, 100)
pos.lineno = 1
pos.end_lineno = 5
# Column-Aware Position
pos = Position(0, 100)
pos.col_offset = 4
pos.end_col_offset = 8
```
### Tree Visualization
```python
# Basic ASCII Tree
tree.visualize()
# Rich Pretty Printing
from tree_interval.rich_printer import RichTreePrinter
printer = RichTreePrinter()
printer.print_tree(tree)
```
## 📚 Documentation
- [Core Components](docs/wiki/Core-Components.md)
- [Installation Guide](docs/wiki/Installation.md)
- [Visualization Guide](docs/wiki/Visualization.md)
- [API Reference](docs/API_REFERENCE.md)
## 💡 Use Cases
1. **Code Analysis**
- Track source positions in AST nodes
- Locate runtime code execution points
- Analyze code structure and relationships
2. **Tree Visualization**
- Debug tree structures
- Generate documentation
- Analyze hierarchical data
3. **Position Tracking**
- Map source locations
- Track text positions
- Handle nested intervals
## 📝 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
Built with ❤️ by Kairos