Pomelo
Implementation of the Lemon parser generator as a Rust procedural macro
Install / Use
/learn @rodrigorc/PomeloREADME
pomelo
A procedural macro to create Lemon-like parsers.
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
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (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.
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
