Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zesterer/parze
A clean, efficient parser combinator
https://github.com/zesterer/parze
parser parser-combinators parser-framework rust
Last synced: 7 days ago
JSON representation
A clean, efficient parser combinator
- Host: GitHub
- URL: https://github.com/zesterer/parze
- Owner: zesterer
- License: apache-2.0
- Created: 2019-11-25T00:25:18.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-15T15:20:17.000Z (almost 3 years ago)
- Last Synced: 2024-12-27T01:05:52.649Z (14 days ago)
- Topics: parser, parser-combinators, parser-framework, rust
- Language: Rust
- Homepage: https://docs.rs/parze
- Size: 102 KB
- Stars: 124
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[![crates.io](https://img.shields.io/crates/v/parze.svg)](https://crates.io/crates/parze)
[![crates.io](https://docs.rs/parze/badge.svg)](https://docs.rs/parze)**Parze is now deprecated**
*Take a look at [chumsky](https://github.com/zesterer/chumsky/), a from-scratch reimplementation of parze with more features, better performance, and a cleaner API.*
# Parze
Parze is a clean, efficient parser combinator written in Rust.
## Example
A parser capable of parsing all valid Brainfuck code into an AST.
```rust
use parze::prelude::*;#[derive(Clone, Debug, PartialEq)]
enum Instr { Add, Sub, Left, Right, In, Out, Loop(Vec) }parsers! {
bf = {
( '+' -> { Instr::Add }
| '-' -> { Instr::Sub }
| '<' -> { Instr::Left }
| '>' -> { Instr::Right }
| ',' -> { Instr::In }
| '.' -> { Instr::Out }
| '[' -& bf &- ']' => { |i| Instr::Loop(i) }
) *
}
}
```## Features
- [x] All the usual parser combinator operations
- [x] Macro for simple rule and parser declaration
- [x] Support for recursive parser definitions
- [x] Custom error types - define your own!
- [x] Prioritised / merged failure for more useful errors
- [x] No dependencies - fast compilation!
- [x] `no_std` support## Why Parze?
Parze is fast and lightweight, acting as a bare-bones framework upon which more verbose and interesting parsers can be constructed (see the `custom_error` example).
## Nightly
Parze's declaration macro currently requires a nightly Rust compiler to work.
You may use the explicit declaration form (as shown below) with stable by disabling the `nightly` feature, however.This can be done like so in your `Cargo.toml`:
```
[dependencies.parze]
version = "x.y.z"
default-features = false
```## Performance
Here are the results of a JSON parsing test when compared with [`pom`](https://github.com/J-F-Liu/pom). More performance metrics to come later.
```
test parze ... bench: 3,696,323 ns/iter (+/- 358,597)
test pom ... bench: 18,538,775 ns/iter (+/- 1,149,589)
```## Explicit Form
While Parze encourages use of macros for much of its declarative notation, it is possible (and often useful) to make use of the more explicit rust-y notation.
Here is the Brainfuck parser given above, declared in explicit form.
```rust
let bf: Parser<_, _> = recursive(|bf| (
sym('+').to(Instr::Add)
.or(sym('-').to(Instr::Sub))
.or(sym('<').to(Instr::Left))
.or(sym('>').to(Instr::Right))
.or(sym(',').to(Instr::In))
.or(sym('.').to(Instr::Out))
.or(sym('[').delimiter_for(bf).delimited_by(sym(']')).map(|i| Instr::Loop(i)))
).repeat(..));
```## License
Parze is distributed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at the discretion of the user.