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

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).
std::optional<SourceLocation> getExplicitLocation() const
Gets the source location of the trivia if one is explicitly known.
syntax::SyntaxNode* syntax() const
If this trivia is tracking a skipped syntax node or a directive, returns that node.
std::string_view getRawText() const
Get the raw text of the trivia, if any.
std::span<Token const> getSkippedTokens() 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.