Skip to content

Commit f4c093c

Browse files
committed
Change #macro to macro_rules! in some cases.
1 parent 7f5fbd4 commit f4c093c

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

src/libcore/future.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ fn from_value<A>(+val: A) -> future<A> {
6060
})
6161
}
6262

63-
fn macros() {
64-
#macro[
65-
[#move[x],
66-
unsafe { let y <- *ptr::addr_of(x); y }]
67-
];
63+
macro_rules! move{
64+
{$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } }
6865
}
6966

7067
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> {
8178
port_ <-> *port;
8279
let port = option::unwrap(port_);
8380
alt recv(port) {
84-
future_pipe::completed(data) { #move(data) }
81+
future_pipe::completed(data) { move!{data} }
8582
}
8683
}
8784
}

src/libsyntax/parse/parser.rs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,52 +101,43 @@ enum class_contents { ctor_decl(fn_decl, ~[attribute], blk, codemap::span),
101101
type arg_or_capture_item = either<arg, capture_item>;
102102
type item_info = (ident, item_, option<~[attribute]>);
103103

104-
fn dummy() {
105104

105+
/* The expr situation is not as complex as I thought it would be.
106+
The important thing is to make sure that lookahead doesn't balk
107+
at ACTUALLY tokens */
108+
macro_rules! maybe_whole_expr{
109+
{$p:expr} => { alt copy $p.token {
110+
ACTUALLY(token::w_expr(e)) {
111+
$p.bump();
112+
ret pexpr(e);
113+
}
114+
ACTUALLY(token::w_path(pt)) {
115+
$p.bump();
116+
ret $p.mk_pexpr($p.span.lo, $p.span.lo,
117+
expr_path(pt));
118+
}
119+
_ {}
120+
}}
121+
}
106122

123+
macro_rules! maybe_whole {
124+
{$p:expr, $constructor:path} => { alt copy $p.token {
125+
ACTUALLY($constructor(x)) { $p.bump(); ret x; }
126+
_ {}
127+
}}
128+
}
107129

108-
#macro[[#maybe_whole_item[p],
109-
alt copy p.token {
110-
ACTUALLY(token::w_item(i)) { p.bump(); ret i; }
111-
_ {} }]];
112-
#macro[[#maybe_whole_block[p],
113-
alt copy p.token {
114-
ACTUALLY(token::w_block(b)) { p.bump(); ret b; }
115-
_ {} }]];
116-
#macro[[#maybe_whole_stmt[p],
117-
alt copy p.token {
118-
ACTUALLY(token::w_stmt(s)) { p.bump(); ret s; }
119-
_ {} }]];
120-
#macro[[#maybe_whole_pat[p],
121-
alt copy p.token {
122-
ACTUALLY(token::w_pat(pt)) { p.bump(); ret pt; }
123-
_ {} }]];
124-
/* The expr situation is not as complex as I thought it would be.
125-
The important thing is to make sure that lookahead doesn't balk
126-
at ACTUALLY tokens */
127-
#macro[[#maybe_whole_expr_pexpr[p], /* ack! */
128-
alt copy p.token {
129-
ACTUALLY(token::w_expr(e)) {
130-
p.bump();
131-
ret pexpr(e);
132-
}
133-
ACTUALLY(token::w_path(pt)) {
134-
p.bump();
135-
ret p.mk_pexpr(p.span.lo, p.span.lo,
136-
expr_path(pt));
137-
}
138-
_ {} }]];
139-
#macro[[#maybe_whole_ty[p],
140-
alt copy p.token {
141-
ACTUALLY(token::w_ty(t)) { p.bump(); ret t; }
142-
_ {} }]];
143-
/* ident is handled by common.rs */
130+
/* ident is handled by common.rs */
131+
132+
fn dummy() {
133+
/* we will need this to bootstrap maybe_whole! */
144134
#macro[[#maybe_whole_path[p],
145135
alt p.token {
146136
ACTUALLY(token::w_path(pt)) { p.bump(); ret pt; }
147137
_ {} }]];
148138
}
149139

140+
150141
class parser {
151142
let sess: parse_sess;
152143
let cfg: crate_cfg;
@@ -734,7 +725,7 @@ class parser {
734725
}
735726
736727
fn parse_bottom_expr() -> pexpr {
737-
#maybe_whole_expr_pexpr[self];
728+
maybe_whole_expr!{self};
738729
let lo = self.span.lo;
739730
let mut hi = self.span.hi;
740731

src/test/run-pass/macro-by-example-1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99

1010
fn add(a: int, b: int) -> int { ret a + b; }
1111

12-
assert (#apply[add, [1, 15]] == 16);
12+
assert(#apply[add, [1, 15]] == 16);
13+
assert(apply!{add, [1, 15]} == 16);
1314
assert(apply_tt!{add, (1, 15)} == 16);
1415
}

0 commit comments

Comments
 (0)