https://github.com/chaosunity/ebnf
A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars
https://github.com/chaosunity/ebnf
ebnf ebnf-syntax parser rust
Last synced: 4 months ago
JSON representation
A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars
- Host: GitHub
- URL: https://github.com/chaosunity/ebnf
- Owner: ChAoSUnItY
- License: mit
- Created: 2022-03-17T18:38:20.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-09-17T18:04:53.000Z (4 months ago)
- Last Synced: 2025-09-20T09:12:18.020Z (4 months ago)
- Topics: ebnf, ebnf-syntax, parser, rust
- Language: Rust
- Homepage:
- Size: 29.3 KB
- Stars: 14
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ebnf
[](https://crates.io/crates/ebnf)
[](https://docs.rs/ebnf/)
[](https://github.com/ChAoSUnItY/ebnf/actions/workflows/push.yml)
> A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars
The code is available on [GitHub](https://github.com/ChAoSUnItY/ebnf)
## Disclaimer:
There are various variants of EBNF, which uses somewhat different syntactic conventions. This library
takes [EBNF Evaluator](https://mdkrajnak.github.io/ebnftest/)'s example code as standard, which has
almost most syntactic conventions on Wikipedia's page.
## What does a valid EBNF grammar looks like?
The following example is taken from EBNF Evaluator:
```ebnf
filter ::= ( first ' ' )? ( number '~ ' )? ( number '-' number ) ( ' ' number '~' )? ( ' hz' )? ( ' b' )? ( ' i' )? ( ' a' )?;
first ::= #'[a-za-z][a-za-z0-9_+]*';
number ::= digits ( ( '.' | ',' ) digits? )?;
digits ::= #'[0-9]+';
```
## How to use this library?
```rust
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);
}
```