2016-08-28 23:16:43 -05:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
#![feature(plugin, plugin_registrar, rustc_private)]
|
|
|
|
|
2016-10-21 02:55:39 -05:00
|
|
|
extern crate proc_macro_tokens;
|
2016-08-28 23:16:43 -05:00
|
|
|
extern crate rustc_plugin;
|
|
|
|
extern crate syntax;
|
|
|
|
|
2016-10-21 02:55:39 -05:00
|
|
|
use proc_macro_tokens::prelude::*;
|
2016-08-28 23:16:43 -05:00
|
|
|
use rustc_plugin::Registry;
|
|
|
|
use syntax::ext::base::SyntaxExtension;
|
|
|
|
use syntax::ext::proc_macro_shim::prelude::*;
|
2016-11-17 08:04:36 -06:00
|
|
|
use syntax::symbol::Symbol;
|
2016-08-28 23:16:43 -05:00
|
|
|
|
|
|
|
#[plugin_registrar]
|
|
|
|
pub fn plugin_registrar(reg: &mut Registry) {
|
2016-11-17 08:04:36 -06:00
|
|
|
reg.register_syntax_extension(Symbol::intern("attr_tru"),
|
2016-08-28 23:16:43 -05:00
|
|
|
SyntaxExtension::AttrProcMacro(Box::new(attr_tru)));
|
2016-11-17 08:04:36 -06:00
|
|
|
reg.register_syntax_extension(Symbol::intern("attr_identity"),
|
2016-08-28 23:16:43 -05:00
|
|
|
SyntaxExtension::AttrProcMacro(Box::new(attr_identity)));
|
2016-11-17 08:04:36 -06:00
|
|
|
reg.register_syntax_extension(Symbol::intern("tru"),
|
2016-08-28 23:16:43 -05:00
|
|
|
SyntaxExtension::ProcMacro(Box::new(tru)));
|
2016-11-17 08:04:36 -06:00
|
|
|
reg.register_syntax_extension(Symbol::intern("ret_tru"),
|
2016-08-28 23:16:43 -05:00
|
|
|
SyntaxExtension::ProcMacro(Box::new(ret_tru)));
|
2016-11-17 08:04:36 -06:00
|
|
|
reg.register_syntax_extension(Symbol::intern("identity"),
|
2016-08-28 23:16:43 -05:00
|
|
|
SyntaxExtension::ProcMacro(Box::new(identity)));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn attr_tru(_attr: TokenStream, _item: TokenStream) -> TokenStream {
|
|
|
|
lex("fn f1() -> bool { true }")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn attr_identity(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
|
let source = item.to_string();
|
|
|
|
lex(&source)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tru(_ts: TokenStream) -> TokenStream {
|
|
|
|
lex("true")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ret_tru(_ts: TokenStream) -> TokenStream {
|
|
|
|
lex("return true;")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn identity(ts: TokenStream) -> TokenStream {
|
|
|
|
let source = ts.to_string();
|
|
|
|
lex(&source)
|
|
|
|
}
|