@@ -50,10 +50,11 @@ fn expr_use_rec<'src>() -> impl Parser<
50
50
extra:: Err < Rich < ' src , char > > ,
51
51
> {
52
52
recursive ( |expr_use_rec| {
53
- let ident = || token ( text:: ascii:: ident ( ) ) ;
54
- let item = ident ( )
53
+ let item = expr_use_tok ( )
55
54
. then (
56
- lexeme ( "as" ) . ignore_then ( ident ( ) ) . or_not ( ) ,
55
+ lexeme ( "as" )
56
+ . ignore_then ( expr_use_tok ( ) )
57
+ . or_not ( ) ,
57
58
)
58
59
. then (
59
60
lexeme ( "::" )
@@ -81,6 +82,17 @@ fn expr_use_rec<'src>() -> impl Parser<
81
82
} )
82
83
}
83
84
85
+ fn expr_use_tok < ' src > ( ) -> impl Parser <
86
+ ' src ,
87
+ & ' src str ,
88
+ & ' src str ,
89
+ extra:: Err < Rich < ' src , char > > ,
90
+ > + Clone {
91
+ keyword_except ( & [ "crate" , "super" , "self" , "Self" ] )
92
+ . not ( )
93
+ . ignore_then ( token ( text:: ascii:: ident ( ) ) )
94
+ }
95
+
84
96
fn expr_other < ' src > ( ) -> impl Parser <
85
97
' src ,
86
98
& ' src str ,
@@ -123,7 +135,9 @@ fn lexeme<'src>(
123
135
token ( just ( seq) )
124
136
}
125
137
126
- fn keyword < ' src > ( ) -> impl Parser <
138
+ fn keyword_except < ' src > (
139
+ except : & [ & str ] ,
140
+ ) -> impl Parser <
127
141
' src ,
128
142
& ' src str ,
129
143
& ' src str ,
@@ -142,6 +156,12 @@ fn keyword<'src>() -> impl Parser<
142
156
"macro" , "override" , "priv" , "typeof" ,
143
157
"unsized" , "virtual" , "yield" , "try" , "gen" ,
144
158
]
145
- . map ( lexeme) ,
159
+ . iter ( )
160
+ . filter ( |x| !except. contains ( x) )
161
+ . map ( |& x| {
162
+ lexeme ( x)
163
+ . then_ignore ( text:: ascii:: ident ( ) . not ( ) )
164
+ } )
165
+ . collect :: < Vec < _ > > ( ) ,
146
166
)
147
167
}
0 commit comments