| Crates.io | arena-terms-parser |
| lib.rs | arena-terms-parser |
| version | 0.4.0 |
| created_at | 2025-10-02 05:34:07.427426+00 |
| updated_at | 2025-10-23 10:17:48.32296+00 |
| description | Parser for arena-backed, lightweight representations of Prolog-like terms |
| homepage | |
| repository | https://github.com/ikhomyakov/arena-terms.git |
| max_upload_size | |
| id | 1863900 |
| size | 161,670 |
Parser for arena-backed, Prolog-like terms.
This crate provides a lexer, parser, and operator handling for Prolog-style
terms. It depends on the arena_terms
crate to store terms efficiently in an arena and is built on top of the
parlex core library.
Lexer Tokenizes atoms, variables, numbers, strings, dates, and symbols.
Parser
An SLR(1) parser (generated by parlex-gen) that
produces arena_terms::Term values.
Operators Dynamically handles operator fixity, associativity, and precedence rules.
Arena-backed Terms are stored compactly in arenas for efficient allocation and traversal.
Parsing a string into arena terms:
use arena_terms::Arena;
use arena_terms_parser::{TermParser, define_opers};
use try_next::{IterInput, TryNextWithContext};
const DEFS: &str = "[
op('+'(x,y), infix, 380, left),
op('*'(x,y), infix, 400, left),
]";
const TERMS: &str = "
likes(mary, pizza).
2 + 2 * 3 = 8 .
";
fn main() {
let mut arena = Arena::try_with_default_opers().unwrap();
define_opers(&mut arena, IterInput::from(DEFS.bytes())).unwrap();
let mut parser = TermParser::try_new(IterInput::from(TERMS.bytes())).unwrap();
while let Some(term) = parser.try_next_with_context(&mut arena).unwrap() {
println!("{}", term.display(&arena));
}
}
Build the binary with:
cargo build --release --bin arena-terms-parser
Then run:
./target/release/parser --terms input.ax
For detailed API documentation, visit docs.rs/arena-terms-parser.
Copyright (c) 2005–2025 IKH Software, Inc.
Released under the terms of the GNU Lesser General Public License, version 3.0 or (at your option) any later version (LGPL-3.0-or-later).
alex and aslr)