constexpr_macros/
lib.rs

1// Copyright (c) 2018 Vladimir Motylenko
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9#[macro_use]
10extern crate proc_macro_hack;
11#[cfg_attr(test, macro_use)]
12extern crate pest;
13#[macro_use]
14extern crate pest_derive;
15
16mod grammar;
17//TODO: Add support of public methods.
18
19proc_macro_item_impl! {
20    pub fn template_impl(input: &str) -> String {
21        // TODO: Add support of rust patterns in arguments.
22        let body_start = input.find("{").expect("Couldn't find function body.");
23        let (signature, body) = input.split_at(body_start);
24        let result = grammar::parse_signature(signature);
25        let macro_name = result.macro_name();
26        let macro_signature = result.to_macro_signature();
27        let binding = result.to_binding();
28        let out = format!("macro_rules! {} {{({}) =>\
29                        {{ {{ {} {} }} }} \
30                }}", macro_name, macro_signature, binding, body);
31//        println!("out = {}", out);
32        out
33    }
34}
35
36