slang::Trivia class

Contents

The Trivia class holds on to a piece of source text that should otherwise not turn into a token; for example, a preprocessor directive, a line continuation character, or a comment.

Public functions

auto withLocation(BumpAllocator& alloc, SourceLocation location) const -> Trivia
auto getExplicitLocation() const -> optional<SourceLocation>
auto syntax() const -> SyntaxNode*
auto getRawText() const -> string_view
Get the raw text of the trivia, if any.
auto getSkippedTokens() const -> span<Token const >

Function documentation

Trivia slang::Trivia::withLocation(BumpAllocator& alloc, SourceLocation location) const

If the trivia is raw source text, creates a new trivia with the specified location (instead of implicitly offset from the parent token). If this trivia is for a directive or skipped tokens, returns a copy without modification.

optional<SourceLocation> slang::Trivia::getExplicitLocation() const

Gets the source location of the trivia if one is explicitly known. If not, nullopt is returned to signify that the location is implicitly relative to the parent token.

SyntaxNode* slang::Trivia::syntax() const

If this trivia is tracking a skipped syntax node or a directive, returns that node. Otherwise returns nullptr.

span<Token const > slang::Trivia::getSkippedTokens() const

If the trivia represents skipped tokens, returns the list of tokens that were skipped. Otherwise returns an empty span.