| Crates.io | sipha-tree |
| lib.rs | sipha-tree |
| version | 0.3.0 |
| created_at | 2025-11-19 17:47:30.498712+00 |
| updated_at | 2025-11-22 09:49:49.298147+00 |
| description | CST/AST construction and node arena management for sipha |
| homepage | |
| repository | https://github.com/NyalephTheCat/sipha |
| max_upload_size | |
| id | 1940487 |
| size | 33,879 |
CST and AST construction for sipha - arena allocation, node types, and lowering.
sipha-tree provides the core data structures for representing Concrete Syntax Trees (CSTs) and utilities for lowering them into Abstract Syntax Trees (ASTs).
Add sipha-tree to your Cargo.toml:
[dependencies]
sipha-tree = "0.1.1"
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());
This project is licensed under the MIT License - see the LICENSE file for details.