Change #macro
to macro_rules!
in some cases.
This commit is contained in:
parent
7f5fbd4f9d
commit
f4c093c4af
3 changed files with 36 additions and 47 deletions
|
@ -60,11 +60,8 @@ fn from_value<A>(+val: A) -> future<A> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn macros() {
|
macro_rules! move{
|
||||||
#macro[
|
{$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } }
|
||||||
[#move[x],
|
|
||||||
unsafe { let y <- *ptr::addr_of(x); y }]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
|
fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
|
||||||
|
@ -81,7 +78,7 @@ fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
|
||||||
port_ <-> *port;
|
port_ <-> *port;
|
||||||
let port = option::unwrap(port_);
|
let port = option::unwrap(port_);
|
||||||
alt recv(port) {
|
alt recv(port) {
|
||||||
future_pipe::completed(data) { #move(data) }
|
future_pipe::completed(data) { move!{data} }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,52 +101,43 @@ enum class_contents { ctor_decl(fn_decl, ~[attribute], blk, codemap::span),
|
||||||
type arg_or_capture_item = either<arg, capture_item>;
|
type arg_or_capture_item = either<arg, capture_item>;
|
||||||
type item_info = (ident, item_, option<~[attribute]>);
|
type item_info = (ident, item_, option<~[attribute]>);
|
||||||
|
|
||||||
|
|
||||||
|
/* The expr situation is not as complex as I thought it would be.
|
||||||
|
The important thing is to make sure that lookahead doesn't balk
|
||||||
|
at ACTUALLY tokens */
|
||||||
|
macro_rules! maybe_whole_expr{
|
||||||
|
{$p:expr} => { alt copy $p.token {
|
||||||
|
ACTUALLY(token::w_expr(e)) {
|
||||||
|
$p.bump();
|
||||||
|
ret pexpr(e);
|
||||||
|
}
|
||||||
|
ACTUALLY(token::w_path(pt)) {
|
||||||
|
$p.bump();
|
||||||
|
ret $p.mk_pexpr($p.span.lo, $p.span.lo,
|
||||||
|
expr_path(pt));
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! maybe_whole {
|
||||||
|
{$p:expr, $constructor:path} => { alt copy $p.token {
|
||||||
|
ACTUALLY($constructor(x)) { $p.bump(); ret x; }
|
||||||
|
_ {}
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ident is handled by common.rs */
|
||||||
|
|
||||||
fn dummy() {
|
fn dummy() {
|
||||||
|
/* we will need this to bootstrap maybe_whole! */
|
||||||
|
|
||||||
|
|
||||||
#macro[[#maybe_whole_item[p],
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_item(i)) { p.bump(); ret i; }
|
|
||||||
_ {} }]];
|
|
||||||
#macro[[#maybe_whole_block[p],
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_block(b)) { p.bump(); ret b; }
|
|
||||||
_ {} }]];
|
|
||||||
#macro[[#maybe_whole_stmt[p],
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_stmt(s)) { p.bump(); ret s; }
|
|
||||||
_ {} }]];
|
|
||||||
#macro[[#maybe_whole_pat[p],
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_pat(pt)) { p.bump(); ret pt; }
|
|
||||||
_ {} }]];
|
|
||||||
/* The expr situation is not as complex as I thought it would be.
|
|
||||||
The important thing is to make sure that lookahead doesn't balk
|
|
||||||
at ACTUALLY tokens */
|
|
||||||
#macro[[#maybe_whole_expr_pexpr[p], /* ack! */
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_expr(e)) {
|
|
||||||
p.bump();
|
|
||||||
ret pexpr(e);
|
|
||||||
}
|
|
||||||
ACTUALLY(token::w_path(pt)) {
|
|
||||||
p.bump();
|
|
||||||
ret p.mk_pexpr(p.span.lo, p.span.lo,
|
|
||||||
expr_path(pt));
|
|
||||||
}
|
|
||||||
_ {} }]];
|
|
||||||
#macro[[#maybe_whole_ty[p],
|
|
||||||
alt copy p.token {
|
|
||||||
ACTUALLY(token::w_ty(t)) { p.bump(); ret t; }
|
|
||||||
_ {} }]];
|
|
||||||
/* ident is handled by common.rs */
|
|
||||||
#macro[[#maybe_whole_path[p],
|
#macro[[#maybe_whole_path[p],
|
||||||
alt p.token {
|
alt p.token {
|
||||||
ACTUALLY(token::w_path(pt)) { p.bump(); ret pt; }
|
ACTUALLY(token::w_path(pt)) { p.bump(); ret pt; }
|
||||||
_ {} }]];
|
_ {} }]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class parser {
|
class parser {
|
||||||
let sess: parse_sess;
|
let sess: parse_sess;
|
||||||
let cfg: crate_cfg;
|
let cfg: crate_cfg;
|
||||||
|
@ -734,7 +725,7 @@ class parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bottom_expr() -> pexpr {
|
fn parse_bottom_expr() -> pexpr {
|
||||||
#maybe_whole_expr_pexpr[self];
|
maybe_whole_expr!{self};
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let mut hi = self.span.hi;
|
let mut hi = self.span.hi;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ fn main() {
|
||||||
|
|
||||||
fn add(a: int, b: int) -> int { ret a + b; }
|
fn add(a: int, b: int) -> int { ret a + b; }
|
||||||
|
|
||||||
assert (#apply[add, [1, 15]] == 16);
|
assert(#apply[add, [1, 15]] == 16);
|
||||||
|
assert(apply!{add, [1, 15]} == 16);
|
||||||
assert(apply_tt!{add, (1, 15)} == 16);
|
assert(apply_tt!{add, (1, 15)} == 16);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue