diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/ifmt.rs | 20 |
3 files changed, 36 insertions, 11 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 560cb26d09a..6f9585652bd 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -139,10 +139,12 @@ pub fn syntax_expander_table() -> SyntaxEnv { ext::tt::macro_rules::add_new_extension)); syntax_expanders.insert(intern(&"fmt"), builtin_normal_tt(ext::fmt::expand_syntax_ext)); - syntax_expanders.insert(intern(&"ifmt"), - builtin_normal_tt(ext::ifmt::expand_sprintf)); - syntax_expanders.insert(intern(&"ifmtf"), - builtin_normal_tt(ext::ifmt::expand_fprintf)); + syntax_expanders.insert(intern(&"format"), + builtin_normal_tt(ext::ifmt::expand_format)); + syntax_expanders.insert(intern(&"write"), + builtin_normal_tt(ext::ifmt::expand_write)); + syntax_expanders.insert(intern(&"writeln"), + builtin_normal_tt(ext::ifmt::expand_writeln)); syntax_expanders.insert( intern(&"auto_encode"), @SE(ItemDecorator(ext::auto_encode::expand_auto_encode))); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4bea1dc23e7..49b8c994dc2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -940,6 +940,7 @@ pub fn std_macros() -> @str { ); ) + // NOTE(acrichto): start removing this after the next snapshot macro_rules! printf ( ($arg:expr) => ( print(fmt!(\"%?\", $arg)) @@ -949,6 +950,7 @@ pub fn std_macros() -> @str { ) ) + // NOTE(acrichto): start removing this after the next snapshot macro_rules! printfln ( ($arg:expr) => ( println(fmt!(\"%?\", $arg)) @@ -958,6 +960,21 @@ pub fn std_macros() -> @str { ) ) + // FIXME(#6846) once stdio is redesigned, this shouldn't perform an + // allocation but should rather delegate to an invocation of + // write! instead of format! + macro_rules! print ( + () => (); + ($arg:expr) => ( ::std::io::print(format!(\"{}\", $arg))); + ($fmt:expr, $($arg:tt)+) => ( ::std::io::print(format!($fmt, $($arg)+))) + ) + + // FIXME(#6846) once stdio is redesigned, this shouldn't perform an + // allocation but should rather delegate to an io::Writer + macro_rules! println ( + ($($arg:tt)*) => ({ print!($($arg)*); ::std::io::println(\"\"); }) + ) + // NOTE: use this after a snapshot lands to abstract the details // of the TLS interface. macro_rules! local_data_key ( diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index ae098735e5b..d4274746a4e 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -697,19 +697,24 @@ impl Context { } } -pub fn expand_sprintf(ecx: @ExtCtxt, sp: span, - tts: &[ast::token_tree]) -> base::MacResult { - expand_ifmt(ecx, sp, tts, false, "sprintf") +pub fn expand_format(ecx: @ExtCtxt, sp: span, + tts: &[ast::token_tree]) -> base::MacResult { + expand_ifmt(ecx, sp, tts, false, false, "format") } -pub fn expand_fprintf(ecx: @ExtCtxt, sp: span, - tts: &[ast::token_tree]) -> base::MacResult { - expand_ifmt(ecx, sp, tts, true, "fprintf") +pub fn expand_write(ecx: @ExtCtxt, sp: span, + tts: &[ast::token_tree]) -> base::MacResult { + expand_ifmt(ecx, sp, tts, true, false, "write") } +pub fn expand_writeln(ecx: @ExtCtxt, sp: span, + tts: &[ast::token_tree]) -> base::MacResult { + expand_ifmt(ecx, sp, tts, true, true, "write") +} fn expand_ifmt(ecx: @ExtCtxt, sp: span, tts: &[ast::token_tree], - leading_arg: bool, function: &str) -> base::MacResult { + leading_arg: bool, append_newline: bool, + function: &str) -> base::MacResult { let mut cx = Context { ecx: ecx, args: ~[], @@ -730,6 +735,7 @@ fn expand_ifmt(ecx: @ExtCtxt, sp: span, tts: &[ast::token_tree], cx.fmtsp = efmt.span; let fmt = expr_to_str(ecx, efmt, "format argument must be a string literal."); + let fmt = if append_newline { fmt + "\n" } else { fmt.to_owned() }; let mut err = false; do parse::parse_error::cond.trap(|m| { |
