Crates.io | ebnf |
lib.rs | ebnf |
version | 0.1.4 |
source | src |
created_at | 2022-03-18 14:30:25.759159 |
updated_at | 2023-04-14 16:47:52.331354 |
description | A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars |
homepage | |
repository | https://github.com/ChAoSUnItY/ebnf |
max_upload_size | |
id | 552724 |
size | 22,562 |
A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars
The code is available on GitHub
There are various variants of EBNF, which uses somewhat different syntactic conventions. This library takes EBNF Evaluator's example code as standard, which has almost most syntactic conventions on Wikipedia's page.
The following example is taken from EBNF Evaluator:
filter ::= ( first ' ' )? ( number '~ ' )? ( number '-' number ) ( ' ' number '~' )? ( ' hz' )? ( ' b' )? ( ' i' )? ( ' a' )?;
first ::= #'[a-za-z][a-za-z0-9_+]*';
number ::= digits ( ( '.' | ',' ) digits? )?;
digits ::= #'[0-9]+';
extern crate ebnf;
fn main() {
let source = r"
filter ::= ( first ' ' )? ( number '~ ' )? ( number '-' number ) ( ' ' number '~' )? ( ' hz' )? ( ' b' )? ( ' i' )? ( ' a' )?;
first ::= #'[a-za-z][a-za-z0-9_+]*';
number ::= digits ( ( '.' | ',' ) digits? )?;
digits ::= #'[0-9]+';
";
let result = ebnf::get_grammar(source);
}