https://github.com/rodrigorc/pomelo
Implementation of the Lemon parser generator as a Rust procedural macro
https://github.com/rodrigorc/pomelo
lemon-parser lemon-parser-generator rust-macro
Last synced: about 2 months ago
JSON representation
Implementation of the Lemon parser generator as a Rust procedural macro
- Host: GitHub
- URL: https://github.com/rodrigorc/pomelo
- Owner: rodrigorc
- License: apache-2.0
- Created: 2019-06-12T16:40:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-09-25T09:45:35.000Z (8 months ago)
- Last Synced: 2026-03-13T05:52:50.207Z (3 months ago)
- Topics: lemon-parser, lemon-parser-generator, rust-macro
- Language: Rust
- Size: 324 KB
- Stars: 53
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# pomelo
A procedural macro to create Lemon-like parsers.
[](https://travis-ci.com/rodrigorc/pomelo)
[](https://crates.io/crates/pomelo)
[](https://docs.rs/pomelo)
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](https://crates.io/crates/pomelo) 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:
```toml
[dependencies]
pomelo = "*"
```
## Example
```rust
use pomelo::pomelo;
pomelo! {
%type input Vec;
%type numbers Vec;
%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](https://github.com/rodrigorc/pomelo/tree/master/examples).
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
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.