2011-06-15 11:19:50 -07:00
|
|
|
|
2011-06-04 15:41:45 -04:00
|
|
|
import std::option;
|
|
|
|
import std::map::hashmap;
|
|
|
|
import driver::session::session;
|
2011-06-04 17:31:44 -04:00
|
|
|
import front::parser::parser;
|
2011-06-04 15:41:45 -04:00
|
|
|
import util::common::span;
|
|
|
|
import util::common::new_str_hash;
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type syntax_expander =
|
|
|
|
fn(&ext_ctxt, span, &vec[@ast::expr], option::t[str]) -> @ast::expr ;
|
|
|
|
|
2011-06-04 15:41:45 -04:00
|
|
|
|
|
|
|
// Temporary: to introduce a tag in order to make a recursive type work
|
2011-06-15 11:19:50 -07:00
|
|
|
tag syntax_extension { x(syntax_expander); }
|
|
|
|
|
2011-06-04 15:41:45 -04:00
|
|
|
|
|
|
|
// A temporary hard-coded map of methods for expanding syntax extension
|
|
|
|
// AST nodes into full ASTs
|
|
|
|
fn syntax_expander_table() -> hashmap[str, syntax_extension] {
|
|
|
|
auto syntax_expanders = new_str_hash[syntax_extension]();
|
|
|
|
syntax_expanders.insert("fmt", x(extfmt::expand_syntax_ext));
|
|
|
|
syntax_expanders.insert("env", x(extenv::expand_syntax_ext));
|
|
|
|
ret syntax_expanders;
|
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type span_msg_fn = fn(span, str) -> ! ;
|
|
|
|
|
|
|
|
type next_ann_fn = fn() -> ast::ann ;
|
|
|
|
|
2011-06-04 15:41:45 -04:00
|
|
|
|
|
|
|
// Provides a limited set of services necessary for syntax extensions
|
|
|
|
// to do their thing
|
2011-06-15 11:19:50 -07:00
|
|
|
type ext_ctxt =
|
2011-06-18 22:41:20 -07:00
|
|
|
rec(span_msg_fn span_fatal,
|
|
|
|
span_msg_fn span_unimpl,
|
|
|
|
next_ann_fn next_ann);
|
2011-06-04 17:31:44 -04:00
|
|
|
|
|
|
|
fn mk_ctxt(parser parser) -> ext_ctxt {
|
|
|
|
auto sess = parser.get_session();
|
2011-06-18 22:41:20 -07:00
|
|
|
fn ext_span_fatal_(session sess, span sp, str msg) -> ! {
|
|
|
|
sess.span_fatal(sp, msg);
|
2011-06-04 15:41:45 -04:00
|
|
|
}
|
2011-06-18 22:41:20 -07:00
|
|
|
auto ext_span_fatal = bind ext_span_fatal_(sess, _, _);
|
2011-06-04 16:55:32 -04:00
|
|
|
fn ext_span_unimpl_(session sess, span sp, str msg) -> ! {
|
|
|
|
sess.span_unimpl(sp, msg);
|
|
|
|
}
|
|
|
|
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
|
2011-06-04 17:31:44 -04:00
|
|
|
fn ext_next_ann_(parser parser) -> ast::ann { parser.get_ann() }
|
|
|
|
auto ext_next_ann = bind ext_next_ann_(parser);
|
2011-06-18 22:41:20 -07:00
|
|
|
ret rec(span_fatal=ext_span_fatal,
|
2011-06-15 11:19:50 -07:00
|
|
|
span_unimpl=ext_span_unimpl,
|
|
|
|
next_ann=ext_next_ann);
|
2011-06-04 15:41:45 -04:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|