From 2ea9c8df0f7c9ee72913883128b37d0a80d2f4f6 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 11 Jul 2012 23:42:26 -0700 Subject: Accept prefix notation for writing the types of str/~ and friends. --- src/libsyntax/ext/auto_serialize.rs | 25 +++++++++++++++++++++++-- src/libsyntax/ext/simplext.rs | 2 +- src/libsyntax/ext/tt/transcribe.rs | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 0de49367b17..e32ebf4eae5 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -218,7 +218,7 @@ impl helpers for ext_ctxt { ast::expr_alt(v, arms, ast::alt_exhaustive))) } - fn lit_str(span: span, s: @str) -> @ast::expr { + fn lit_str(span: span, s: @str/~) -> @ast::expr { self.expr( span, ast::expr_lit( @@ -343,8 +343,19 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty, cx.lambda(cx.blk(ty.span, ser_ty(cx, tps, ty, s, v))) } +fn is_vec_or_str(ty: @ast::ty) -> bool { + alt ty.node { + ast::ty_vec(_) { true } + // This may be wrong if the user has shadowed (!) str + ast::ty_path(@{span: _, global: _, idents: ids, + rp: none, types: _}, _) + if ids == ~[@"str"] { true } + _ { false } + } +} + fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, - ty: @ast::ty, -s: @ast::expr, -v: @ast::expr) + ty: @ast::ty, -s: @ast::expr, -v: @ast::expr) -> ~[@ast::stmt] { let ext_cx = cx; // required for #ast{} @@ -365,6 +376,11 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, ~[#ast(stmt){$(s).emit_box($(l));}] } + // For unique evecs/estrs, just pass through to underlying vec or str + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + ser_ty(cx, tps, mt.ty, s, v) + } + ast::ty_uniq(mt) { let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) }); ~[#ast(stmt){$(s).emit_uniq($(l));}] @@ -612,6 +628,11 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ @$(d).read_box($(l)) } } + // For unique evecs/estrs, just pass through to underlying vec or str + ast::ty_uniq(mt) if is_vec_or_str(mt.ty) { + deser_ty(cx, tps, mt.ty, d) + } + ast::ty_uniq(mt) { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ ~$(d).read_uniq($(l)) } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index c9355f05e38..0d415ccfc43 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -679,7 +679,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body) -> base::macro_def { let args = get_mac_args_no_max(cx, sp, arg, 0u, "macro"); - let mut macro_name: option<@str> = none; + let mut macro_name: option<@str/~> = none; let mut clauses: ~[@clause] = ~[]; for args.each |arg| { alt arg.node { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 8924c5820a9..113fdea42e4 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -24,7 +24,7 @@ type tt_frame = @{ type tt_reader = @{ sp_diag: span_handler, - interner: @interner<@str>, + interner: @interner<@str/~>, mut cur: tt_frame, /* for MBE-style macro transcription */ interpolations: std::map::hashmap, @@ -38,7 +38,7 @@ type tt_reader = @{ /** This can do Macro-By-Example transcription. On the other hand, if * `src` contains no `tt_dotdotdot`s and `tt_interpolate`s, `interp` can (and * should) be none. */ -fn new_tt_reader(sp_diag: span_handler, itr: @interner<@str>, +fn new_tt_reader(sp_diag: span_handler, itr: @interner<@str/~>, interp: option>, src: ~[ast::token_tree]) -> tt_reader { -- cgit 1.4.1-3-g733a5