@@ -2253,7 +2253,8 @@ impl Parser {
2253
2253
2254
2254
let item_attrs = vec::append(first_item_attrs, item_attrs);
2255
2255
2256
- match self.parse_item_or_view_item(item_attrs, true, false) {
2256
+ match self.parse_item_or_view_item(item_attrs,
2257
+ true, false, false) {
2257
2258
iovi_item(i) => {
2258
2259
let mut hi = i.span.hi;
2259
2260
let decl = @spanned(lo, hi, decl_item(i));
@@ -2333,7 +2334,7 @@ impl Parser {
2333
2334
2334
2335
let {attrs_remaining, view_items, items: items, _} =
2335
2336
self.parse_items_and_view_items(first_item_attrs,
2336
- IMPORTS_AND_ITEMS_ALLOWED);
2337
+ IMPORTS_AND_ITEMS_ALLOWED, false );
2337
2338
2338
2339
for items.each |item| {
2339
2340
let decl = @spanned(item.span.lo, item.span.hi, decl_item(*item));
@@ -2968,7 +2969,8 @@ impl Parser {
2968
2969
// Shouldn't be any view items since we've already parsed an item attr
2969
2970
let {attrs_remaining, view_items, items: starting_items, _} =
2970
2971
self.parse_items_and_view_items(first_item_attrs,
2971
- VIEW_ITEMS_AND_ITEMS_ALLOWED);
2972
+ VIEW_ITEMS_AND_ITEMS_ALLOWED,
2973
+ true);
2972
2974
let mut items: ~[@item] = move starting_items;
2973
2975
2974
2976
let mut first = true;
@@ -2980,7 +2982,7 @@ impl Parser {
2980
2982
}
2981
2983
debug!(" parse_mod_items: parse_item_or_view_item( attrs=%?) ",
2982
2984
attrs);
2983
- match self.parse_item_or_view_item(attrs, true, false) {
2985
+ match self.parse_item_or_view_item(attrs, true, false, true ) {
2984
2986
iovi_item(item) => items.push(item),
2985
2987
iovi_view_item(view_item) => {
2986
2988
self.span_fatal(view_item.span, ~" view items must be \
@@ -3168,7 +3170,8 @@ impl Parser {
3168
3170
// Shouldn't be any view items since we've already parsed an item attr
3169
3171
let {attrs_remaining, view_items, items: _, foreign_items} =
3170
3172
self.parse_items_and_view_items(first_item_attrs,
3171
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED);
3173
+ VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED,
3174
+ true);
3172
3175
3173
3176
let mut items: ~[@foreign_item] = move foreign_items;
3174
3177
let mut initial_attrs = attrs_remaining;
@@ -3472,7 +3475,8 @@ impl Parser {
3472
3475
}
3473
3476
3474
3477
fn parse_item_or_view_item(+attrs: ~[attribute], items_allowed: bool,
3475
- foreign_items_allowed: bool)
3478
+ foreign_items_allowed: bool,
3479
+ macros_allowed: bool)
3476
3480
-> item_or_view_item {
3477
3481
assert items_allowed != foreign_items_allowed;
3478
3482
@@ -3581,20 +3585,22 @@ impl Parser {
3581
3585
vis: visibility,
3582
3586
span: mk_sp(lo, self.last_span.hi)
3583
3587
});
3584
- } else if items_allowed && ( !self.is_any_keyword(copy self.token)
3588
+ } else if macros_allowed && !self.is_any_keyword(copy self.token)
3585
3589
&& self.look_ahead(1) == token::NOT
3586
- && is_plain_ident(self.look_ahead(2))) {
3590
+ && (is_plain_ident(self.look_ahead(2))
3591
+ || self.look_ahead(2) == token::LPAREN
3592
+ || self.look_ahead(2) == token::LBRACE) {
3587
3593
// item macro.
3588
3594
let pth = self.parse_path_without_tps();
3589
3595
self.expect(token::NOT);
3590
3596
3591
3597
// a 'special' identifier (like what `macro_rules!` uses)
3592
3598
// is optional. We should eventually unify invoc syntax
3593
3599
// and remove this.
3594
- let id = if self.token == token::LPAREN {
3595
- token::special_idents::invalid // no special identifier
3596
- } else {
3600
+ let id = if is_plain_ident(self.token) {
3597
3601
self.parse_ident()
3602
+ } else {
3603
+ token::special_idents::invalid // no special identifier
3598
3604
};
3599
3605
let tts = match self.token {
3600
3606
token::LPAREN | token::LBRACE => {
@@ -3624,7 +3630,7 @@ impl Parser {
3624
3630
}
3625
3631
3626
3632
fn parse_item( +attrs: ~[ attribute] ) -> Option <@ast:: item> {
3627
- match self . parse_item_or_view_item( attrs, true , false ) {
3633
+ match self . parse_item_or_view_item( attrs, true , false , true ) {
3628
3634
iovi_none =>
3629
3635
None ,
3630
3636
iovi_view_item( _) =>
@@ -3762,7 +3768,8 @@ impl Parser {
3762
3768
}
3763
3769
3764
3770
fn parse_items_and_view_items(+first_item_attrs: ~[attribute],
3765
- mode: view_item_parse_mode)
3771
+ mode: view_item_parse_mode,
3772
+ macros_allowed: bool)
3766
3773
-> {attrs_remaining: ~[attribute],
3767
3774
view_items: ~[@view_item],
3768
3775
items: ~[@item],
@@ -3789,7 +3796,8 @@ impl Parser {
3789
3796
let (view_items, items, foreign_items) = (DVec(), DVec(), DVec());
3790
3797
loop {
3791
3798
match self.parse_item_or_view_item(attrs, items_allowed,
3792
- foreign_items_allowed) {
3799
+ foreign_items_allowed,
3800
+ macros_allowed) {
3793
3801
iovi_none =>
3794
3802
break,
3795
3803
iovi_view_item(view_item) => {
0 commit comments