Skip to content

Commit e18d70f

Browse files
committed
Implement Macro By Example.
1 parent 4a6ccf3 commit e18d70f

File tree

7 files changed

+643
-211
lines changed

7 files changed

+643
-211
lines changed

src/comp/syntax/ext/base.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
2828
}
2929

3030
type span_msg_fn = fn(span, str) -> ! ;
31+
type msg_fn = fn(str) -> ! ;
3132

3233
type next_id_fn = fn() -> ast::node_id ;
3334

@@ -38,6 +39,8 @@ type ext_ctxt =
3839
rec(str crate_file_name_hack,
3940
span_msg_fn span_fatal,
4041
span_msg_fn span_unimpl,
42+
span_msg_fn span_bug,
43+
msg_fn bug,
4144
next_id_fn next_id);
4245

4346
fn mk_ctxt(&session sess) -> ext_ctxt {
@@ -50,6 +53,18 @@ fn mk_ctxt(&session sess) -> ext_ctxt {
5053
sess.span_err(sp, "unimplemented " + msg);
5154
fail;
5255
}
56+
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
57+
fn ext_span_bug_(&session sess, span sp, str msg) -> ! {
58+
sess.span_bug(sp, msg);
59+
fail;
60+
}
61+
auto ext_span_bug = bind ext_span_bug_(sess, _, _);
62+
fn ext_bug_(&session sess, str msg) -> ! {
63+
sess.bug(msg);
64+
fail;
65+
}
66+
auto ext_bug = bind ext_bug_(sess, _);
67+
5368

5469
// FIXME: Some extensions work by building ASTs with paths to functions
5570
// they need to call at runtime. As those functions live in the std crate,
@@ -59,14 +74,16 @@ fn mk_ctxt(&session sess) -> ext_ctxt {
5974
// use it to guess whether paths should be prepended with "std::". This is
6075
// super-ugly and needs a better solution.
6176
auto crate_file_name_hack = sess.get_codemap().files.(0).name;
62-
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
77+
6378
fn ext_next_id_(&session sess) -> ast::node_id {
6479
ret sess.next_node_id(); // temporary, until bind works better
6580
}
6681
auto ext_next_id = bind ext_next_id_(sess);
6782
ret rec(crate_file_name_hack=crate_file_name_hack,
6883
span_fatal=ext_span_fatal,
6984
span_unimpl=ext_span_unimpl,
85+
span_bug=ext_span_bug,
86+
bug=ext_bug,
7087
next_id=ext_next_id);
7188
}
7289

0 commit comments

Comments
 (0)