1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use ;
use TokenStream;
use parse_macro_input;
/// Generate LR(1) parser at compilation time.<br>
/// If the specified grammar is ambiguous, compilation is aborted with conflict.
///
/// # Examples
///
/// ```
/// use bnf_rules::bnf_rules_macro::bnf_rules;
///
/// // Grammar
/// bnf_rules!(
/// // If it specified false, it will only check whether the grammar contains ambiguity, with no generated code.
/// // This setting is optional.
/// #[generate_code = true]
///
/// source ::= expr
/// expr ::= factor { "+" factor }
/// factor ::= "-" primary | primary
/// primary ::= "(" expr ")" | number
/// number ::= r"\d+" // regex
/// );
///
/// pub fn parse() {
///
/// // A function named "parse_source" is automatically generated.
/// let ast_node: Result<ASTNode, ParseError> = parse_source("(100 + 200) + -100");
/// dbg!(ast_node.unwrap());
///
/// }
/// ```