Skip to content

Commit 79f7581

Browse files
committed
---
yaml --- r: 79355 b: refs/heads/try c: 7cd65e0 h: refs/heads/master i: 79353: 412159f 79351: 5c8c929 v: v3
1 parent 9859cb7 commit 79f7581

File tree

6 files changed

+223
-86
lines changed

6 files changed

+223
-86
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: 3e6de6b7da8ee88bf84b0e217900051334be08da
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
5-
refs/heads/try: 34015c36c7154ab34e04d32ec622934ede7d0393
5+
refs/heads/try: 7cd65e0f3279080543cdcbdba914a5117fc5e7e8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

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

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub struct MacroDef {
3333
ext: SyntaxExtension
3434
}
3535

36+
// No context arg for an Item Decorator macro, simply because
37+
// adding it would require adding a ctxt field to all items.
38+
// we could do this if it turns out to be useful.
39+
3640
pub type ItemDecoratorFun = @fn(@ExtCtxt,
3741
Span,
3842
@ast::MetaItem,
@@ -41,15 +45,34 @@ pub type ItemDecoratorFun = @fn(@ExtCtxt,
4145

4246
pub type SyntaxExpanderTTFun = @fn(@ExtCtxt,
4347
Span,
44-
&[ast::token_tree])
48+
&[ast::token_tree],
49+
ast::SyntaxContext)
4550
-> MacResult;
4651

4752
pub type SyntaxExpanderTTItemFun = @fn(@ExtCtxt,
53+
Span,
54+
ast::Ident,
55+
~[ast::token_tree],
56+
ast::SyntaxContext)
57+
-> MacResult;
58+
59+
// oog... in order to make the presentation of builtin_normal_tt_no_ctxt
60+
// and builtin_ident_tt_no_ctxt palatable, we need one-off types for
61+
// functions that don't consume a ctxt:
62+
63+
pub type SyntaxExpanderTTFunNoCtxt = @fn(@ExtCtxt,
64+
Span,
65+
&[ast::token_tree])
66+
-> MacResult;
67+
68+
pub type SyntaxExpanderTTItemFunNoCtxt = @fn(@ExtCtxt,
4869
Span,
4970
ast::Ident,
5071
~[ast::token_tree])
5172
-> MacResult;
5273

74+
75+
5376
pub enum MacResult {
5477
MRExpr(@ast::Expr),
5578
MRItem(@ast::item),
@@ -78,6 +101,7 @@ pub enum SyntaxExtension {
78101
IdentTT(SyntaxExpanderTTItemFun, Option<Span>),
79102
}
80103

104+
81105
// The SyntaxEnv is the environment that's threaded through the expansion
82106
// of macros. It contains bindings for macros, and also a special binding
83107
// for " block" (not a legal identifier) that maps to a BlockInfo
@@ -109,12 +133,16 @@ type RenameList = ~[(ast::Ident,Name)];
109133
// AST nodes into full ASTs
110134
pub fn syntax_expander_table() -> SyntaxEnv {
111135
// utility function to simplify creating NormalTT syntax extensions
112-
fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> @Transformer {
113-
@SE(NormalTT(f, None))
136+
// that ignore their contexts
137+
fn builtin_normal_tt_no_ctxt(f: SyntaxExpanderTTFunNoCtxt) -> @Transformer {
138+
let wrapped_expander : SyntaxExpanderTTFun = |a,b,c,d|{f(a,b,c)};
139+
@SE(NormalTT(wrapped_expander, None))
114140
}
115141
// utility function to simplify creating IdentTT syntax extensions
116-
fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> @Transformer {
117-
@SE(IdentTT(f, None))
142+
// that ignore their contexts
143+
fn builtin_item_tt_no_ctxt(f: SyntaxExpanderTTItemFunNoCtxt) -> @Transformer {
144+
let wrapped_expander : SyntaxExpanderTTItemFun = |a,b,c,d,e|{f(a,b,c,d)};
145+
@SE(IdentTT(wrapped_expander, None))
118146
}
119147
let mut syntax_expanders = HashMap::new();
120148
// NB identifier starts with space, and can't conflict with legal idents
@@ -124,83 +152,83 @@ pub fn syntax_expander_table() -> SyntaxEnv {
124152
pending_renames : @mut ~[]
125153
}));
126154
syntax_expanders.insert(intern(&"macro_rules"),
127-
builtin_item_tt(
155+
builtin_item_tt_no_ctxt(
128156
ext::tt::macro_rules::add_new_extension));
129157
syntax_expanders.insert(intern(&"fmt"),
130-
builtin_normal_tt(ext::fmt::expand_syntax_ext));
158+
builtin_normal_tt_no_ctxt(ext::fmt::expand_syntax_ext));
131159
syntax_expanders.insert(intern(&"format"),
132-
builtin_normal_tt(ext::ifmt::expand_format));
160+
builtin_normal_tt_no_ctxt(ext::ifmt::expand_format));
133161
syntax_expanders.insert(intern(&"write"),
134-
builtin_normal_tt(ext::ifmt::expand_write));
162+
builtin_normal_tt_no_ctxt(ext::ifmt::expand_write));
135163
syntax_expanders.insert(intern(&"writeln"),
136-
builtin_normal_tt(ext::ifmt::expand_writeln));
164+
builtin_normal_tt_no_ctxt(ext::ifmt::expand_writeln));
137165
syntax_expanders.insert(
138166
intern(&"auto_encode"),
139167
@SE(ItemDecorator(ext::auto_encode::expand_auto_encode)));
140168
syntax_expanders.insert(
141169
intern(&"auto_decode"),
142170
@SE(ItemDecorator(ext::auto_encode::expand_auto_decode)));
143171
syntax_expanders.insert(intern(&"env"),
144-
builtin_normal_tt(ext::env::expand_env));
172+
builtin_normal_tt_no_ctxt(ext::env::expand_env));
145173
syntax_expanders.insert(intern(&"option_env"),
146-
builtin_normal_tt(ext::env::expand_option_env));
174+
builtin_normal_tt_no_ctxt(ext::env::expand_option_env));
147175
syntax_expanders.insert(intern("bytes"),
148-
builtin_normal_tt(ext::bytes::expand_syntax_ext));
176+
builtin_normal_tt_no_ctxt(ext::bytes::expand_syntax_ext));
149177
syntax_expanders.insert(intern("concat_idents"),
150-
builtin_normal_tt(
178+
builtin_normal_tt_no_ctxt(
151179
ext::concat_idents::expand_syntax_ext));
152180
syntax_expanders.insert(intern(&"log_syntax"),
153-
builtin_normal_tt(
181+
builtin_normal_tt_no_ctxt(
154182
ext::log_syntax::expand_syntax_ext));
155183
syntax_expanders.insert(intern(&"deriving"),
156184
@SE(ItemDecorator(
157185
ext::deriving::expand_meta_deriving)));
158186

159187
// Quasi-quoting expanders
160188
syntax_expanders.insert(intern(&"quote_tokens"),
161-
builtin_normal_tt(ext::quote::expand_quote_tokens));
189+
@SE(NormalTT(ext::quote::expand_quote_tokens, None)));
162190
syntax_expanders.insert(intern(&"quote_expr"),
163-
builtin_normal_tt(ext::quote::expand_quote_expr));
191+
@SE(NormalTT(ext::quote::expand_quote_expr, None)));
164192
syntax_expanders.insert(intern(&"quote_ty"),
165-
builtin_normal_tt(ext::quote::expand_quote_ty));
193+
@SE(NormalTT(ext::quote::expand_quote_ty, None)));
166194
syntax_expanders.insert(intern(&"quote_item"),
167-
builtin_normal_tt(ext::quote::expand_quote_item));
195+
@SE(NormalTT(ext::quote::expand_quote_item, None)));
168196
syntax_expanders.insert(intern(&"quote_pat"),
169-
builtin_normal_tt(ext::quote::expand_quote_pat));
197+
@SE(NormalTT(ext::quote::expand_quote_pat, None)));
170198
syntax_expanders.insert(intern(&"quote_stmt"),
171-
builtin_normal_tt(ext::quote::expand_quote_stmt));
199+
@SE(NormalTT(ext::quote::expand_quote_stmt, None)));
172200

