parsimonious

Crates.ioparsimonious
lib.rsparsimonious
version0.0.8
sourcesrc
created_at2016-01-29 19:26:41.144032
updated_at2016-02-05 15:18:53.695316
descriptionParsimonious parser combinators
homepage
repositoryhttps://github.com/asajeffrey/parsimonious
max_upload_size
id4016
size107,595
Alan Jeffrey (asajeffrey)

documentation

http://asajeffrey.github.io/parsimonious

README

parsimonious: a 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 | Crate | CI

Example

extern crate parsimonious;
use parsimonious::{character,Parser,Uncommitted,Committed,Stateful};
use parsimonious::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.star(String::new);

    // If you provide complete input to the parser, you'll get back a Done response:
    match ALPHANUMERICS.init().parse("abc123!") {
        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().parse("abc") {
        Continue("",parsing) => match parsing.parse("123!") {
            Done("!",result) => assert_eq!(result, "abc123"),
            _ => panic!("Can't happen."),
        },
        _ => panic!("Can't happen."),
    }

}

Example tested with Skeptic.

Commit count: 298

cargo fmt