项目作者: rodrigorc

项目描述 :
Implementation of the Lemon parser generator as a Rust procedural macro
高级语言: Rust
项目地址: git://github.com/rodrigorc/pomelo.git
创建时间: 2019-06-12T16:40:05Z
项目社区:https://github.com/rodrigorc/pomelo

开源协议:Other

下载


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:

  1. [dependencies]
  2. pomelo = "*"

Example

  1. use pomelo::pomelo;
  2. pomelo! {
  3. %type input Vec<i32>;
  4. %type numbers Vec<i32>;
  5. %type Number i32;
  6. input ::= numbers?(A) { A.unwrap_or_else(Vec::new) };
  7. numbers ::= Number(N) { vec![N] }
  8. numbers ::= numbers(mut L) Comma Number(N) { L.push(N); L }
  9. }
  10. fn main() -> Result<(), ()> {
  11. use parser::{Parser, Token};
  12. //Real world code would use a tokenizer
  13. let tokens = vec![
  14. Token::Number(1),
  15. Token::Comma,
  16. Token::Number(2),
  17. Token::Comma,
  18. Token::Number(3),
  19. ];
  20. let mut p = Parser::new();
  21. for tok in tokens.into_iter() {
  22. p.parse(tok)?;
  23. }
  24. let data = p.end_of_input()?;
  25. assert_eq!(data, vec![1, 2, 3]);
  26. Ok(())
  27. }

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.