arena-terms-parser 0.1.6

Parser for arena-backed, lightweight representations of Prolog-like terms
Documentation
# Arena Terms Parser

[![Crates.io](https://img.shields.io/crates/v/arena-terms-parser.svg)](https://crates.io/crates/arena-terms-parser)
[![Documentation](https://docs.rs/arena-terms-parser/badge.svg)](https://docs.rs/arena-terms-parser)
[![License: LGPL-3.0-or-later](https://img.shields.io/badge/License-LGPL%203.0--or--later-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
[![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg)](https://www.rust-lang.org)

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`](https://crates.io/crates/arena_terms)
crate to store terms efficiently in an arena and is built on top of the
[`parlex`](https://crates.io/crates/parlex) runtime library.


## Features

- **Lexer**  
  Tokenizes atoms, variables, numbers, strings, dates, and symbols.

- **Parser**  
  An SLR(1) parser (generated by [`parlex-gen`]https://crates.io/crates/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.


## Installation

Add this crate to your `Cargo.toml`:

```toml
[dependencies]
arena-terms-parser = "0.1"
````

Also add:

```toml
[dependencies]
arena_terms = "0.1"
parlex = "0.1"
```


## Usage

Parsing a string into arena terms:

```rust
use arena_terms_parser::parser::parse_term;
use arena_terms::Arena;

fn main() {
    let mut arena = Arena::new();

    let mut parser = TermParser::try_new(b"likes(mary, pizza).".fuse(), None).unwrap();

    if let Some(defs) = defs {
        parser.define_opers(arena, b"[op('+'(x,y), infix, 380, left)]".fuse(), None)?;
    }

    let Some(term) = parser.try_next_term(&mut arena) else { unreachable!() }

    println!("{}", term.display(&arena));
}
```


## CLI

Build the binary with:

```bash
cargo build --release --bin arena-terms-parser
```

Then run:

```bash
./target/release/parser --terms input.ax
```


## Documentation

For detailed API documentation, visit [docs.rs/parlex](https://docs.rs/parlex).


## License

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).

## See Also

- [parlex]https://crates.io/crates/parlex - Parlex core runtime library
- [parlex-gen]https://crates.io/crates/parlex-gen - Lexer and parser generation tools (`alex` and `aslr`)
- [arena-terms]https://crates.io/crates/arena-terms - Arena-backed Prolog-like terms