1 | // pest. The Elegant Parser |
2 | // Copyright (c) 2018 DragoČ™ Tiselice |
3 | // |
4 | // Licensed under the Apache License, Version 2.0 |
5 | // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
6 | // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
7 | // option. All files in the project carrying such notice may not be copied, |
8 | // modified, or distributed except according to those terms. |
9 | |
10 | macro_rules! insert_builtin { |
11 | ($builtin: expr, $name: ident, $pattern: expr) => { |
12 | $builtin.push((stringify!($name), generate_rule!($name, $pattern))); |
13 | }; |
14 | } |
15 | |
16 | #[cfg (feature = "std" )] |
17 | macro_rules! generate_rule { |
18 | ($name: ident, $pattern: expr) => { |
19 | quote! { |
20 | #[inline] |
21 | #[allow(dead_code, non_snake_case, unused_variables)] |
22 | pub fn $name(state: ::std::boxed::Box<::pest::ParserState<'_, Rule>>) -> ::pest::ParseResult<::std::boxed::Box<::pest::ParserState<'_, Rule>>> { |
23 | $pattern |
24 | } |
25 | } |
26 | } |
27 | } |
28 | |
29 | #[cfg (not(feature = "std" ))] |
30 | macro_rules! generate_rule { |
31 | ($name: ident, $pattern: expr) => { |
32 | quote! { |
33 | #[inline] |
34 | #[allow(dead_code, non_snake_case, unused_variables)] |
35 | pub fn $name(state: ::alloc::boxed::Box<::pest::ParserState<'_, Rule>>) -> ::pest::ParseResult<::alloc::boxed::Box<::pest::ParserState<'_, Rule>>> { |
36 | $pattern |
37 | } |
38 | } |
39 | } |
40 | } |
41 | |