convert SyntaxExtensions's key to a @~str

This commit is contained in:
Erick Tryzelaar
2013-02-14 21:17:34 -08:00
parent de5fdaf934
commit e95f21f7be
2 changed files with 31 additions and 31 deletions

View File

@@ -75,7 +75,7 @@ pub enum SyntaxExtension {
ItemTT(SyntaxExpanderTTItem), ItemTT(SyntaxExpanderTTItem),
} }
type SyntaxExtensions = HashMap<~str, SyntaxExtension>; type SyntaxExtensions = HashMap<@~str, SyntaxExtension>;
// A temporary hard-coded map of methods for expanding syntax extension // A temporary hard-coded map of methods for expanding syntax extension
// AST nodes into full ASTs // AST nodes into full ASTs
@@ -89,74 +89,74 @@ pub fn syntax_expander_table() -> SyntaxExtensions {
ItemTT(SyntaxExpanderTTItem{expander: f, span: None}) ItemTT(SyntaxExpanderTTItem{expander: f, span: None})
} }
let syntax_expanders = HashMap(); let syntax_expanders = HashMap();
syntax_expanders.insert(~"macro_rules", syntax_expanders.insert(@~"macro_rules",
builtin_item_tt( builtin_item_tt(
ext::tt::macro_rules::add_new_extension)); ext::tt::macro_rules::add_new_extension));
syntax_expanders.insert(~"fmt", syntax_expanders.insert(@~"fmt",
builtin_normal_tt(ext::fmt::expand_syntax_ext)); builtin_normal_tt(ext::fmt::expand_syntax_ext));
syntax_expanders.insert( syntax_expanders.insert(
~"auto_encode", @~"auto_encode",
ItemDecorator(ext::auto_encode::expand_auto_encode)); ItemDecorator(ext::auto_encode::expand_auto_encode));
syntax_expanders.insert( syntax_expanders.insert(
~"auto_decode", @~"auto_decode",
ItemDecorator(ext::auto_encode::expand_auto_decode)); ItemDecorator(ext::auto_encode::expand_auto_decode));
syntax_expanders.insert(~"env", syntax_expanders.insert(@~"env",
builtin_normal_tt(ext::env::expand_syntax_ext)); builtin_normal_tt(ext::env::expand_syntax_ext));
syntax_expanders.insert(~"concat_idents", syntax_expanders.insert(@~"concat_idents",
builtin_normal_tt( builtin_normal_tt(
ext::concat_idents::expand_syntax_ext)); ext::concat_idents::expand_syntax_ext));
syntax_expanders.insert(~"log_syntax", syntax_expanders.insert(@~"log_syntax",
builtin_normal_tt( builtin_normal_tt(
ext::log_syntax::expand_syntax_ext)); ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(~"deriving_eq", syntax_expanders.insert(@~"deriving_eq",
ItemDecorator( ItemDecorator(
ext::deriving::expand_deriving_eq)); ext::deriving::expand_deriving_eq));
syntax_expanders.insert(~"deriving_iter_bytes", syntax_expanders.insert(@~"deriving_iter_bytes",
ItemDecorator( ItemDecorator(
ext::deriving::expand_deriving_iter_bytes)); ext::deriving::expand_deriving_iter_bytes));
// Quasi-quoting expanders // Quasi-quoting expanders
syntax_expanders.insert(~"quote_tokens", syntax_expanders.insert(@~"quote_tokens",
builtin_normal_tt(ext::quote::expand_quote_tokens)); builtin_normal_tt(ext::quote::expand_quote_tokens));
syntax_expanders.insert(~"quote_expr", syntax_expanders.insert(@~"quote_expr",
builtin_normal_tt(ext::quote::expand_quote_expr)); builtin_normal_tt(ext::quote::expand_quote_expr));
syntax_expanders.insert(~"quote_ty", syntax_expanders.insert(@~"quote_ty",
builtin_normal_tt(ext::quote::expand_quote_ty)); builtin_normal_tt(ext::quote::expand_quote_ty));
syntax_expanders.insert(~"quote_item", syntax_expanders.insert(@~"quote_item",
builtin_normal_tt(ext::quote::expand_quote_item)); builtin_normal_tt(ext::quote::expand_quote_item));
syntax_expanders.insert(~"quote_pat", syntax_expanders.insert(@~"quote_pat",
builtin_normal_tt(ext::quote::expand_quote_pat)); builtin_normal_tt(ext::quote::expand_quote_pat));
syntax_expanders.insert(~"quote_stmt", syntax_expanders.insert(@~"quote_stmt",
builtin_normal_tt(ext::quote::expand_quote_stmt)); builtin_normal_tt(ext::quote::expand_quote_stmt));
syntax_expanders.insert(~"line", syntax_expanders.insert(@~"line",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_line)); ext::source_util::expand_line));
syntax_expanders.insert(~"col", syntax_expanders.insert(@~"col",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_col)); ext::source_util::expand_col));
syntax_expanders.insert(~"file", syntax_expanders.insert(@~"file",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_file)); ext::source_util::expand_file));
syntax_expanders.insert(~"stringify", syntax_expanders.insert(@~"stringify",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_stringify)); ext::source_util::expand_stringify));
syntax_expanders.insert(~"include", syntax_expanders.insert(@~"include",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_include)); ext::source_util::expand_include));
syntax_expanders.insert(~"include_str", syntax_expanders.insert(@~"include_str",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_include_str)); ext::source_util::expand_include_str));
syntax_expanders.insert(~"include_bin", syntax_expanders.insert(@~"include_bin",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_include_bin)); ext::source_util::expand_include_bin));
syntax_expanders.insert(~"module_path", syntax_expanders.insert(@~"module_path",
builtin_normal_tt( builtin_normal_tt(
ext::source_util::expand_mod)); ext::source_util::expand_mod));
syntax_expanders.insert(~"proto", syntax_expanders.insert(@~"proto",
builtin_item_tt(ext::pipes::expand_proto)); builtin_item_tt(ext::pipes::expand_proto));
syntax_expanders.insert( syntax_expanders.insert(
~"trace_macros", @~"trace_macros",
builtin_normal_tt(ext::trace_macros::expand_trace_macros)); builtin_normal_tt(ext::trace_macros::expand_trace_macros));
return syntax_expanders; return syntax_expanders;
} }

