Accept prefix notation for writing the types of str/~ and friends.

This commit is contained in:
Michael Sullivan 2012-07-11 23:42:26 -07:00
parent acb86921a6
commit 2ea9c8df0f
37 changed files with 198 additions and 147 deletions

View file

@ -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)) }

View file

@ -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 {

View file

@ -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<ident, @arb_depth>,
@ -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<std::map::hashmap<ident,@arb_depth>>,
src: ~[ast::token_tree])
-> tt_reader {