]> git.proxmox.com Git - rustc.git/blame - vendor/pest_generator/src/macros.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / vendor / pest_generator / src / macros.rs
CommitLineData
9fa01778
XL
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
10macro_rules! insert_builtin {
11 ($builtin: expr, $name: ident, $pattern: expr) => {
f9f354fc 12 $builtin.push((stringify!($name), generate_rule!($name, $pattern)));
9fa01778
XL
13 };
14}
15
f2b60f7d 16#[cfg(feature = "std")]
9fa01778
XL
17macro_rules! generate_rule {
18 ($name: ident, $pattern: expr) => {
19 quote! {
20 #[inline]
21 #[allow(dead_code, non_snake_case, unused_variables)]
9c376795 22 pub fn $name(state: ::std::boxed::Box<::pest::ParserState<'_, Rule>>) -> ::pest::ParseResult<::std::boxed::Box<::pest::ParserState<'_, Rule>>> {
9fa01778
XL
23 $pattern
24 }
25 }
26 }
27}
28
f2b60f7d
FG
29#[cfg(not(feature = "std"))]
30macro_rules! generate_rule {
9fa01778
XL
31 ($name: ident, $pattern: expr) => {
32 quote! {
33 #[inline]
34 #[allow(dead_code, non_snake_case, unused_variables)]
9c376795 35 pub fn $name(state: ::alloc::boxed::Box<::pest::ParserState<'_, Rule>>) -> ::pest::ParseResult<::alloc::boxed::Box<::pest::ParserState<'_, Rule>>> {
9fa01778
XL
36 $pattern
37 }
38 }
39 }
40}