17 releases (5 breaking)

Uses old Rust 2015

0.6.5 Mar 7, 2016
0.6.4 Mar 4, 2016
0.5.0 Feb 24, 2016
0.4.3 Feb 23, 2016
0.1.1 Feb 8, 2016

#288 in Parser tooling

Download history 8/week @ 2024-09-22

55 downloads per month

MPL-2.0 license

115KB
2K SLoC

Parsell: an LL(1) streaming parser combinator library for Rust

The goal of this library is to provide parser combinators that:

  • are optimized for LL(1) grammars,
  • support streaming input,
  • do as little buffering or copying as possible, and
  • do as little dynamic method dispatch as possible.

It is based on:

Rustdoc | Video | Slides | Crate | CI

Example

extern crate parsell;
use parsell::{character,Parser,UncommittedStr,StatefulStr};
use parsell::ParseResult::{Done,Continue};
#[allow(non_snake_case)]
fn main() {

    // A sequence of alphanumerics, saved in a string buffer
    let ALPHANUMERIC = character(char::is_alphanumeric);
    let ALPHANUMERICS = ALPHANUMERIC.plus(String::new);

    // If you provide unmatching input to the parser, you'll get back a None response:
    match ALPHANUMERICS.init_str("!$?") {
        None => (),
        _ => panic!("Can't happen."),
    }

    // If you provide complete input to the parser, you'll get back a Done response:
    match ALPHANUMERICS.init_str("abc123!") {
        Some(Done(result)) => assert_eq!(result, "abc123"),
        _ => panic!("Can't happen."),
    }

    // If you provide incomplete input to the parser, you'll get back a Continue response:
    match ALPHANUMERICS.init_str("abc") {
        Some(Continue(parsing)) => match parsing.more_str("123!") {
            Done(result) => assert_eq!(result, "abc123"),
            _ => panic!("Can't happen."),
        },
        _ => panic!("Can't happen."),
    }

}

Example tested with Skeptic.

No runtime deps

~245KB