diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-02-27 23:49:25 -0800 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-03-11 00:28:25 -0700 |
| commit | eb4cbd55a859be68d381ce4fdb597b0893c18c04 (patch) | |
| tree | f4240852dd1c31e8494306acfd331a9946f0c0d6 /src/libsyntax/ext/base.rs | |
| parent | 294d3ddb89c86a91b0ac7298a31e729a9192171f (diff) | |
| download | rust-eb4cbd55a859be68d381ce4fdb597b0893c18c04.tar.gz rust-eb4cbd55a859be68d381ce4fdb597b0893c18c04.zip | |
Add an ItemModifier syntax extension type
Where ItemDecorator creates new items given a single item, ItemModifier alters the tagged item in place. The expansion rules for this are a bit weird, but I think are the most reasonable option available. When an item is expanded, all ItemModifier attributes are stripped from it and the item is folded through all ItemModifiers. At that point, the process repeats until there are no ItemModifiers in the new item.
Diffstat (limited to 'src/libsyntax/ext/base.rs')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 459c0d1d0e3..ae8c13a5f98 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -38,6 +38,9 @@ pub struct MacroDef { pub type ItemDecorator = fn(&mut ExtCtxt, Span, @ast::MetaItem, @ast::Item, |@ast::Item|); +pub type ItemModifier = + fn(&mut ExtCtxt, Span, @ast::MetaItem, @ast::Item) -> @ast::Item; + pub struct BasicMacroExpander { expander: MacroExpanderFn, span: Option<Span> @@ -126,21 +129,27 @@ impl MacResult { } } +/// An enum representing the different kinds of syntax extensions. pub enum SyntaxExtension { - // #[deriving] and such + /// A syntax extension that is attached to an item and creates new items + /// based upon it. + /// + /// `#[deriving(...)]` is an `ItemDecorator`. ItemDecorator(ItemDecorator), - // Token-tree expanders - NormalTT(~MacroExpander:'static, Option<Span>), + /// A syntax extension that is attached to an item and modifies it + /// in-place. + ItemModifier(ItemModifier), - // An IdentTT is a macro that has an - // identifier in between the name of the - // macro and the argument. Currently, - // the only examples of this is - // macro_rules! + /// A normal, function-like syntax extension. + /// + /// `bytes!` is a `NormalTT`. + NormalTT(~MacroExpander:'static, Option<Span>), - // perhaps macro_rules! will lose its odd special identifier argument, - // and this can go away also + /// A function-like syntax extension that has an extra ident before + /// the block. + /// + /// `macro_rules!` is an `IdentTT`. IdentTT(~IdentMacroExpander:'static, Option<Span>), } |
