|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +//! Defines the crate attribute syntax for macro re-export. |
| 12 | +
|
| 13 | +use ast; |
| 14 | +use attr::AttrMetaMethods; |
| 15 | +use diagnostic::SpanHandler; |
| 16 | + |
| 17 | +/// Return a vector of the names of all macros re-exported from the crate. |
| 18 | +pub fn gather(diag: &SpanHandler, krate: &ast::Crate) -> Vec<String> { |
| 19 | + let usage = "malformed macro_reexport attribute, expected \ |
| 20 | + #![macro_reexport(ident, ident, ...)]"; |
| 21 | + |
| 22 | + let mut reexported: Vec<String> = vec!(); |
| 23 | + for attr in krate.attrs.iter() { |
| 24 | + if !attr.check_name("macro_reexport") { |
| 25 | + continue; |
| 26 | + } |
| 27 | + |
| 28 | + match attr.meta_item_list() { |
| 29 | + None => diag.span_err(attr.span, usage), |
| 30 | + Some(list) => for mi in list.iter() { |
| 31 | + match mi.node { |
| 32 | + ast::MetaWord(ref word) |
| 33 | + => reexported.push(word.to_string()), |
| 34 | + _ => diag.span_err(mi.span, usage), |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + reexported |
| 41 | +} |
0 commit comments