@@ -120,7 +120,7 @@ pub enum item_or_view_item {
120
120
121
121
enum view_item_parse_mode {
122
122
VIEW_ITEMS_AND_ITEMS_ALLOWED ,
123
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED ,
123
+ FOREIGN_ITEMS_ALLOWED ,
124
124
IMPORTS_AND_ITEMS_ALLOWED
125
125
}
126
126
@@ -3535,7 +3535,7 @@ pub impl Parser {
3535
3535
items : _,
3536
3536
foreign_items : foreign_items
3537
3537
} = self . parse_items_and_view_items ( first_item_attrs,
3538
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED ,
3538
+ FOREIGN_ITEMS_ALLOWED ,
3539
3539
true ) ;
3540
3540
3541
3541
let mut items: ~[ @foreign_item] = foreign_items;
@@ -3885,12 +3885,14 @@ pub impl Parser {
3885
3885
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3886
3886
visibility,
3887
3887
maybe_append ( attrs, extra_attrs) ) ) ;
3888
- } else if foreign_items_allowed &&
3888
+ }
3889
+ if foreign_items_allowed &&
3889
3890
( self . is_keyword ( & ~"const ") || self . is_keyword ( & ~"static ") ) {
3890
3891
// FOREIGN CONST ITEM
3891
3892
let item = self . parse_item_foreign_const ( visibility, attrs) ;
3892
3893
return iovi_foreign_item ( item) ;
3893
- } else if items_allowed &&
3894
+ }
3895
+ if items_allowed &&
3894
3896
// FUNCTION ITEM (not sure about lookahead condition...)
3895
3897
self . is_keyword ( & ~"fn ") &&
3896
3898
!self . fn_expr_lookahead ( self . look_ahead ( 1 u) ) {
@@ -3899,21 +3901,24 @@ pub impl Parser {
3899
3901
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3900
3902
visibility,
3901
3903
maybe_append ( attrs, extra_attrs) ) ) ;
3902
- } else if items_allowed && self . eat_keyword ( & ~"pure") {
3904
+ }
3905
+ if items_allowed && self . eat_keyword ( & ~"pure") {
3903
3906
// PURE FUNCTION ITEM
3904
3907
// NB: We parse this as impure for bootstrapping purposes.
3905
3908
self . expect_keyword ( & ~"fn ") ;
3906
3909
let ( ident, item_, extra_attrs) = self . parse_item_fn ( impure_fn) ;
3907
3910
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3908
3911
visibility,
3909
3912
maybe_append ( attrs, extra_attrs) ) ) ;
3910
- } else if foreign_items_allowed &&
3913
+ }
3914
+ if foreign_items_allowed &&
3911
3915
( self . is_keyword ( & ~"fn ") || self . is_keyword ( & ~"pure") ||
3912
3916
self . is_keyword ( & ~"unsafe ") ) {
3913
3917
// FOREIGN FUNCTION ITEM (no items allowed)
3914
3918
let item = self . parse_item_foreign_fn ( attrs) ;
3915
3919
return iovi_foreign_item ( item) ;
3916
- } else if items_allowed && self . is_keyword ( & ~"unsafe ")
3920
+ }
3921
+ if items_allowed && self . is_keyword ( & ~"unsafe ")
3917
3922
&& self . look_ahead ( 1 u) != token:: LBRACE {
3918
3923
// UNSAFE FUNCTION ITEM (where items are allowed)
3919
3924
self . bump ( ) ;
@@ -3922,7 +3927,8 @@ pub impl Parser {
3922
3927
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3923
3928
visibility,
3924
3929
maybe_append ( attrs, extra_attrs) ) ) ;
3925
- } else if self . eat_keyword ( & ~"extern ") {
3930
+ }
3931
+ if self . eat_keyword ( & ~"extern ") {
3926
3932
if items_allowed && self.eat_keyword(&~" fn ") {
3927
3933
// EXTERN FUNCTION ITEM
3928
3934
let ( ident, item_, extra_attrs) =
@@ -3932,47 +3938,62 @@ pub impl Parser {
3932
3938
maybe_append ( attrs,
3933
3939
extra_attrs) ) ) ;
3934
3940
}
3935
- // EXTERN MODULE ITEM
3936
- return self . parse_item_foreign_mod ( lo, visibility, attrs,
3937
- items_allowed) ;
3938
- } else if items_allowed && self . eat_keyword ( & ~"mod ") {
3941
+ if !foreign_items_allowed {
3942
+ // EXTERN MODULE ITEM
3943
+ return self . parse_item_foreign_mod ( lo, visibility, attrs,
3944
+ items_allowed) ;
3945
+ }
3946
+ }
3947
+ if items_allowed && !foreign_items_allowed &&
3948
+ self . eat_keyword ( & ~"mod ") {
3939
3949
// MODULE ITEM
3940
3950
let ( ident, item_, extra_attrs) = self . parse_item_mod ( attrs) ;
3941
3951
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3942
3952
visibility,
3943
3953
maybe_append ( attrs, extra_attrs) ) ) ;
3944
- } else if items_allowed && self . eat_keyword ( & ~"type ") {
3954
+ }
3955
+ if items_allowed && !foreign_items_allowed &&
3956
+ self . eat_keyword ( & ~"type ") {
3945
3957
// TYPE ITEM
3946
3958
let ( ident, item_, extra_attrs) = self . parse_item_type ( ) ;
3947
3959
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3948
3960
visibility,
3949
3961
maybe_append ( attrs, extra_attrs) ) ) ;
3950
- } else if items_allowed && self . eat_keyword ( & ~"enum ") {
3962
+ }
3963
+ if items_allowed && !foreign_items_allowed &&
3964
+ self . eat_keyword ( & ~"enum ") {
3951
3965
// ENUM ITEM
3952
3966
let ( ident, item_, extra_attrs) = self . parse_item_enum ( ) ;
3953
3967
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3954
3968
visibility,
3955
3969
maybe_append ( attrs, extra_attrs) ) ) ;
3956
- } else if items_allowed && self . eat_keyword ( & ~"trait ") {
3970
+ }
3971
+ if items_allowed && !foreign_items_allowed &&
3972
+ self . eat_keyword ( & ~"trait ") {
3957
3973
// TRAIT ITEM
3958
3974
let ( ident, item_, extra_attrs) = self . parse_item_trait ( ) ;
3959
3975
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3960
3976
visibility,
3961
3977
maybe_append ( attrs, extra_attrs) ) ) ;
3962
- } else if items_allowed && self . eat_keyword ( & ~"impl ") {
3978
+ }
3979
+ if items_allowed && !foreign_items_allowed &&
3980
+ self . eat_keyword ( & ~"impl ") {
3963
3981
// IMPL ITEM
3964
3982
let ( ident, item_, extra_attrs) =
3965
3983
self . parse_item_impl ( visibility) ;
3966
3984
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3967
3985
visibility,
3968
3986
maybe_append ( attrs, extra_attrs) ) ) ;
3969
- } else if items_allowed && self . eat_keyword ( & ~"struct ") {
3987
+ }
3988
+ if items_allowed && !foreign_items_allowed &&
3989
+ self . eat_keyword ( & ~"struct ") {
3970
3990
// STRUCT ITEM
3971
3991
let ( ident, item_, extra_attrs) = self . parse_item_struct ( ) ;
3972
3992
return iovi_item ( self . mk_item ( lo, self . last_span . hi , ident, item_,
3973
3993
visibility,
3974
3994
maybe_append ( attrs, extra_attrs) ) ) ;
3975
- } else if self . eat_keyword ( & ~"use ") {
3995
+ }
3996
+ if !foreign_items_allowed && self . eat_keyword ( & ~"use ") {
3976
3997
// USE ITEM
3977
3998
let view_item = self . parse_use ( ) ;
3978
3999
self . expect ( & token:: SEMI ) ;
@@ -3982,7 +4003,8 @@ pub impl Parser {
3982
4003
vis : visibility,
3983
4004
span : mk_sp ( lo, self . last_span . hi )
3984
4005
} ) ;
3985
- } else if macros_allowed && !self . is_any_keyword ( & copy * self . token )
4006
+ }
4007
+ if macros_allowed && !self . is_any_keyword ( & copy * self . token )
3986
4008
&& self . look_ahead ( 1 ) == token:: NOT
3987
4009
&& ( is_plain_ident ( & self . look_ahead ( 2 ) )
3988
4010
|| self . look_ahead ( 2 ) == token:: LPAREN
@@ -4025,16 +4047,16 @@ pub impl Parser {
4025
4047
let item_ = item_mac ( m) ;
4026
4048
return iovi_item ( self . mk_item ( lo, self . last_span . hi , id, item_,
4027
4049
visibility, attrs) ) ;
4028
- } else {
4029
- // FAILURE TO PARSE ITEM
4030
- if visibility != inherited {
4031
- let mut s = ~"unmatched visibility `" ;
4032
- s += if visibility == public { ~" pub " } else { ~"priv" } ;
4033
- s += ~"`" ;
4034
- self . span_fatal ( * self . last_span , s ) ;
4035
- }
4036
- return iovi_none ;
4037
- } ;
4050
+ }
4051
+
4052
+ // FAILURE TO PARSE ITEM
4053
+ if visibility != inherited {
4054
+ let mut s = ~"unmatched visibility `" ;
4055
+ s += if visibility == public { ~" pub " } else { ~"priv" } ;
4056
+ s += ~"`" ;
4057
+ self . span_fatal ( * self . last_span , s ) ;
4058
+ }
4059
+ return iovi_none ;
4038
4060
}
4039
4061
4040
4062
fn parse_item ( & self , +attrs : ~[ attribute ] ) -> Option < @ast:: item > {
@@ -4201,17 +4223,17 @@ pub impl Parser {
4201
4223
4202
4224
let items_allowed = match mode {
4203
4225
VIEW_ITEMS_AND_ITEMS_ALLOWED | IMPORTS_AND_ITEMS_ALLOWED => true ,
4204
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED => false
4226
+ FOREIGN_ITEMS_ALLOWED => false
4205
4227
} ;
4206
4228
4207
4229
let restricted_to_imports = match mode {
4208
4230
IMPORTS_AND_ITEMS_ALLOWED => true ,
4209
4231
VIEW_ITEMS_AND_ITEMS_ALLOWED |
4210
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED => false
4232
+ FOREIGN_ITEMS_ALLOWED => false
4211
4233
} ;
4212
4234
4213
4235
let foreign_items_allowed = match mode {
4214
- VIEW_ITEMS_AND_FOREIGN_ITEMS_ALLOWED => true ,
4236
+ FOREIGN_ITEMS_ALLOWED => true ,
4215
4237
VIEW_ITEMS_AND_ITEMS_ALLOWED | IMPORTS_AND_ITEMS_ALLOWED => false
4216
4238
} ;
4217
4239
0 commit comments