| Crates.io | sipha-memo |
| lib.rs | sipha-memo |
| version | 0.3.0 |
| created_at | 2025-11-19 17:47:59.865197+00 |
| updated_at | 2025-11-22 09:50:04.828362+00 |
| description | Memoization support for packrat parsing in sipha |
| homepage | |
| repository | https://github.com/NyalephTheCat/sipha |
| max_upload_size | |
| id | 1940489 |
| size | 23,271 |
Memoization support for packrat parsing in sipha.
sipha-memo provides memoization tables for caching parse results at specific positions, enabling packrat parsing which can handle left-recursive grammars and improve performance for ambiguous grammars.
Add sipha-memo to your Cargo.toml:
[dependencies]
sipha-memo = "0.1.1"
use sipha_memo::{MemoTable, MemoEntry};
use sipha_core::traits::{TokenKind, RuleId};
use sipha_tree::RawNodeId;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum Token { A }
impl TokenKind for Token { fn is_trivia(&self) -> bool { false } }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum Rule { Expr }
let mut memo: MemoTable<Token, Rule, RawNodeId> = MemoTable::new();
memo.store_success(Rule::Expr, 0, RawNodeId(0), 5);
if let Some(entry) = memo.get(Rule::Expr, 0) {
match entry {
MemoEntry::Success { node, consumed } => {
println!("Cached: node {:?}, consumed {} tokens", node, consumed);
}
_ => {}
}
}
This project is licensed under the MIT License - see the LICENSE file for details.