Created
February 12, 2015 12:02
-
-
Save Manishearth/8aa7391ee6840f544898 to your computer and use it in GitHub Desktop.
Broken reexport generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "gen" | |
version = "0.0.1" | |
authors = ["Manish Goregaokar <[email protected]>"] | |
[lib] | |
name = "gen" | |
path = "lib.rs" | |
plugin = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(plugin, box_syntax, plugin_registrar)] | |
#[plugin] | |
#[macro_use] | |
extern crate syntax; | |
#[plugin] | |
#[macro_use] | |
extern crate rustc; | |
use rustc::lint::LintPassObject; | |
use rustc::plugin::Registry; | |
use syntax::ext::base::{Decorator, Modifier}; | |
use syntax::ext::base::ExtCtxt; | |
use syntax::codemap::Span; | |
use syntax::ptr::P; | |
use syntax::ast::{Item, MetaItem, Expr, Visibility}; | |
use syntax::ast; | |
use syntax::attr; | |
use syntax::ext::build::AstBuilder; | |
use syntax::ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct, Substructure, TraitDef, ty}; | |
use syntax::parse::token::{intern, InternedString}; | |
use std::slice::SliceConcatExt; | |
#[plugin_registrar] | |
pub fn plugin_registrar(reg: &mut Registry) { | |
reg.register_syntax_extension(intern("ree"), Decorator(box expand_ree)); | |
} | |
pub fn expand_ree(cx: &mut ExtCtxt, span: Span, _: &MetaItem, _: &Item, mut push: Box<FnMut(P<Item>)>) { | |
let mut generator = |buf: &[&str]| { | |
let path = cx.path(span, buf.iter().map(|x| intern(*x).ident()).collect()); | |
push(cx.item_use_simple(span, Visibility::Public, path)) | |
}; | |
generator(&["dom", "bindings", "FooCast"]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(plugin, box_syntax, plugin_registrar)] | |
#[plugin] | |
extern crate gen; | |
fn main(){} | |
mod dom { | |
mod attr { | |
use dom::node::FooCast; | |
} | |
mod bindings { | |
pub trait FooCast{} | |
} | |
mod node { | |
#[ree] | |
struct Node; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment