Skip to content

Commit bd92499

Browse files
paulstansifergraydon
authored andcommitted
Allow parsing of macros in statement position.
1 parent 9814e58 commit bd92499

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ use ast::{_mod, add, arg, arm, attribute,
5252
pat_tup, pat_uniq, pat_wild, path, private, Proto, ProtoBare,
5353
ProtoBorrowed, ProtoBox, ProtoUniq, provided, public, pure_fn,
5454
purity, re_static, re_self, re_anon, re_named, region,
55-
rem, required, ret_style,
56-
return_val, self_ty, shl, shr, stmt, stmt_decl, stmt_expr,
57-
stmt_semi, struct_def, struct_field, struct_variant_kind,
58-
subtract, sty_box, sty_by_ref, sty_region, sty_static, sty_uniq,
59-
sty_value, token_tree, trait_method, trait_ref, tt_delim, tt_seq,
60-
tt_tok, tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot,
55+
rem, required, ret_style, return_val, self_ty, shl, shr, stmt,
56+
stmt_decl, stmt_expr, stmt_semi, stmt_mac, struct_def,
57+
struct_field, struct_variant_kind, subtract, sty_box, sty_by_ref,
58+
sty_region, sty_static, sty_uniq, sty_value, token_tree,
59+
trait_method, trait_ref, tt_delim, tt_seq, tt_tok,
60+
tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot,
6161
ty_box, ty_field, ty_fn, ty_infer, ty_mac, ty_method, ty_nil,
6262
ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr,
6363
ty_tup, ty_u32, ty_uniq, ty_vec, ty_fixed_length_vec,
@@ -2207,6 +2207,39 @@ impl Parser {
22072207
self.expect_keyword(~"let");
22082208
let decl = self.parse_let();
22092209
return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
2210+
} else if is_ident(self.token)
2211+
&& !self.is_any_keyword(copy self.token)
2212+
&& self.look_ahead(1) == token::NOT {
2213+
// Potential trouble: if we allow macros with paths instead of
2214+
// idents, we'd need to look ahead past the whole path here...
2215+
let pth = self.parse_value_path();
2216+
self.bump();
2217+
2218+
let id = if self.token == token::LPAREN {
2219+
token::special_idents::invalid // no special identifier
2220+
} else {
2221+
self.parse_ident()
2222+
};
2223+
2224+
let tts = self.parse_unspanned_seq(
2225+
token::LPAREN, token::RPAREN, seq_sep_none(),
2226+
|p| p.parse_token_tree());
2227+
let hi = self.span.hi;
2228+
2229+
if id == token::special_idents::invalid {
2230+
return @spanned(lo, hi, stmt_mac(
2231+
spanned(lo, hi, mac_invoc_tt(pth, tts))));
2232+
} else {
2233+
// if it has a special ident, it's definitely an item
2234+
return @spanned(lo, hi, stmt_decl(
2235+
@spanned(lo, hi, decl_item(
2236+
self.mk_item(
2237+
lo, hi, id /*id is good here*/,
2238+
item_mac(spanned(lo, hi, mac_invoc_tt(pth, tts))),
2239+
inherited, ~[/*no attrs*/]))),
2240+
self.get_id()));
2241+
}
2242+
22102243
} else {
22112244
let mut item_attrs;
22122245
match self.parse_outer_attrs_or_ext(first_item_attrs) {

0 commit comments

Comments
 (0)