• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 macro_rules! insert_public_builtin {
17     ($builtin: expr, $name: ident, $pattern: expr) => {
18         $builtin.push((stringify!($name), generate_public_rule!($name, $pattern)));
19     };
20 }
21 
22 macro_rules! generate_rule {
23     ($name: ident, $pattern: expr) => {
24         quote! {
25             #[inline]
26             #[allow(dead_code, non_snake_case, unused_variables)]
27             pub fn $name(state: Box<::pest::ParserState<Rule>>) -> ::pest::ParseResult<Box<::pest::ParserState<Rule>>> {
28                 $pattern
29             }
30         }
31     }
32 }
33 
34 macro_rules! generate_public_rule {
35     ($name: ident, $pattern: expr) => {
36         quote! {
37             #[inline]
38             #[allow(dead_code, non_snake_case, unused_variables)]
39             pub fn $name(state: Box<::pest::ParserState<Rule>>) -> ::pest::ParseResult<Box<::pest::ParserState<Rule>>> {
40                 $pattern
41             }
42         }
43     }
44 }
45