#parser #context-free-grammar #ebnf #bnf #syntax #forms #kbnf

kbnf-syntax

An internal syntax crate for kbnf crate

16 unstable releases (3 breaking)

0.4.3 Sep 2, 2024
0.4.2 Aug 30, 2024
0.3.0 Aug 28, 2024
0.2.0 Aug 14, 2024
0.1.2 Jun 25, 2024

#1 in #bnf

Download history 1138/week @ 2024-06-14 1013/week @ 2024-06-21 59/week @ 2024-06-28 6/week @ 2024-07-05 169/week @ 2024-07-19 683/week @ 2024-07-26 213/week @ 2024-08-02 661/week @ 2024-08-09 252/week @ 2024-08-16 172/week @ 2024-08-23 688/week @ 2024-08-30 72/week @ 2024-09-06 89/week @ 2024-09-13 31/week @ 2024-09-20 15/week @ 2024-09-27

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

MIT license

115KB
2.5K 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

~8MB
~140K SLoC