Skip to content

Added TriviaPiece.isComment #2469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,19 @@ fileprivate func generateIsHelpers(for pieceName: TokenSyntax) throws -> Extensi
}
"""
)

DeclSyntax(
"""
/// Returns `true` if this piece is a comment.
public var isComment: Bool {
switch self {
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
return true
default:
return false
}
}
"""
)
}
}
4 changes: 4 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
- 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.
- Pull request: https://github.com/apple/swift-syntax/pull/1554

- `TriviaPiece.isComment`
- Description: `TriviaPiece` now has a computed property `isComment` that returns `true` if the trivia piece is a comment.
- Pull Request: https://github.com/apple/swift-syntax/pull/2469

## API Behavior Changes

## Deprecations
Expand Down
20 changes: 20 additions & 0 deletions Sources/SwiftSyntax/generated/TriviaPieces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ extension TriviaPiece {
return false
}
}

/// Returns `true` if this piece is a comment.
public var isComment: Bool {
switch self {
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
return true
default:
return false
}
}
}

extension RawTriviaPiece {
Expand Down Expand Up @@ -510,4 +520,14 @@ extension RawTriviaPiece {
return false
}
}

/// Returns `true` if this piece is a comment.
public var isComment: Bool {
switch self {
case .lineComment, .blockComment, .docLineComment, .docBlockComment:
return true
default:
return false
}
}
}