# sipha-tree
[](https://opensource.org/licenses/MIT)
[](https://github.com/NyalephTheCat/sipha)
[](https://crates.io/crates/sipha-tree)
[](https://docs.rs/sipha-tree)
CST and AST construction for sipha - arena allocation, node types, and lowering.
## Overview
`sipha-tree` provides the core data structures for representing Concrete Syntax Trees (CSTs) and utilities for lowering them into Abstract Syntax Trees (ASTs).
## Features
- **NodeArena**: Efficient arena-based allocation for CST nodes
- **CstNode**: Fundamental building block of the CST
- **CstKind**: Enum representing different node types (Token, Rule, Trivia, Error)
- **NodeChildren**: Compact representation for node children
- **LowerCtx**: Context for AST lowering operations
- **AstNode**: Trait for AST nodes to be lowered from CST
## Quick Start
Add `sipha-tree` to your `Cargo.toml`:
```toml
[dependencies]
sipha-tree = "0.1.1"
```
## Example
```rust
use sipha_core::traits::{TokenKind, RuleId};
use sipha_tree::{NodeArena, RawNodeId, CstNode, CstKind, NodeChildren};
use sipha_core::span::Span;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum MyToken { Ident, Number }
impl TokenKind for MyToken { fn is_trivia(&self) -> bool { false } }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum MyRule { Expr, Term }
impl RuleId for MyRule {}
let mut arena = NodeArena::<MyToken, MyRule, RawNodeId>::new();
let num_node = arena.alloc(CstNode::create(
CstKind::Token(MyToken::Number),
Span::new(0, 5),
NodeChildren::new(),
));
let expr_node = arena.alloc(CstNode::create(
CstKind::Rule(MyRule::Expr),
Span::new(0, 5),
NodeChildren::from_iter(vec![num_node]),
));
assert!(arena.get(expr_node).is_some());
```
## License
This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details.