diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-12-12 17:08:09 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-12-12 17:08:09 -0800 |
| commit | 9a4c669867765d42bdd13fc09eb9a32b7a667a43 (patch) | |
| tree | 64a4ba0ae49ece9b0a1b29c112d0a5b21fba7efe | |
| parent | e24ae85025e40aa17915f6c604d89aefbca274bd (diff) | |
| download | rust-9a4c669867765d42bdd13fc09eb9a32b7a667a43.tar.gz rust-9a4c669867765d42bdd13fc09eb9a32b7a667a43.zip | |
syntax: remove remaining #syntaxext machinery. Close #3516.
| -rw-r--r-- | src/libsyntax/ast.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 151 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/ext/env.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/ext/fmt.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/ident_to_str.rs | 20 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 76 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/syntax.rc | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/ext-noname.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/extenv-no-args.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/extenv-too-many-args.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/extfmt-no-args.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/class-attributes-1.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/syntax-extension-minor.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/syntax-extension-source-utils.rs | 2 |
18 files changed, 150 insertions, 272 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 160dc43a3b9..c21aa7d248e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -831,14 +831,6 @@ enum matcher_ { type mac = spanned<mac_>; -type mac_arg = Option<@expr>; - -#[auto_serialize] -#[auto_deserialize] -type mac_body_ = {span: span}; - -type mac_body = Option<mac_body_>; - #[auto_serialize] #[auto_deserialize] enum mac_ { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 08f8746c45e..a5ed1f5e101 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -13,11 +13,8 @@ use parse::parser; use diagnostic::span_handler; use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom}; use ast_util::dummy_sp; +use parse::token; -// obsolete old-style #macro code: -// -// syntax_expander, normal, builtin -// // new-style macro! tt code: // // syntax_expander_tt, syntax_expander_tt_item, mac_result, @@ -27,12 +24,6 @@ use ast_util::dummy_sp; // is now probably a redundant AST node, can be merged with // ast::mac_invoc_tt. -// second argument is the span to blame for general argument problems -type syntax_expander_ = - fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> @ast::expr; -// second argument is the origin of the macro, if user-defined -type syntax_expander = {expander: syntax_expander_, span: Option<span>}; - type macro_def = {name: ~str, ext: syntax_extension}; type item_decorator = @@ -56,10 +47,7 @@ enum mac_result { enum syntax_extension { - // normal() is obsolete, remove when #old_macros go away. - normal(syntax_expander), - - // #[auto_serialize] and such. will probably survive death of #old_macros + // #[auto_serialize] and such item_decorator(item_decorator), // Token-tree expanders @@ -73,8 +61,6 @@ enum syntax_extension { // A temporary hard-coded map of methods for expanding syntax extension // AST nodes into full ASTs fn syntax_expander_table() -> HashMap<~str, syntax_extension> { - fn builtin(f: syntax_expander_) -> syntax_extension - {normal({expander: f, span: None})} fn builtin_normal_tt(f: syntax_expander_tt_) -> syntax_extension { normal_tt({expander: f, span: None}) } @@ -85,18 +71,19 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> { syntax_expanders.insert(~"macro_rules", builtin_item_tt( ext::tt::macro_rules::add_new_extension)); - syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext)); + syntax_expanders.insert(~"fmt", + builtin_normal_tt(ext::fmt::expand_syntax_ext)); syntax_expanders.insert( ~"auto_serialize", item_decorator(ext::auto_serialize::expand_auto_serialize)); syntax_expanders.insert( ~"auto_deserialize", item_decorator(ext::auto_serialize::expand_auto_deserialize)); - syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext)); + syntax_expanders.insert(~"env", + builtin_normal_tt(ext::env::expand_syntax_ext)); syntax_expanders.insert(~"concat_idents", - builtin(ext::concat_idents::expand_syntax_ext)); - syntax_expanders.insert(~"ident_to_str", - builtin(ext::ident_to_str::expand_syntax_ext)); + builtin_normal_tt( + ext::concat_idents::expand_syntax_ext)); syntax_expanders.insert(~"log_syntax", builtin_normal_tt( ext::log_syntax::expand_syntax_ext)); @@ -122,21 +109,29 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> { builtin_normal_tt(ext::quote::expand_quote_stmt)); syntax_expanders.insert(~"line", - builtin(ext::source_util::expand_line)); + builtin_normal_tt( + ext::source_util::expand_line)); syntax_expanders.insert(~"col", - builtin(ext::source_util::expand_col)); + builtin_normal_tt( + ext::source_util::expand_col)); syntax_expanders.insert(~"file", - builtin(ext::source_util::expand_file)); + builtin_normal_tt( + ext::source_util::expand_file)); syntax_expanders.insert(~"stringify", - builtin(ext::source_util::expand_stringify)); + builtin_normal_tt( + ext::source_util::expand_stringify)); syntax_expanders.insert(~"include", - builtin(ext::source_util::expand_include)); + builtin_normal_tt( + ext::source_util::expand_include)); syntax_expanders.insert(~"include_str", - builtin(ext::source_util::expand_include_str)); + builtin_normal_tt( + ext::source_util::expand_include_str)); syntax_expanders.insert(~"include_bin", - builtin(ext::source_util::expand_include_bin)); + builtin_normal_tt( + ext::source_util::expand_include_bin)); syntax_expanders.insert(~"module_path", - builtin(ext::source_util::expand_mod)); + builtin_normal_tt( + ext::source_util::expand_mod)); syntax_expanders.insert(~"proto", builtin_item_tt(ext::pipes::expand_proto)); syntax_expanders.insert( @@ -292,87 +287,39 @@ fn expr_to_ident(cx: ext_ctxt, } } -fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - min: uint, name: ~str) -> ~[@ast::expr] { - return get_mac_args(cx, sp, arg, min, None, name); +fn check_zero_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree], + name: &str) { + if tts.len() != 0 { + cx.span_fatal(sp, fmt!("%s takes no arguments", name)); + } } -fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - min: uint, max: Option<uint>, name: ~str) -> ~[@ast::expr] { - match arg { - Some(expr) => match expr.node { - ast::expr_vec(elts, _) => { - let elts_len = vec::len(elts); - match max { - Some(max) if ! (min <= elts_len && elts_len <= max) => { - cx.span_fatal(sp, - fmt!("%s! takes between %u and %u arguments.", - name, min, max)); - } - None if ! (min <= elts_len) => { - cx.span_fatal(sp, fmt!("%s! needs at least %u arguments.", - name, min)); - } - _ => return elts /* we are good */ - } - } - _ => { - cx.span_fatal(sp, fmt!("%s!: malformed invocation", name)) - } - }, - None => cx.span_fatal(sp, fmt!("%s!: missing arguments", name)) +fn get_single_str_from_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree], + name: &str) -> ~str { + if tts.len() != 1 { + cx.span_fatal(sp, fmt!("%s takes 1 argument.", name)); } -} -fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) - -> ast::mac_body_ -{ - match (args) { - Some(body) => body, - None => cx.span_fatal(sp, ~"missing macro body") + match tts[0] { + ast::tt_tok(_, token::LIT_STR(ident)) => cx.str_of(ident), + _ => + cx.span_fatal(sp, fmt!("%s requires a string.", name)) } } -// Massage syntactic form of new-style arguments to internal representation -// of old-style macro args, such that old-style macro can be run and invoked -// using new syntax. This will be obsolete when #old_macros go away. -fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) - -> ast::mac_arg { - use ast::{matcher, matcher_, match_tok, match_seq, match_nonterminal}; - use parse::lexer::{new_tt_reader, reader}; - use tt::macro_parser::{parse_or_else, matched_seq, - matched_nonterminal}; - - // these spans won't matter, anyways - fn ms(m: matcher_) -> matcher { - {node: m, span: dummy_sp()} +fn get_exprs_from_tts(cx: ext_ctxt, tts: ~[ast::token_tree]) + -> ~[@ast::expr] { + let p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), + tts); + let mut es = ~[]; + while p.token != token::EOF { + if es.len() != 0 { + p.eat(token::COMMA); + } + es.push(p.parse_expr()); } - let arg_nm = cx.parse_sess().interner.gensym(@~"arg"); - - let argument_gram = ~[ms(match_seq(~[ - ms(match_nonterminal(arg_nm, parse::token::special_idents::expr, 0u)) - ], Some(parse::token::COMMA), true, 0u, 1u))]; - - let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic, - cx.parse_sess().interner, None, arg); - let args = - match parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, - argument_gram).get(arg_nm) { - @matched_seq(s, _) => { - do s.map() |lf| { - match *lf { - @matched_nonterminal(parse::token::nt_expr(arg)) => - arg, /* whew! list of exprs, here we come! */ - _ => fail ~"badly-structured parse result" - } - } - }, - _ => fail ~"badly-structured parse result" - }; - - return Some(@{id: parse::next_node_id(cx.parse_sess()), - callee_id: parse::next_node_id(cx.parse_sess()), - node: ast::expr_vec(args, ast::m_imm), span: sp}); + es } // diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index b6fb3a75938..a47b64bea3a 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -10,19 +10,32 @@ use base::*; -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,1u,~"concat_idents"); +fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { let mut res_str = ~""; - for args.each |e| { - res_str += *cx.parse_sess().interner.get( - expr_to_ident(cx, *e, ~"expected an ident")); + for tts.eachi |i, e| { + if i & 1 == 1 { + match *e { + ast::tt_tok(_, token::COMMA) => (), + _ => cx.span_fatal(sp, ~"concat_idents! \ + expecting comma.") + } + } else { + match *e { + ast::tt_tok(_, token::IDENT(ident,_)) => + res_str += cx.str_of(ident), + _ => cx.span_fatal(sp, ~"concat_idents! \ + requires ident args.") + } + } } let res = cx.parse_sess().interner.intern(@res_str); - return @{id: cx.next_id(), - callee_id: cx.next_id(), - node: ast::expr_path(@{span: sp, global: false, idents: ~[res], - rp: None, types: ~[]}), - span: sp}; + let e = @{id: cx.next_id(), + callee_id: cx.next_id(), + node: ast::expr_path(@{span: sp, global: false, + idents: ~[res], + rp: None, types: ~[]}), + span: sp}; + mr_expr(e) } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 51db63c819a..68db1b41781 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -18,18 +18,19 @@ use base::*; use build::mk_uniq_str; export expand_syntax_ext; -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(cx, sp, arg, 1u, option::Some(1u), ~"env"); +fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + + let var = get_single_str_from_tts(cx, sp, tts, "env!"); // FIXME (#2248): if this was more thorough it would manufacture an // Option<str> rather than just an maybe-empty string. - let var = expr_to_str(cx, args[0], ~"env! requires a string"); - match os::getenv(var) { - option::None => return mk_uniq_str(cx, sp, ~""), - option::Some(ref s) => return mk_uniq_str(cx, sp, (*s)) - } + let e = match os::getenv(var) { + option::None => mk_uniq_str(cx, sp, ~""), + option::Some(ref s) => mk_uniq_str(cx, sp, (*s)) + }; + mr_expr(e) } // diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 391edbbb799..a35f351451b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -62,21 +62,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, s) } - Some(normal({expander: exp, span: exp_sp})) => { - cx.bt_push(ExpandedFrom({call_site: s, - callie: {name: *extname, span: exp_sp}})); - - //convert the new-style invoc for the old-style macro - let arg = base::tt_args_to_original_flavor(cx, pth.span, - (*tts)); - let expanded = exp(cx, (*mac).span, arg, None); - - //keep going, outside-in - let fully_expanded = fld.fold_expr(expanded).node; - cx.bt_pop(); - - (fully_expanded, s) - } _ => { cx.span_fatal(pth.span, fmt!("'%s' is not a tt-style macro", @@ -119,8 +104,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, ast::meta_list(ref n, _) => (*n) }; match exts.find(mname) { - None | Some(normal(_)) - | Some(normal_tt(_)) | Some(item_tt(*)) => items, + None | Some(normal_tt(_)) | Some(item_tt(*)) => items, Some(item_decorator(dec_fn)) => { cx.bt_push(ExpandedFrom({call_site: attr.span, callie: {name: copy mname, @@ -262,23 +246,6 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, (fully_expanded, sp) } - Some(normal({expander: exp, span: exp_sp})) => { - cx.bt_push(ExpandedFrom({call_site: sp, - callie: {name: *extname, - span: exp_sp}})); - //convert the new-style invoc for the old-style macro - let arg = base::tt_args_to_original_flavor(cx, pth.span, tts); - let exp_expr = exp(cx, mac.span, arg, None); - let expanded = @{node: stmt_expr(exp_expr, cx.next_id()), - span: exp_expr.span}; - - //keep going, outside-in - let fully_expanded = fld.fold_stmt(expanded).node; - cx.bt_pop(); - - (fully_expanded, sp) - } - _ => { cx.span_fatal(pth.span, fmt!("'%s' is not a tt-style macro", *extname)) diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index e0d3bd03f42..46003624a76 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -21,9 +21,12 @@ use codemap::span; use ext::build::*; export expand_syntax_ext; -fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - let args = get_mac_args_no_max(cx, sp, arg, 1u, ~"fmt"); +fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + let args = get_exprs_from_tts(cx, copy tts); + if args.len() == 0 { + cx.span_fatal(sp, "fmt! takes at least 1 argument."); + } let fmt = expr_to_str(cx, args[0], ~"first argument to fmt! must be a string literal."); @@ -37,7 +40,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg, parse_fmt_err_(cx, fmtspan, s) }; let pieces = parse_fmt_string(fmt, parse_fmt_err); - return pieces_to_expr(cx, sp, pieces, args); + mr_expr(pieces_to_expr(cx, sp, pieces, args)) } // FIXME (#2249): A lot of these functions for producing expressions can diff --git a/src/libsyntax/ext/ident_to_str.rs b/src/libsyntax/ext/ident_to_str.rs deleted file mode 100644 index ededc1a5f7f..00000000000 --- a/src/libsyntax/ext/ident_to_str.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use base::*; -use build::mk_uniq_str; - -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(cx,sp,arg,1u,option::Some(1u),~"ident_to_str"); - - return mk_uniq_str(cx, sp, *cx.parse_sess().interner.get( - expr_to_ident(cx, args[0u], ~"expected an ident"))); -} diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index aa97646c054..8d2b9163f15 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -23,63 +23,58 @@ export expand_include_str; export expand_include_bin; /* line!(): expands to the current line number */ -fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"line"); +fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + base::check_zero_tts(cx, sp, tts, "line!"); let loc = cx.codemap().lookup_char_pos(sp.lo); - return mk_uint(cx, sp, loc.line); + base::mr_expr(mk_uint(cx, sp, loc.line)) } /* col!(): expands to the current column number */ -fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"col"); +fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + base::check_zero_tts(cx, sp, tts, "col!"); let loc = cx.codemap().lookup_char_pos(sp.lo); - return mk_uint(cx, sp, loc.col.to_uint()); + base::mr_expr(mk_uint(cx, sp, loc.col.to_uint())) } /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file"); +fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + base::check_zero_tts(cx, sp, tts, "file!"); let Loc { file: @FileMap { name: filename, _ }, _ } = cx.codemap().lookup_char_pos(sp.lo); - return mk_uniq_str(cx, sp, filename); + base::mr_expr(mk_uniq_str(cx, sp, filename)) } -fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"stringify"); - let s = pprust::expr_to_str(args[0], cx.parse_sess().interner); - return mk_uniq_str(cx, sp, s); +fn expand_stringify(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + let s = pprust::tts_to_str(tts, cx.parse_sess().interner); + base::mr_expr(mk_uniq_str(cx, sp, s)) } -fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) - -> @ast::expr { - get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file"); - return mk_uniq_str(cx, sp, - str::connect(cx.mod_path().map( - |x| cx.str_of(*x)), ~"::")); +fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + base::check_zero_tts(cx, sp, tts, "module_path!"); + base::mr_expr(mk_uniq_str(cx, sp, + str::connect(cx.mod_path().map( + |x| cx.str_of(*x)), ~"::"))) } -fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"include"); - let file = expr_to_str(cx, args[0], ~"include_str! requires a string"); +fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( cx.parse_sess(), cx.cfg(), &res_rel_file(cx, sp, &Path(file)), sp); - return p.parse_expr(); + base::mr_expr(p.parse_expr()) } -fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_str"); - - let file = expr_to_str(cx, args[0], ~"include_str! requires a string"); - +fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); match res { result::Ok(_) => { /* Continue. */ } @@ -88,21 +83,18 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, } } - return mk_uniq_str(cx, sp, result::unwrap(res)); + base::mr_expr(mk_uniq_str(cx, sp, result::unwrap(res))) } -fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, - _body: ast::mac_body) -> @ast::expr { - let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_bin"); - - let file = expr_to_str(cx, args[0], ~"include_bin! requires a string"); - +fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) + -> base::mac_result { + let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { result::Ok(src) => { let u8_exprs = vec::map(src, |char| { mk_u8(cx, sp, *char) }); - return mk_base_vec_e(cx, sp, u8_exprs); + base::mr_expr(mk_base_vec_e(cx, sp, u8_exprs)) } result::Err(ref e) => { cx.parse_sess().span_diagnostic.handler().fatal((*e)) diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 3e9fe805260..d90341254cc 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -154,8 +154,7 @@ fn mk_printer(out: io::Writer, linewidth: uint) -> printer { mut top: 0, mut bottom: 0, print_stack: DVec(), - mut pending_indentation: 0, - mut token_tree_last_was_ident: false}) + mut pending_indentation: 0 }) } @@ -261,7 +260,6 @@ type printer_ = { print_stack: DVec<print_stack_elt>, // buffered indentation to avoid writing trailing whitespace mut pending_indentation: int, - mut token_tree_last_was_ident: bool }; enum printer { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 684f74f3575..fa384341fb9 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -118,6 +118,10 @@ fn tt_to_str(tt: ast::token_tree, intr: @ident_interner) -> ~str { to_str(tt, print_tt, intr) } +fn tts_to_str(tts: &[ast::token_tree], intr: @ident_interner) -> ~str { + to_str(tts, print_tts, intr) +} + fn stmt_to_str(s: ast::stmt, intr: @ident_interner) -> ~str { to_str(s, print_stmt, intr) } @@ -584,9 +588,7 @@ fn print_item(s: ps, &&item: @ast::item) { print_ident(s, item.ident); cbox(s, indent_unit); popen(s); - for (*tts).each |tt| { - print_tt(s, *tt); - } + print_tts(s, *tts); pclose(s); end(s); } @@ -736,17 +738,9 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param], /// expression arguments as expressions). It can be done! I think. fn print_tt(s: ps, tt: ast::token_tree) { match tt { - ast::tt_delim(ref tts) => - for (*tts).each() |tt_elt| { print_tt(s, *tt_elt); }, + ast::tt_delim(ref tts) => print_tts(s, *tts), ast::tt_tok(_, ref tk) => { - match (*tk) { - parse::token::IDENT(*) => { // don't let idents run together - if s.s.token_tree_last_was_ident { word(s.s, ~" ") } - s.s.token_tree_last_was_ident = true; - } - _ => { s.s.token_tree_last_was_ident = false; } - } - word(s.s, parse::token::to_str(s.intr, (*tk))); + word(s.s, parse::token::to_str(s.intr, (*tk))); } ast::tt_seq(_, ref tts, ref sep, zerok) => { word(s.s, ~"$("); @@ -757,16 +751,25 @@ fn print_tt(s: ps, tt: ast::token_tree) { None => () } word(s.s, if zerok { ~"*" } else { ~"+" }); - s.s.token_tree_last_was_ident = false; } ast::tt_nonterminal(_, name) => { word(s.s, ~"$"); print_ident(s, name); - s.s.token_tree_last_was_ident = true; } } } +fn print_tts(s: ps, &&tts: &[ast::token_tree]) { + ibox(s, 0); + for tts.eachi |i, tt| { + if i != 0 { + space(s.s); + } + print_tt(s, *tt); + } + end(s); +} + fn print_variant(s: ps, v: ast::variant) { print_visibility(s, v.node.vis); match v.node.kind { @@ -1001,7 +1004,7 @@ fn print_mac(s: ps, m: ast::mac) { print_path(s, pth, false); word(s.s, ~"!"); popen(s); - for (*tts).each() |tt| { print_tt(s, *tt); } + print_tts(s, *tts); pclose(s); } } diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 00c3804cce1..fbc5f10fcd6 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -109,9 +109,6 @@ mod ext { #[path = "ext/concat_idents.rs"] mod concat_idents; #[legacy_exports] - #[path = "ext/ident_to_str.rs"] - mod ident_to_str; - #[legacy_exports] #[path = "ext/log_syntax.rs"] mod log_syntax; #[legacy_exports] diff --git a/src/test/compile-fail/ext-noname.rs b/src/test/compile-fail/ext-noname.rs deleted file mode 100644 index bf6bcd6f081..00000000000 --- a/src/test/compile-fail/ext-noname.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern:expected a syntax expander name - -fn main() { - #(); -} diff --git a/src/test/compile-fail/extenv-no-args.rs b/src/test/compile-fail/extenv-no-args.rs index 0c59ed9d339..7ff1357dcf3 100644 --- a/src/test/compile-fail/extenv-no-args.rs +++ b/src/test/compile-fail/extenv-no-args.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: env! takes between 1 and 1 arguments +// error-pattern: env! takes 1 argument fn main() { env!(); } diff --git a/src/test/compile-fail/extenv-too-many-args.rs b/src/test/compile-fail/extenv-too-many-args.rs index abd7487f50c..b1b2001abc3 100644 --- a/src/test/compile-fail/extenv-too-many-args.rs +++ b/src/test/compile-fail/extenv-too-many-args.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: env! takes between 1 and 1 arguments +// error-pattern: env! takes 1 argument fn main() { env!("one", "two"); } diff --git a/src/test/compile-fail/extfmt-no-args.rs b/src/test/compile-fail/extfmt-no-args.rs index b5d0462b436..cd9308e7b3f 100644 --- a/src/test/compile-fail/extfmt-no-args.rs +++ b/src/test/compile-fail/extfmt-no-args.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:fmt! needs at least 1 arguments +// error-pattern:fmt! takes at least 1 argument fn main() { fmt!(); } diff --git a/src/test/run-pass/class-attributes-1.rs b/src/test/run-pass/class-attributes-1.rs index d3a24488ca8..ef3a82d1e2b 100644 --- a/src/test/run-pass/class-attributes-1.rs +++ b/src/test/run-pass/class-attributes-1.rs @@ -16,7 +16,7 @@ struct cat { impl cat: Drop { #[cat_dropper] - fn finalize(&self) { error!("%s landed on hir feet",self.name); } + fn finalize(&self) { error!("%s landed on hir feet" , self . name); } } diff --git a/src/test/run-pass/syntax-extension-minor.rs b/src/test/run-pass/syntax-extension-minor.rs index dd08605ae61..aafd71d9162 100644 --- a/src/test/run-pass/syntax-extension-minor.rs +++ b/src/test/run-pass/syntax-extension-minor.rs @@ -13,6 +13,6 @@ fn main() { let asdf_fdsa = ~"<.<"; assert (concat_idents!(asd, f_f, dsa) == ~"<.<"); - assert (ident_to_str!(use_mention_distinction) == + assert (stringify!(use_mention_distinction) == ~"use_mention_distinction"); } diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index 44eb6337a6f..0d7174370a0 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -24,7 +24,7 @@ fn main() { assert(line!() == 24); assert(col!() == 11); assert(file!().ends_with(~"syntax-extension-source-utils.rs")); - assert(stringify!((2*3) + 5) == ~"(2 * 3) + 5"); + assert(stringify!((2*3) + 5) == ~"( 2 * 3 ) + 5"); assert(include!("syntax-extension-source-utils-files/includeme.fragment") == ~"victory robot 6"); |
