slang::parsing::TriviaView class

A lightweight view over a sequence of Trivia objects associated with a Token.

Most of the time the view simply wraps an externally stored contiguous buffer of Trivia (i.e. the buffer that lives in a Token's heap-allocated info block). However, certain very common single-trivia cases (a short whitespace run or a newline) are encoded directly into free bits of the parent Token, in which case the view materializes a synthesized Trivia on the fly. That synthesized Trivia is stored inside the view itself so iteration can return references into the view's own storage.

This type models std::ranges::view so it can be used with the standard ranges library (e.g. piped through std::views::filter). Iterators returned by begin()/end() reference the view object itself; do not move or destroy the view while iterators into it are still in use.

Public static functions

static TriviaView makeInline(const Trivia* src, size_t n) noexcept
Constructs a view containing one or two inline Trivia.

Constructors, destructors, conversion operators

TriviaView() defaulted noexcept
Constructs an empty view.
template<std::ranges::contiguous_range R>
TriviaView(R&& range) noexcept
Constructs a view over an externally stored contiguous range of Trivia.
TriviaView(std::span<const Trivia> span) noexcept
Constructs a view from a span of Trivia.
TriviaView(const TriviaView& other) noexcept
Copy/move constructors fix up the inline storage pointer for views that hold a synthesized Trivia.

Public functions

size_t size() const noexcept
Number of Trivia elements in the view.
bool empty() const noexcept
True if the view is empty.
const Trivia* data() const noexcept
Pointer to the underlying contiguous buffer.

Function documentation

static TriviaView slang::parsing::TriviaView::makeInline(const Trivia* src, size_t n) noexcept

Constructs a view containing one or two inline Trivia.

The trivia are held by value inside the view; iterators reference them directly.

const Trivia* slang::parsing::TriviaView::data() const noexcept

Pointer to the underlying contiguous buffer.

For inline views this points at the view's internal storage; for external views it points at the originally referenced buffer. Only valid while the view is alive.