@@ -156,22 +156,6 @@ enum PrevTokenKind {
156
156
Other ,
157
157
}
158
158
159
- // Simple circular buffer used for keeping few next tokens.
160
- #[ derive( Default ) ]
161
- struct LookaheadBuffer {
162
- buffer : [ TokenAndSpan ; LOOKAHEAD_BUFFER_CAPACITY ] ,
163
- start : usize ,
164
- end : usize ,
165
- }
166
-
167
- const LOOKAHEAD_BUFFER_CAPACITY : usize = 8 ;
168
-
169
- impl LookaheadBuffer {
170
- fn len ( & self ) -> usize {
171
- ( LOOKAHEAD_BUFFER_CAPACITY + self . end - self . start ) % LOOKAHEAD_BUFFER_CAPACITY
172
- }
173
- }
174
-
175
159
/* ident is handled by common.rs */
176
160
177
161
pub struct Parser < ' a > {
@@ -184,7 +168,6 @@ pub struct Parser<'a> {
184
168
pub prev_span : Span ,
185
169
/// the previous token kind
186
170
prev_token_kind : PrevTokenKind ,
187
- lookahead_buffer : LookaheadBuffer ,
188
171
pub restrictions : Restrictions ,
189
172
pub quote_depth : usize , // not (yet) related to the quasiquoter
190
173
parsing_token_tree : bool ,
@@ -281,7 +264,6 @@ impl<'a> Parser<'a> {
281
264
span : syntax_pos:: DUMMY_SP ,
282
265
prev_span : syntax_pos:: DUMMY_SP ,
283
266
prev_token_kind : PrevTokenKind :: Other ,
284
- lookahead_buffer : Default :: default ( ) ,
285
267
restrictions : Restrictions :: empty ( ) ,
286
268
quote_depth : 0 ,
287
269
parsing_token_tree : false ,
@@ -875,14 +857,7 @@ impl<'a> Parser<'a> {
875
857
_ => PrevTokenKind :: Other ,
876
858
} ;
877
859
878
- let next = if self . lookahead_buffer . start == self . lookahead_buffer . end {
879
- self . next_tok ( )
880
- } else {
881
- // Avoid token copies with `replace`.
882
- let old_start = self . lookahead_buffer . start ;
883
- self . lookahead_buffer . start = ( old_start + 1 ) % LOOKAHEAD_BUFFER_CAPACITY ;
884
- mem:: replace ( & mut self . lookahead_buffer . buffer [ old_start] , Default :: default ( ) )
885
- } ;
860
+ let next = self . next_tok ( ) ;
886
861
self . span = next. sp ;
887
862
self . token = next. tok ;
888
863
self . expected_tokens . clear ( ) ;
@@ -917,18 +892,20 @@ impl<'a> Parser<'a> {
917
892
F : FnOnce ( & token:: Token ) -> R ,
918
893
{
919
894
if dist == 0 {
920
- f ( & self . token )
921
- } else if dist < LOOKAHEAD_BUFFER_CAPACITY {
922
- while self . lookahead_buffer . len ( ) < dist {
923
- self . lookahead_buffer . buffer [ self . lookahead_buffer . end ] = self . next_tok ( ) ;
924
- self . lookahead_buffer . end =
925
- ( self . lookahead_buffer . end + 1 ) % LOOKAHEAD_BUFFER_CAPACITY ;
926
- }
927
- let index = ( self . lookahead_buffer . start + dist - 1 ) % LOOKAHEAD_BUFFER_CAPACITY ;
928
- f ( & self . lookahead_buffer . buffer [ index] . tok )
929
- } else {
930
- self . bug ( "lookahead distance is too large" ) ;
895
+ return f ( & self . token ) ;
896
+ }
897
+ let mut tok = token:: Eof ;
898
+ if let Some ( & ( ref tts, mut i) ) = self . tts . last ( ) {
899
+ i += dist - 1 ;
900
+ if i < tts. len ( ) {
901
+ tok = match tts. get_tt ( i) {
902
+ TokenTree :: Token ( _, tok) => tok,
903
+ TokenTree :: Delimited ( _, delimited) => token:: OpenDelim ( delimited. delim ) ,
904
+ TokenTree :: Sequence ( ..) => token:: Dollar ,
905
+ } ;
906
+ }
931
907
}
908
+ f ( & tok)
932
909
}
933
910
pub fn fatal ( & self , m : & str ) -> DiagnosticBuilder < ' a > {
934
911
self . sess . span_diagnostic . struct_span_fatal ( self . span , m)
0 commit comments