Fix log_syntax of unexpanded code.
This commit is contained in:
parent
a4cedd9598
commit
c0f7ed68e2
@ -68,6 +68,9 @@ enum syntax_extension {
|
||||
fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
|
||||
fn builtin(f: syntax_expander_) -> syntax_extension
|
||||
{normal({expander: f, span: none})}
|
||||
fn builtin_expr_tt(f: syntax_expander_tt_) -> syntax_extension {
|
||||
expr_tt({expander: f, span: none})
|
||||
}
|
||||
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
|
||||
item_tt({expander: f, span: none})
|
||||
}
|
||||
@ -86,7 +89,8 @@ fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
|
||||
syntax_expanders.insert(~"ident_to_str",
|
||||
builtin(ext::ident_to_str::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"log_syntax",
|
||||
builtin(ext::log_syntax::expand_syntax_ext));
|
||||
builtin_expr_tt(
|
||||
ext::log_syntax::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"ast",
|
||||
builtin(ext::qquote::expand_ast));
|
||||
syntax_expanders.insert(~"line",
|
||||
|
@ -1,16 +1,15 @@
|
||||
import base::*;
|
||||
import io::writer_util;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args_no_max(cx,sp,arg,0u,~"log_syntax");
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
|
||||
-> base::mac_result {
|
||||
|
||||
cx.print_backtrace();
|
||||
io::stdout().write_line(
|
||||
str::connect(vec::map(args,
|
||||
|&&ex| print::pprust::expr_to_str(ex)), ~", ")
|
||||
);
|
||||
print::pprust::unexpanded_tt_to_str(ast::tt_delim(tt),
|
||||
cx.parse_sess().interner));
|
||||
|
||||
//trivial expression
|
||||
return @{id: cx.next_id(), callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::none), span: sp};
|
||||
return mr_expr(@{id: cx.next_id(), callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::none), span: sp});
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import dvec::{dvec, extensions};
|
||||
import parse::classify::*;
|
||||
import util::interner;
|
||||
|
||||
type ident_interner = @interner::interner<@~str>;
|
||||
|
||||
// The ps is stored here to prevent recursive type.
|
||||
enum ann_node {
|
||||
node_block(ps, ast::blk),
|
||||
@ -48,15 +50,27 @@ fn end(s: ps) {
|
||||
|
||||
fn rust_printer(writer: io::writer) -> ps {
|
||||
return @{s: pp::mk_printer(writer, default_columns),
|
||||
cm: none::<codemap>,
|
||||
intr: @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y)),
|
||||
comments: none::<~[comments::cmnt]>,
|
||||
literals: none::<~[comments::lit]>,
|
||||
mut cur_cmnt: 0u,
|
||||
mut cur_lit: 0u,
|
||||
boxes: dvec(),
|
||||
ann: no_ann()};
|
||||
cm: none::<codemap>,
|
||||
intr: @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y)),
|
||||
comments: none::<~[comments::cmnt]>,
|
||||
literals: none::<~[comments::lit]>,
|
||||
mut cur_cmnt: 0u,
|
||||
mut cur_lit: 0u,
|
||||
boxes: dvec(),
|
||||
ann: no_ann()};
|
||||
}
|
||||
|
||||
fn unexpanded_rust_printer(writer: io::writer, intr: ident_interner) -> ps {
|
||||
return @{s: pp::mk_printer(writer, default_columns),
|
||||
cm: none::<codemap>,
|
||||
intr: intr,
|
||||
comments: none::<~[comments::cmnt]>,
|
||||
literals: none::<~[comments::lit]>,
|
||||
mut cur_cmnt: 0u,
|
||||
mut cur_lit: 0u,
|
||||
boxes: dvec(),
|
||||
ann: no_ann()};
|
||||
}
|
||||
|
||||
const indent_unit: uint = 4u;
|
||||
@ -101,6 +115,15 @@ fn pat_to_str(pat: @ast::pat) -> ~str { return to_str(pat, print_pat); }
|
||||
|
||||
fn expr_to_str(e: @ast::expr) -> ~str { return to_str(e, print_expr); }
|
||||
|
||||
fn unexpanded_tt_to_str(tt: ast::token_tree, intr: ident_interner)
|
||||
-> ~str {
|
||||
let buffer = io::mem_buffer();
|
||||
let s = unexpanded_rust_printer(io::mem_buffer_writer(buffer), intr);
|
||||
print_tt(s, tt);
|
||||
eof(s.s);
|
||||
io::mem_buffer_str(buffer)
|
||||
}
|
||||
|
||||
fn stmt_to_str(s: ast::stmt) -> ~str { return to_str(s, print_stmt); }
|
||||
|
||||
fn item_to_str(i: @ast::item) -> ~str { return to_str(i, print_item); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user