Skip to content

Commit 1d6f1dc

Browse files
committed
rustc: Add a next_ann method to ext_ctxt
After this we can remove the parser from the syntax extensions, at least for now.
1 parent 3ca5fff commit 1d6f1dc

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/comp/front/ext.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import std::option;
22
import std::map::hashmap;
33

44
import driver::session::session;
5+
import front::parser::parser;
56
import util::common::span;
67
import util::common::new_str_hash;
78

@@ -24,13 +25,17 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
2425
}
2526

2627
type span_msg_fn = fn (span sp, str msg) -> !;
28+
type next_ann_fn = fn () -> ast::ann;
2729

2830
// Provides a limited set of services necessary for syntax extensions
2931
// to do their thing
3032
type ext_ctxt = rec(span_msg_fn span_err,
31-
span_msg_fn span_unimpl);
33+
span_msg_fn span_unimpl,
34+
next_ann_fn next_ann);
35+
36+
fn mk_ctxt(parser parser) -> ext_ctxt {
37+
auto sess = parser.get_session();
3238

33-
fn mk_ctxt(session sess) -> ext_ctxt {
3439
fn ext_span_err_(session sess, span sp, str msg) -> ! {
3540
sess.span_err(sp, msg);
3641
}
@@ -41,8 +46,12 @@ fn mk_ctxt(session sess) -> ext_ctxt {
4146
}
4247
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
4348

49+
fn ext_next_ann_(parser parser) -> ast::ann { parser.get_ann() }
50+
auto ext_next_ann = bind ext_next_ann_(parser);
51+
4452
ret rec(span_err = ext_span_err,
45-
span_unimpl = ext_span_unimpl);
53+
span_unimpl = ext_span_unimpl,
54+
next_ann = ext_next_ann);
4655
}
4756

4857
//

src/comp/front/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ fn expand_syntax_ext(&parser p, common::span sp,
10481048
p.err("unknown syntax expander: '" + extname + "'");
10491049
}
10501050
case (some(ext::x(?ext))) {
1051-
auto ext_cx = ext::mk_ctxt(p.get_session());
1051+
auto ext_cx = ext::mk_ctxt(p);
10521052
ret ast::expr_ext(path, args, body,
10531053
ext(ext_cx, p, sp, args, body),
10541054
p.get_ann());

0 commit comments

Comments
 (0)