@@ -285,9 +285,8 @@ impl Marker {
285285 }
286286 _ => unreachable ! ( ) ,
287287 }
288- let finish_pos = p. events . len ( ) as u32 ;
289288 p. push_event ( Event :: Finish ) ;
290- CompletedMarker :: new ( self . pos , finish_pos , kind)
289+ CompletedMarker :: new ( self . pos , kind)
291290 }
292291
293292 /// Abandons the syntax tree node. All its children
@@ -305,14 +304,13 @@ impl Marker {
305304}
306305
307306pub ( crate ) struct CompletedMarker {
308- start_pos : u32 ,
309- finish_pos : u32 ,
307+ pos : u32 ,
310308 kind : SyntaxKind ,
311309}
312310
313311impl CompletedMarker {
314- fn new ( start_pos : u32 , finish_pos : u32 , kind : SyntaxKind ) -> Self {
315- CompletedMarker { start_pos , finish_pos , kind }
312+ fn new ( pos : u32 , kind : SyntaxKind ) -> Self {
313+ CompletedMarker { pos , kind }
316314 }
317315
318316 /// This method allows to create a new node which starts
@@ -330,29 +328,22 @@ impl CompletedMarker {
330328 /// distance to `NEWSTART` into forward_parent(=2 in this case);
331329 pub ( crate ) fn precede ( self , p : & mut Parser ) -> Marker {
332330 let new_pos = p. start ( ) ;
333- let idx = self . start_pos as usize ;
331+ let idx = self . pos as usize ;
334332 match & mut p. events [ idx] {
335333 Event :: Start { forward_parent, .. } => {
336- * forward_parent = Some ( new_pos. pos - self . start_pos ) ;
334+ * forward_parent = Some ( new_pos. pos - self . pos ) ;
337335 }
338336 _ => unreachable ! ( ) ,
339337 }
340338 new_pos
341339 }
342340
343- /// Undo this completion and turns into a `Marker`
344- pub ( crate ) fn undo_completion ( self , p : & mut Parser ) -> Marker {
345- let start_idx = self . start_pos as usize ;
346- let finish_idx = self . finish_pos as usize ;
347- match & mut p. events [ start_idx] {
348- Event :: Start { kind, forward_parent : None } => * kind = TOMBSTONE ,
349- _ => unreachable ! ( ) ,
350- }
351- match & mut p. events [ finish_idx] {
352- slot @ Event :: Finish => * slot = Event :: tombstone ( ) ,
353- _ => unreachable ! ( ) ,
354- }
355- Marker :: new ( self . start_pos )
341+ /// Extends this completed marker *to the left* up to `m`.
342+ pub ( crate ) fn extend_to ( self , p : & mut Parser , mut m : Marker ) {
343+ assert ! ( m. pos <= self . pos) ;
344+ m. bomb . defuse ( ) ;
345+
346+ p. events . swap ( self . pos as usize , m. pos as usize ) ;
356347 }
357348
358349 pub ( crate ) fn kind ( & self ) -> SyntaxKind {
0 commit comments