parze

Crates.ioparze
lib.rsparze
version0.7.3
sourcesrc
created_at2019-11-25 00:28:24.036385
updated_at2019-11-29 23:24:39.01648
descriptionA clean, efficient parser combinator
homepagehttps://www.github.com/zesterer/parze
repositoryhttps://www.github.com/zesterer/parze
max_upload_size
id184081
size184,532
Joshua Barretto (zesterer)

documentation

https://docs.rs/parze

README

crates.io crates.io

Parze

Parze is a clean, efficient parser combinator written in Rust.

Example

A parser capable of parsing all valid Brainfuck code into an AST.

use parze::prelude::*;

#[derive(Clone, Debug, PartialEq)]
enum Instr { Add, Sub, Left, Right, In, Out, Loop(Vec<Instr>) }

parsers! {
    bf = {
        ( '+' -> { Instr::Add }
        | '-' -> { Instr::Sub }
        | '<' -> { Instr::Left }
        | '>' -> { Instr::Right }
        | ',' -> { Instr::In }
        | '.' -> { Instr::Out }
        | '[' -& bf &- ']' => { |i| Instr::Loop(i) }
        ) *
    }
}

Features

  • All the usual parser combinator operations
  • Macro for simple rule and parser declaration
  • Support for recursive parser definitions
  • Custom error types - define your own!
  • Prioritised / merged failure for more useful errors
  • No dependencies - fast compilation!
  • 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. 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.

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:

at the disgression of the user.

Commit count: 0

cargo fmt