Skip to content

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

License

Notifications You must be signed in to change notification settings

ChAoSUnItY/ebnf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ebnf

Crates.io Docs .github/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

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 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);
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages