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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Derive macros implemented with [pest3_generator].
//!
//! ## Code Generation
//!
//! ### Meta Rules
//!
//! Rules can have several arguments.
//!
//! Definitions of these rules can use these arguments,
//! and these rules will be mapped to a struct in Rust using generics.
//!
//! ```rust
//! use pest3_derive::Parser;
//! use pest3_core::typed::TypedNode;
//!
//! #[derive(Parser)]
//! #[grammar_inline = r#"
//! pair(a, b) = a - " "* - ":" - " "* - b
//! string = "\"" - ('a'..'z' | 'A'..'Z' | '0'..'9')* - "\""
//! main = pair(string, string)
//! "#]
//! struct Parser;
//!
//! fn main() -> anyhow::Result<()> {
//! use rules::*;
//! pair::<string, string>::check(r#""a": "b""#)?;
//! Ok(())
//! }
//! ```
//!
//! Once called with some exact parameters,
//! these arguments are replaced directly as a whole.
//!
//! In the example above,
//! `pair(string, string)` has the same structure with
//! `string - " "* - ":" - " "* - string`.
//!
//! But there are some restrictions on meta rules:
//!
//! - All arguments must be used.
//! I think there is no reason in pest for one to define an argument
//! that won't be used, at least for now.
//!
//! And later we may support constant arguments
//! just like the built-in rule `pest::stack::peek`.
use TokenStream;
/// Derive typed parser from given grammar.