Skip to content

Commit d364cac

Browse files
authored
Merge pull request #2469 from vinu-vanjari/TriviaPiece.isComment
Added TriviaPiece.isComment
2 parents 262d1fa + 88bd3ba commit d364cac

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TriviaPiecesFile.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,19 @@ fileprivate func generateIsHelpers(for pieceName: TokenSyntax) throws -> Extensi
310310
}
311311
"""
312312
)
313+
314+
DeclSyntax(
315+
"""
316+
/// Returns `true` if this piece is a comment.
317+
public var isComment: Bool {
318+
switch self {
319+
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
320+
return true
321+
default:
322+
return false
323+
}
324+
}
325+
"""
326+
)
313327
}
314328
}

Release Notes/511.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
- Description: Produce the lexical context for a given syntax node (if it has one), or the entire stack of lexical contexts enclosing a syntax node, for use in macro expansion.
4646
- Pull request: https://github.com/apple/swift-syntax/pull/1554
4747

48+
- `TriviaPiece.isComment`
49+
- Description: `TriviaPiece` now has a computed property `isComment` that returns `true` if the trivia piece is a comment.
50+
- Pull Request: https://github.com/apple/swift-syntax/pull/2469
51+
4852
## API Behavior Changes
4953

5054
## Deprecations

Sources/SwiftSyntax/generated/TriviaPieces.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ extension TriviaPiece {
475475
return false
476476
}
477477
}
478+
479+
/// Returns `true` if this piece is a comment.
480+
public var isComment: Bool {
481+
switch self {
482+
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
483+
return true
484+
default:
485+
return false
486+
}
487+
}
478488
}
479489

480490
extension RawTriviaPiece {
@@ -510,4 +520,14 @@ extension RawTriviaPiece {
510520
return false
511521
}
512522
}
523+
524+
/// Returns `true` if this piece is a comment.
525+
public var isComment: Bool {
526+
switch self {
527+
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
528+
return true
529+
default:
530+
return false
531+
}
532+
}
513533
}

0 commit comments

Comments
 (0)