View File

@@ -41,7 +41,7 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt,
/* using idents and token::special_idents would make the /* using idents and token::special_idents would make the
the macro names be hygienic */ the macro names be hygienic */
let extname = cx.parse_sess().interner.get(pth.idents[0]); let extname = cx.parse_sess().interner.get(pth.idents[0]);
match exts.find(extname) { match exts.find(&extname) {
None => { None => {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!("macro undefined: '%s'", *extname)) fmt!("macro undefined: '%s'", *extname))
@@ -102,7 +102,7 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt,
do vec::foldr(item.attrs, ~[*item]) |attr, items| { do vec::foldr(item.attrs, ~[*item]) |attr, items| {
let mname = attr::get_attr_name(attr); let mname = attr::get_attr_name(attr);
match exts.find(&*mname) { match exts.find(&mname) {
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items, None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
Some(ItemDecorator(dec_fn)) => { Some(ItemDecorator(dec_fn)) => {
cx.bt_push(ExpandedFrom({call_site: attr.span, cx.bt_push(ExpandedFrom({call_site: attr.span,
@@ -159,7 +159,7 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
}; };
let extname = cx.parse_sess().interner.get(pth.idents[0]); let extname = cx.parse_sess().interner.get(pth.idents[0]);
let expanded = match exts.find(extname) { let expanded = match exts.find(&extname) {
None => cx.span_fatal(pth.span, None => cx.span_fatal(pth.span,
fmt!("macro undefined: '%s!'", *extname)), fmt!("macro undefined: '%s!'", *extname)),
@@ -198,7 +198,7 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
MRAny(_, item_maker, _) => MRAny(_, item_maker, _) =>
option::chain(item_maker(), |i| {fld.fold_item(i)}), option::chain(item_maker(), |i| {fld.fold_item(i)}),
MRDef(ref mdef) => { MRDef(ref mdef) => {
exts.insert((*mdef).name, (*mdef).ext); exts.insert(@/*bad*/ copy mdef.name, (*mdef).ext);
None None
} }
}; };
@@ -222,7 +222,7 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt,
assert(vec::len(pth.idents) == 1u); assert(vec::len(pth.idents) == 1u);
let extname = cx.parse_sess().interner.get(pth.idents[0]); let extname = cx.parse_sess().interner.get(pth.idents[0]);
let (fully_expanded, sp) = match exts.find(extname) { let (fully_expanded, sp) = match exts.find(&extname) {
None => None =>
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)),