@@ -295,6 +295,17 @@ public extension SyntaxProtocol {
295
295
return data. indexInParent
296
296
}
297
297
298
+ /// Whether or not this node has a parent.
299
+ var hasParent : Bool {
300
+ return parent != nil
301
+ }
302
+
303
+ /// Recursively walks through the tree to find the token semantically before
304
+ /// this node.
305
+ var previousToken : TokenSyntax ? {
306
+ return self . previousToken ( viewMode: . sourceAccurate)
307
+ }
308
+
298
309
/// Recursively walks through the tree to find the token semantically before
299
310
/// this node.
300
311
func previousToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
@@ -315,6 +326,12 @@ public extension SyntaxProtocol {
315
326
return parent. previousToken ( viewMode: viewMode)
316
327
}
317
328
329
+ /// Recursively walks through the tree to find the next token semantically
330
+ /// after this node.
331
+ var nextToken : TokenSyntax ? {
332
+ return self . nextToken ( viewMode: . sourceAccurate)
333
+ }
334
+
318
335
/// Recursively walks through the tree to find the next token semantically
319
336
/// after this node.
320
337
func nextToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
@@ -353,6 +370,11 @@ public extension SyntaxProtocol {
353
370
return nil
354
371
}
355
372
373
+ /// Returns the last token node that is part of this syntax node.
374
+ var lastToken : TokenSyntax ? {
375
+ return self . lastToken ( viewMode: . sourceAccurate)
376
+ }
377
+
356
378
/// Returns the last token node that is part of this syntax node.
357
379
func lastToken( viewMode: SyntaxTreeViewMode ) -> TokenSyntax ? {
358
380
guard viewMode. shouldTraverse ( node: raw) else { return nil }
@@ -450,6 +472,16 @@ public extension SyntaxProtocol {
450
472
}
451
473
}
452
474
475
+ /// The length this node's leading trivia takes up spelled out in source.
476
+ var leadingTriviaLength : SourceLength {
477
+ return raw. leadingTriviaLength
478
+ }
479
+
480
+ /// The length this node's trailing trivia takes up spelled out in source.
481
+ var trailingTriviaLength : SourceLength {
482
+ return raw. trailingTriviaLength
483
+ }
484
+
453
485
/// Returns a new syntax node with its leading trivia replaced
454
486
/// by the provided trivia.
455
487
func withLeadingTrivia( _ leadingTrivia: Trivia ) -> Self {
0 commit comments