slang::parsing::Trivia class

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 anchorLocation) const -> Trivia
If the trivia is raw source text, creates a new trivia attached from behind to the specified location (instead of implicitly offset from the parent token).
auto getExplicitLocation() const -> std::optional<SourceLocation>
Gets the source location of the trivia if one is explicitly known.
auto syntax() const -> syntax::SyntaxNode*
If this trivia is tracking a skipped syntax node or a directive, returns that node.
auto getRawText() const -> std::string_view
Get the raw text of the trivia, if any.
auto getSkippedTokens() const -> std::span<Token const>
If the trivia represents skipped tokens, returns the list of tokens that were skipped.

Function documentation

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

If the trivia is raw source text, creates a new trivia attached from behind to 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.

std::optional<SourceLocation> slang::parsing::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 or subsequent trivia.

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

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

Otherwise returns nullptr.

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

If the trivia represents skipped tokens, returns the list of tokens that were skipped.

Otherwise returns an empty span.