#parser #parser-generator #lemon #yacc #bison

no-std pomelo

Implementation of the Lemon parser generator as a Rust procedural macro

7 releases

0.1.5 Jan 8, 2021
0.1.4 Mar 17, 2020
0.1.3 Aug 21, 2019
0.1.2 Jul 12, 2019
0.0.1 Jun 12, 2019

#24 in Parser tooling

Download history 1438/week @ 2021-06-07 2013/week @ 2021-06-14 1826/week @ 2021-06-21 1946/week @ 2021-06-28 2239/week @ 2021-07-05 1754/week @ 2021-07-12 2677/week @ 2021-07-19 2476/week @ 2021-07-26 2291/week @ 2021-08-02 1893/week @ 2021-08-09 1019/week @ 2021-08-16 1129/week @ 2021-08-23 961/week @ 2021-08-30 1745/week @ 2021-09-06 2113/week @ 2021-09-13 2046/week @ 2021-09-20

4,735 downloads per month
Used in 4 crates (via smt2parser)

MIT/Apache

245KB
4.5K SLoC

pomelo

A procedural macro to create Lemon-like parsers.

Travis-CI Status Latest version Documentation

Pomelo is a port to Rust of the Lemon Parser Generator (from now on, Lemon_C) originally written by D. Richard Hipp for his SQLite parser. It is based on a previous attempt to port Lemon to Rust (Lemon_Rust), but now it is written as a Rust procedural macro, so it does not contain any of the original C code (although it uses the same algorithms). Thus the change in name to a different citrus fruit.

Getting Started

It is recommended to go to crates.io for the newest released version, as well as links to the newest builds of the docs.

Just add the following dependency to your Cargo manifest:

[dependencies]
pomelo = "*"

Example

use pomelo::pomelo;

pomelo! {
    %type input Vec<i32>;
    %type numbers Vec<i32>;
    %type Number i32;

    input ::= numbers?(A) { A.unwrap_or_else(Vec::new) };
    numbers ::= Number(N) { vec![N] }
    numbers ::= numbers(mut L) Comma Number(N) { L.push(N); L }
}
fn main() -> Result<(), ()> {
    use parser::{Parser, Token};
    //Real world code would use a tokenizer
    let tokens = vec![
        Token::Number(1),
        Token::Comma,
        Token::Number(2),
        Token::Comma,
        Token::Number(3),
    ];
    let mut p = Parser::new();
    for tok in tokens.into_iter() {
        p.parse(tok)?;
    }
    let data = p.end_of_input()?;
    assert_eq!(data, vec![1, 2, 3]);
    Ok(())
}

See more examples in the github repo folder.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~310–730KB
~18K SLoC