rustc: Add a next_ann method to ext_ctxt
After this we can remove the parser from the syntax extensions, at least for now.
This commit is contained in:
parent
3ca5fff195
commit
1d6f1dc58d
2 changed files with 13 additions and 4 deletions
|
@ -2,6 +2,7 @@ import std::option;
|
||||||
import std::map::hashmap;
|
import std::map::hashmap;
|
||||||
|
|
||||||
import driver::session::session;
|
import driver::session::session;
|
||||||
|
import front::parser::parser;
|
||||||
import util::common::span;
|
import util::common::span;
|
||||||
import util::common::new_str_hash;
|
import util::common::new_str_hash;
|
||||||
|
|
||||||
|
@ -24,13 +25,17 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
|
||||||
}
|
}
|
||||||
|
|
||||||
type span_msg_fn = fn (span sp, str msg) -> !;
|
type span_msg_fn = fn (span sp, str msg) -> !;
|
||||||
|
type next_ann_fn = fn () -> ast::ann;
|
||||||
|
|
||||||
// Provides a limited set of services necessary for syntax extensions
|
// Provides a limited set of services necessary for syntax extensions
|
||||||
// to do their thing
|
// to do their thing
|
||||||
type ext_ctxt = rec(span_msg_fn span_err,
|
type ext_ctxt = rec(span_msg_fn span_err,
|
||||||
span_msg_fn span_unimpl);
|
span_msg_fn span_unimpl,
|
||||||
|
next_ann_fn next_ann);
|
||||||
|
|
||||||
|
fn mk_ctxt(parser parser) -> ext_ctxt {
|
||||||
|
auto sess = parser.get_session();
|
||||||
|
|
||||||
fn mk_ctxt(session sess) -> ext_ctxt {
|
|
||||||
fn ext_span_err_(session sess, span sp, str msg) -> ! {
|
fn ext_span_err_(session sess, span sp, str msg) -> ! {
|
||||||
sess.span_err(sp, msg);
|
sess.span_err(sp, msg);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +46,12 @@ fn mk_ctxt(session sess) -> ext_ctxt {
|
||||||
}
|
}
|
||||||
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
|
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
|
||||||
|
|
||||||
|
fn ext_next_ann_(parser parser) -> ast::ann { parser.get_ann() }
|
||||||
|
auto ext_next_ann = bind ext_next_ann_(parser);
|
||||||
|
|
||||||
ret rec(span_err = ext_span_err,
|
ret rec(span_err = ext_span_err,
|
||||||
span_unimpl = ext_span_unimpl);
|
span_unimpl = ext_span_unimpl,
|
||||||
|
next_ann = ext_next_ann);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ fn expand_syntax_ext(&parser p, common::span sp,
|
||||||
p.err("unknown syntax expander: '" + extname + "'");
|
p.err("unknown syntax expander: '" + extname + "'");
|
||||||
}
|
}
|
||||||
case (some(ext::x(?ext))) {
|
case (some(ext::x(?ext))) {
|
||||||
auto ext_cx = ext::mk_ctxt(p.get_session());
|
auto ext_cx = ext::mk_ctxt(p);
|
||||||
ret ast::expr_ext(path, args, body,
|
ret ast::expr_ext(path, args, body,
|
||||||
ext(ext_cx, p, sp, args, body),
|
ext(ext_cx, p, sp, args, body),
|
||||||
p.get_ann());
|
p.get_ann());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue