Skip to content

Commit a22f832

Browse files
committed
Added TriviaPiece.isComment (via generator)
1 parent a26915d commit a22f832

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
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
}

Sources/SwiftParserDiagnostics/SyntaxExtensions.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,6 @@ public extension TriviaPiece {
181181
default: return false
182182
}
183183
}
184-
185-
var isComment: Bool {
186-
switch self {
187-
case .blockComment, .docBlockComment, .docLineComment, .lineComment:
188-
return true
189-
default:
190-
return false
191-
}
192-
}
193184
}
194185

195186
extension TokenSyntax {

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)