lbnf/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(
3    clippy::all,
4    clippy::pedantic,
5    clippy::nursery,
6    clippy::cargo,
7    clippy::perf,
8    missing_docs
9)]
10#![allow(clippy::multiple_crate_versions)]
11
12/// The structure of LBNF grammar.
13pub mod grammar;
14
15mod display;
16
17#[cfg(test)]
18mod proptests;
19
20use crate::grammar::Grammar;
21
22use lalrpop_util::{lexer::Token, ParseError};
23
24#[macro_use]
25extern crate lalrpop_util;
26
27lalrpop_mod!(
28    #[allow(clippy::all)]
29    #[allow(clippy::pedantic)]
30    #[allow(clippy::nursery)]
31    #[allow(clippy::perf)]
32    #[allow(unused)]
33    lbnf
34);
35
36/// Parse the given string as LBNF grammar.
37/// Returns [`Grammar`] if the provided grammar is valid.
38///
39/// # Errors
40///
41/// Will return `Err` if the provided grammar fails to parse.
42///
43/// # Examples
44///
45/// ```rust
46/// use lbnf::parse;
47///
48/// let grammar = r#"
49///    EAdd.  Exp ::= Exp "+" Exp ;
50///    EInt.  Exp ::= Integer     ;
51/// "#;
52/// assert!(parse(grammar).is_ok());
53/// ```
54pub fn parse(input: &str) -> Result<Grammar, ParseError<usize, Token<'_>, &str>> {
55    lbnf::GrammarParser::new().parse(input)
56}