@@ -25,18 +25,18 @@ public protocol IncrementalParseReusedNodeDelegate {
25
25
/// - range: The source region of the currently parsed source.
26
26
/// - previousNode: The node from the previous tree that is associated with
27
27
/// the skipped source region.
28
- func parserReusedNode( range: ByteSourceRange , previousNode: SyntaxNode )
28
+ func parserReusedNode( range: ByteSourceRange , previousNode: Syntax )
29
29
}
30
30
31
31
/// An implementation of `IncrementalParseReusedNodeDelegate` that just collects
32
32
/// the range and re-used node into an array.
33
33
public final class IncrementalParseReusedNodeCollector :
34
34
IncrementalParseReusedNodeDelegate {
35
- public var rangeAndNodes : [ ( ByteSourceRange , SyntaxNode ) ] = [ ]
35
+ public var rangeAndNodes : [ ( ByteSourceRange , Syntax ) ] = [ ]
36
36
37
37
public init ( ) { }
38
38
39
- public func parserReusedNode( range: ByteSourceRange , previousNode: SyntaxNode ) {
39
+ public func parserReusedNode( range: ByteSourceRange , previousNode: Syntax ) {
40
40
rangeAndNodes. append ( ( range, previousNode) )
41
41
}
42
42
}
@@ -226,7 +226,7 @@ public struct IncrementalParseLookup {
226
226
227
227
public init ( transition: IncrementalParseTransition ) {
228
228
self . transition = transition
229
- self . cursor = . init( root: transition. previousTree. data. absoluteRaw )
229
+ self . cursor = . init( root: transition. previousTree. data)
230
230
}
231
231
232
232
fileprivate var edits : ConcurrentEdits {
@@ -246,11 +246,11 @@ public struct IncrementalParseLookup {
246
246
/// - Parameters:
247
247
/// - offset: The byte offset of the source string that is currently parsed.
248
248
/// - kind: The `CSyntaxKind` that the parser expects at this position.
249
- /// - Returns: A `SyntaxNode ` node from the previous parse invocation,
249
+ /// - Returns: A `Syntax ` node from the previous parse invocation,
250
250
/// representing the contents of this region, if it is still valid
251
251
/// to re-use. `nil` otherwise.
252
252
@_spi ( RawSyntax)
253
- public mutating func lookUp( _ newOffset: Int , kind: SyntaxKind ) -> SyntaxNode ? {
253
+ public mutating func lookUp( _ newOffset: Int , kind: SyntaxKind ) -> Syntax ? {
254
254
guard let prevOffset = translateToPreEditOffset ( newOffset) else {
255
255
return nil
256
256
}
@@ -266,7 +266,7 @@ public struct IncrementalParseLookup {
266
266
267
267
mutating fileprivate func cursorLookup(
268
268
prevPosition: AbsolutePosition , kind: SyntaxKind
269
- ) -> SyntaxNode ? {
269
+ ) -> Syntax ? {
270
270
guard !cursor. finished else { return nil }
271
271
272
272
while true {
@@ -348,60 +348,52 @@ public struct IncrementalParseLookup {
348
348
/// Functions as an iterator that walks the tree looking for nodes with a
349
349
/// certain position.
350
350
fileprivate struct SyntaxCursor {
351
- var parents : [ AbsoluteRawSyntax ]
352
- var node : AbsoluteRawSyntax
351
+ var node : SyntaxData
353
352
var finished : Bool
354
353
let viewMode = SyntaxTreeViewMode . sourceAccurate
355
354
356
- init ( root: AbsoluteRawSyntax ) {
355
+ init ( root: SyntaxData ) {
357
356
self . node = root
358
- self . parents = [ ]
359
357
self . finished = false
360
358
}
361
359
362
- var asSyntaxNode : SyntaxNode {
363
- return SyntaxNode ( node: node , parents : ArraySlice ( parents ) )
360
+ var asSyntaxNode : Syntax {
361
+ return Syntax ( node)
364
362
}
365
363
366
364
/// Returns the next sibling node or the parent's sibling node if this is
367
365
/// the last child. The cursor state is unmodified.
368
- /// - Returns: False if it run out of nodes to walk to.
369
- var nextSibling : AbsoluteRawSyntax ? {
370
- var parents = ArraySlice ( self . parents)
366
+ /// - Returns: `nil` if it run out of nodes to walk to.
367
+ var nextSibling : SyntaxData ? {
371
368
var node = self . node
372
- while !parents . isEmpty {
373
- if let sibling = node. nextSibling ( parent: parents . last! , viewMode: viewMode) {
374
- return sibling
369
+ while let parent = node . parent ? . data {
370
+ if let sibling = node. absoluteRaw . nextSibling ( parent: parent . absoluteRaw , viewMode: viewMode) {
371
+ return SyntaxData ( sibling, parent : Syntax ( parent ) )
375
372
}
376
- node = parents . removeLast ( )
373
+ node = parent
377
374
}
378
-
379
375
return nil
380
376
}
381
377
382
378
/// Moves to the first child of the current node.
383
379
/// - Returns: False if the node has no children.
384
380
mutating func advanceToFirstChild( ) -> Bool {
385
- guard let child = node. firstChild ( viewMode: viewMode) else { return false }
386
- parents. append ( node)
387
- node = child
381
+ guard let child = node. absoluteRaw. firstChild ( viewMode: viewMode) else { return false }
382
+ node = SyntaxData ( child, parent: Syntax ( node) )
388
383
return true
389
384
}
390
385
391
386
/// Moves to the next sibling node or the parent's sibling node if this is
392
387
/// the last child.
393
388
/// - Returns: False if it run out of nodes to walk to.
394
389
mutating func advanceToNextSibling( ) -> Bool {
395
- while !parents. isEmpty {
396
- if let sibling = node. nextSibling ( parent: parents. last!, viewMode: viewMode) {
397
- node = sibling
398
- return true
399
- }
400
- node = parents. removeLast ( )
390
+ guard let next = nextSibling else {
391
+ finished = true
392
+ return false
401
393
}
402
394
403
- finished = true
404
- return false
395
+ self . node = next
396
+ return true
405
397
}
406
398
407
399
/// Moves to the next node in the tree with the provided `position`.
0 commit comments