20 releases (4 breaking)

0.5.3 Dec 2, 2024
0.5.2 Oct 25, 2024
0.4.3 Sep 2, 2024
0.1.5 Jul 26, 2024

#1402 in Parser implementations

Download history 231/week @ 2024-11-27 67/week @ 2024-12-04 37/week @ 2024-12-11 11/week @ 2024-12-18 2/week @ 2025-01-01 27/week @ 2025-01-08 18/week @ 2025-01-15 15/week @ 2025-01-22 23/week @ 2025-01-29 22/week @ 2025-02-05 26/week @ 2025-02-12 18/week @ 2025-02-19 67/week @ 2025-02-26 24/week @ 2025-03-05 9/week @ 2025-03-12

120 downloads per month
Used in 2 crates (via kbnf)

MIT license

120KB
3K SLoC

ebnf

Crates.io Docs

This crate is forked from ebnf to support kbnf syntax. This is currently intended as an internal crate for crate kbnf.


lib.rs:

ebnf - A successor bnf parsing library of bnf parsing library, for parsing Extended Backus–Naur form context-free grammars

The code is available on GitHub

Disclaimer:

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.

What does a valid EBNF grammar looks like?

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]+';

How to use this library?

extern crate kbnf_syntax;

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 = kbnf_syntax::get_grammar(source);
}

Dependencies

~7MB
~127K SLoC