TriviaView class
#include <slang/parsing/Token.h>
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
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.