sipha-tree

Crates.iosipha-tree
lib.rssipha-tree
version0.3.0
created_at2025-11-19 17:47:30.498712+00
updated_at2025-11-22 09:49:49.298147+00
descriptionCST/AST construction and node arena management for sipha
homepage
repositoryhttps://github.com/NyalephTheCat/sipha
max_upload_size
id1940487
size33,879
Nyaleph (NyalephTheCat)

documentation

README

sipha-tree

License: MIT Repository Crates.io docs.rs

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:

[dependencies]
sipha-tree = "0.1.1"

Example

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 file for details.

Commit count: 0

cargo fmt