use lint::LintPassObject;
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
-use syntax::ext::base::{IdentTT, ItemDecorator, ItemModifier, BasicMacroExpander};
+use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier, BasicMacroExpander};
use syntax::ext::base::{MacroExpanderFn};
use syntax::codemap::Span;
use syntax::parse::token;
IdentTT(ext, _) => IdentTT(ext, Some(self.krate_span)),
ItemDecorator(ext) => ItemDecorator(ext),
ItemModifier(ext) => ItemModifier(ext),
+ // there's probably a nicer way to signal this:
+ LetSyntaxTT(_, _) => fail!("can't register a new LetSyntax!"),
}));
}
/// A function-like syntax extension that has an extra ident before
/// the block.
///
- /// `macro_rules!` is an `IdentTT`.
IdentTT(Box<IdentMacroExpander + 'static>, Option<Span>),
+
+ /// An ident macro that has two properties:
+ /// - it adds a macro definition to the environment, and
+ /// - the definition it adds doesn't introduce any new
+ /// identifiers.
+ ///
+ /// `macro_rules!` is a LetSyntaxTT
+ LetSyntaxTT(Box<IdentMacroExpander + 'static>, Option<Span>),
}
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
let mut syntax_expanders = SyntaxEnv::new();
syntax_expanders.insert(intern("macro_rules"),
- IdentTT(box BasicIdentMacroExpander {
+ LetSyntaxTT(box BasicIdentMacroExpander {
expander: ext::tt::macro_rules::add_new_extension,
span: None,
},
let marked_tts = mark_tts(tts.as_slice(), fm);
expander.expand(fld.cx, it.span, it.ident, marked_tts)
}
+ Some(&LetSyntaxTT(ref expander, span)) => {
+ if it.ident.name == parse::token::special_idents::invalid.name {
+ fld.cx.span_err(pth.span,
+ format!("macro {}! expects an ident argument",
+ extnamestr.get()).as_slice());
+ return SmallVector::zero();
+ }
+ fld.cx.bt_push(ExpnInfo {
+ call_site: it.span,
+ callee: NameAndSpan {
+ name: extnamestr.get().to_string(),
+ format: MacroBang,
+ span: span
+ }
+ });
+ // DON'T mark before expansion:
+ expander.expand(fld.cx, it.span, it.ident, tts)
+ }
_ => {
fld.cx.span_err(it.span,
format!("{}! is not legal in item position",