@@ -147,12 +147,11 @@ where
147147
148148pub struct Lexer < T : Iterator < Item = char > > {
149149 chars : T ,
150- window : CharWindow < 3 > ,
151-
152150 at_begin_of_line : bool ,
153151 nesting : usize , // Amount of parenthesis
154152 indentations : Indentations ,
155153 pending : Vec < Spanned > ,
154+ window : CharWindow < 3 > ,
156155 location : Location ,
157156}
158157
@@ -167,8 +166,7 @@ pub type LexResult = Result<Spanned, LexicalError>;
167166// types into \n always.
168167pub struct NewlineHandler < T : Iterator < Item = char > > {
169168 source : T ,
170- chr0 : Option < char > ,
171- chr1 : Option < char > ,
169+ window : CharWindow < 2 > ,
172170}
173171
174172impl < T > NewlineHandler < T >
@@ -178,18 +176,16 @@ where
178176 pub fn new ( source : T ) -> Self {
179177 let mut nlh = NewlineHandler {
180178 source,
181- chr0 : None ,
182- chr1 : None ,
179+ window : CharWindow :: default ( ) ,
183180 } ;
184181 nlh. shift ( ) ;
185182 nlh. shift ( ) ;
186183 nlh
187184 }
188185
189186 fn shift ( & mut self ) -> Option < char > {
190- let result = self . chr0 ;
191- self . chr0 = self . chr1 ;
192- self . chr1 = self . source . next ( ) ;
187+ let result = self . window [ 0 ] ;
188+ self . window . slide ( self . source . next ( ) ) ;
193189 result
194190 }
195191}
@@ -203,14 +199,14 @@ where
203199 fn next ( & mut self ) -> Option < Self :: Item > {
204200 // Collapse \r\n into \n
205201 loop {
206- match ( self . chr0 , self . chr1 ) {
202+ match ( self . window [ 0 ] , self . window [ 1 ] ) {
207203 ( Some ( '\r' ) , Some ( '\n' ) ) => {
208204 // Windows EOL into \n
209205 self . shift ( ) ;
210206 }
211207 ( Some ( '\r' ) , _) => {
212208 // MAC EOL into \n
213- self . chr0 = Some ( '\n' ) ;
209+ self . window [ 0 ] = Some ( '\n' ) ;
214210 }
215211 _ => break ,
216212 }
0 commit comments