173201
syntax_expanders.insert(intern(&"line"),
174-
builtin_normal_tt(
202+
builtin_normal_tt_no_ctxt(
175203
ext::source_util::expand_line));
176204
syntax_expanders.insert(intern(&"col"),
177-
builtin_normal_tt(
205+
builtin_normal_tt_no_ctxt(
178206
ext::source_util::expand_col));
179207
syntax_expanders.insert(intern(&"file"),
180-
builtin_normal_tt(
208+
builtin_normal_tt_no_ctxt(
181209
ext::source_util::expand_file));
182210
syntax_expanders.insert(intern(&"stringify"),
183-
builtin_normal_tt(
211+
builtin_normal_tt_no_ctxt(
184212
ext::source_util::expand_stringify));
185213
syntax_expanders.insert(intern(&"include"),
186-
builtin_normal_tt(
214+
builtin_normal_tt_no_ctxt(
187215
ext::source_util::expand_include));
188216
syntax_expanders.insert(intern(&"include_str"),
189-
builtin_normal_tt(
217+
builtin_normal_tt_no_ctxt(
190218
ext::source_util::expand_include_str));
191219
syntax_expanders.insert(intern(&"include_bin"),
192-
builtin_normal_tt(
220+
builtin_normal_tt_no_ctxt(
193221
ext::source_util::expand_include_bin));
194222
syntax_expanders.insert(intern(&"module_path"),
195-
builtin_normal_tt(
223+
builtin_normal_tt_no_ctxt(
196224
ext::source_util::expand_mod));
197225
syntax_expanders.insert(intern(&"asm"),
198-
builtin_normal_tt(ext::asm::expand_asm));
226+
builtin_normal_tt_no_ctxt(ext::asm::expand_asm));
199227
syntax_expanders.insert(intern(&"cfg"),
200-
builtin_normal_tt(ext::cfg::expand_cfg));
228+
builtin_normal_tt_no_ctxt(ext::cfg::expand_cfg));
201229
syntax_expanders.insert(
202230
intern(&"trace_macros"),
203-
builtin_normal_tt(ext::trace_macros::expand_trace_macros));
231+
builtin_normal_tt_no_ctxt(ext::trace_macros::expand_trace_macros));
204232
MapChain::new(~syntax_expanders)
205233
}
206234

0 commit comments

Comments
 (0)