Crates.io | lbnf |
lib.rs | lbnf |
version | 0.1.0 |
source | src |
created_at | 2023-07-19 09:15:30.209699 |
updated_at | 2023-07-19 09:15:30.209699 |
description | A crate for parsing LBNF grammar |
homepage | |
repository | https://github.com/sebostien/lbnf |
max_upload_size | |
id | 920151 |
size | 27,923 |
A crate for parsing LBNF.
A crate for parsing LBNF. This crate is solely responsible for parsing LBNF. Several components, such as lexer, parser, and AST generation, are missing and needed to generate complete parsers for context-free grammars.
Labeled Backus-Naur form (LBNF) is an extension of BNF formalized by the tool BNFC. In addition to regular BNF syntax, each production is also given a label that is used to generate the abstract syntax of context-free languages.
This crate does not follow all the rules specified in BNFC's LBNF reference. Some changes, especially with the macro syntax, have been made to make LBNF suitable for a wider number of applications.
let source = r#"
EAdd. Expr ::= Expr "+" Num ;
ENum. Expr ::= Num ;
NZero. Num ::= "0" ;
"#;
if let Ok(grammar) = lbnf::parse(source) {
// The parsed grammar can now be used to generate the following structure:
enum Expr {
EAdd(Box<Expr>, Num),
ENum(Num),
}
enum Num {
NZero
}
}
Licensed under either of
at your option.
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.