Skip to content

Commit ff5b804

Browse files
committed
---
yaml --- r: 123685 b: refs/heads/try c: 9ee9c49 h: refs/heads/master i: 123683: 9f24dd7 v: v3
1 parent 23a13e3 commit ff5b804

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: da4e4e4e0a7778a85748aa4a303b13f603e96b4b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8ddd286ea4ba4384a0dc9eae393ed515460a986e
5-
refs/heads/try: 92c2ff6d697fe7be2d4e3979b4dec9f86b969b69
5+
refs/heads/try: 9ee9c49cb4823c5bddbd9ec1ece6dfafa9e833ea
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/plugin/registry.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use lint::LintPassObject;
1414

1515
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
16-
use syntax::ext::base::{IdentTT, ItemDecorator, ItemModifier, BasicMacroExpander};
16+
use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier, BasicMacroExpander};
1717
use syntax::ext::base::{MacroExpanderFn};
1818
use syntax::codemap::Span;
1919
use syntax::parse::token;
@@ -57,6 +57,8 @@ impl Registry {
5757
IdentTT(ext, _) => IdentTT(ext, Some(self.krate_span)),
5858
ItemDecorator(ext) => ItemDecorator(ext),
5959
ItemModifier(ext) => ItemModifier(ext),
60+
// there's probably a nicer way to signal this:
61+
LetSyntaxTT(_, _) => fail!("can't register a new LetSyntax!"),
6062
}));
6163
}
6264

branches/try/src/libsyntax/ext/base.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,15 @@ pub enum SyntaxExtension {
264264
/// A function-like syntax extension that has an extra ident before
265265
/// the block.
266266
///
267-
/// `macro_rules!` is an `IdentTT`.
268267
IdentTT(Box<IdentMacroExpander + 'static>, Option<Span>),
268+
269+
/// An ident macro that has two properties:
270+
/// - it adds a macro definition to the environment, and
271+
/// - the definition it adds doesn't introduce any new
272+
/// identifiers.
273+
///
274+
/// `macro_rules!` is a LetSyntaxTT
275+
LetSyntaxTT(Box<IdentMacroExpander + 'static>, Option<Span>),
269276
}
270277

271278
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
@@ -300,7 +307,7 @@ pub fn syntax_expander_table() -> SyntaxEnv {
300307

301308
let mut syntax_expanders = SyntaxEnv::new();
302309
syntax_expanders.insert(intern("macro_rules"),
303-
IdentTT(box BasicIdentMacroExpander {
310+
LetSyntaxTT(box BasicIdentMacroExpander {
304311
expander: ext::tt::macro_rules::add_new_extension,
305312
span: None,
306313
},

branches/try/src/libsyntax/ext/expand.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,24 @@ fn expand_item_mac(it: Gc<ast::Item>, fld: &mut MacroExpander)
484484
let marked_tts = mark_tts(tts.as_slice(), fm);
485485
expander.expand(fld.cx, it.span, it.ident, marked_tts)
486486
}
487+
Some(&LetSyntaxTT(ref expander, span)) => {
488+
if it.ident.name == parse::token::special_idents::invalid.name {
489+
fld.cx.span_err(pth.span,
490+
format!("macro {}! expects an ident argument",
491+
extnamestr.get()).as_slice());
492+
return SmallVector::zero();
493+
}
494+
fld.cx.bt_push(ExpnInfo {
495+
call_site: it.span,
496+
callee: NameAndSpan {
497+
name: extnamestr.get().to_string(),
498+
format: MacroBang,
499+
span: span
500+
}
501+
});
502+
// DON'T mark before expansion:
503+
expander.expand(fld.cx, it.span, it.ident, tts)
504+
}
487505
_ => {
488506
fld.cx.span_err(it.span,
489507
format!("{}! is not legal in item position",

0 commit comments

Comments
 (0)