5#include <portals/detail/pss_parser.hpp>
25using portals::detail::pssError;
27using portals::detail::PssPolicy;
45inline constexpr auto NO_COMPACT_DECLARATION = std::numeric_limits<std::uint16_t>::max();
60 std::array<std::uint16_t, PSS_SCALAR_PROPERTY_COUNT> result{};
61 result.fill(NO_COMPACT_DECLARATION);
79 return {
static_cast<std::uint32_t
>(location.
offset),
static_cast<std::uint32_t
>(location.
line),
80 static_cast<std::uint32_t
>(location.
column)};
86constexpr PssLocation expandPosition(PssPosition location) {
87 return {location.offset, location.line, location.column};
146 constexpr std::expected<void, PssError>
readOnly() {
173 return std::unexpected(
183 constexpr std::expected<void, PssError>
endRule() {
191 constexpr std::expected<void, PssError>
text(std::size_t bytes,
PssLocation location) {
193 return std::unexpected(
208template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
class PssCompactSink;
218template <std::size_t RuleCapacity, std::size_t ClassCapacity, std::size_t DeclarationCapacity,
219 std::size_t ByteCapacity>
223 "Compact stylesheet capacities exceed CT PSS budgets");
230 constexpr std::span<const detail::PssCompactRule>
rules() const noexcept {
231 return {rules_.data(), ruleCount_};
235 constexpr std::span<const detail::PssText>
classes() const noexcept {
236 return {classes_.data(), classCount_};
240 constexpr std::span<const detail::PssCompactDeclaration>
declarations() const noexcept {
241 return {declarations_.data(), declarationCount_};
248 if (range.size == 0) {
252 return {bytes_.data() + range.offset, range.size};
257 return text(sourceName_);
271 template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
friend class detail::PssCompactSink;
273 std::array<detail::PssCompactRule, RuleCapacity> rules_{};
274 std::array<detail::PssText, ClassCapacity> classes_{};
275 std::array<detail::PssCompactDeclaration, DeclarationCapacity> declarations_{};
276 std::array<char, ByteCapacity> bytes_{};
277 detail::PssText sourceName_;
279 std::size_t ruleCount_{};
280 std::size_t classCount_{};
281 std::size_t declarationCount_{};
282 std::size_t byteCount_{};
292template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
class PssCompactSink {
299 "Compact stylesheet object exceeds descriptor budget");
305 constexpr std::expected<void, PssError>
sourceName(std::string_view name) {
306 return copyText(name, {}, sheet_.sourceName_);
311 sheet_.originKind_ = kind;
318 if (sheet_.ruleCount_ == R) {
322 auto &
rule = current();
324 rule.selector = compactPosition(location);
325 rule.classBegin =
static_cast<std::uint32_t
>(sheet_.classCount_);
326 rule.declarationBegin =
static_cast<std::uint32_t
>(sheet_.declarationCount_);
368 return copyText(bytes, location, current().
id);
376 if (sheet_.classCount_ == C) {
380 auto admitted =
copyText(bytes, location, sheet_.classes_[sheet_.classCount_]);
386 ++sheet_.classCount_;
387 ++current().classCount;
393 constexpr std::expected<void, PssError>
readOnly() {
394 current().readOnly =
true;
402 current().state = value;
417 if (sheet_.declarationCount_ == D) {
418 return std::unexpected(
422 auto &
rule = current();
424 rule.effectiveDeclaration[
static_cast<std::size_t
>(property)] =
425 static_cast<std::uint16_t
>(sheet_.declarationCount_);
426 ++
rule.declarationCount;
427 sheet_.declarations_[sheet_.declarationCount_++] = {
static_cast<std::uint32_t
>(sheet_.ruleCount_), property,
428 compactPosition(location), value};
434 constexpr std::expected<void, PssError>
endRule() {
446 if (bytes.size() > B - sheet_.byteCount_) {
447 return std::unexpected(
451 destination = {
static_cast<std::uint32_t
>(sheet_.byteCount_),
static_cast<std::uint32_t
>(bytes.size())};
453 for (
const auto value : bytes) {
454 sheet_.bytes_[sheet_.byteCount_++] = value;
467 template <std::
size_t SourceR, std::
size_t SourceC, std::
size_t SourceD, std::
size_t SourceB>
469 if (source.ruleCount_ > R || source.classCount_ > C || source.declarationCount_ > D || source.byteCount_ > B) {
473 sheet_.ruleCount_ = source.ruleCount_;
474 sheet_.classCount_ = source.classCount_;
475 sheet_.declarationCount_ = source.declarationCount_;
476 sheet_.byteCount_ = source.byteCount_;
477 sheet_.sourceName_ = source.sourceName_;
478 sheet_.originKind_ = source.originKind_;
480 for (std::size_t index = 0; index < source.ruleCount_; ++index) {
481 sheet_.rules_[index] = source.rules_[index];
484 for (std::size_t index = 0; index < source.classCount_; ++index) {
485 sheet_.classes_[index] = source.classes_[index];
488 for (std::size_t index = 0; index < source.declarationCount_; ++index) {
489 sheet_.declarations_[index] = source.declarations_[index];
492 for (std::size_t index = 0; index < source.byteCount_; ++index) {
493 sheet_.bytes_[index] = source.bytes_[index];
501 return sheet_.rules_[sheet_.ruleCount_];
504 std::string_view source_;
Shared allocation-free grammar kernel; sink calls are synchronous and may throw.
Definition pss_parser.hpp:368
Immutable owning scalar stylesheet; its public type contains only numeric capacities.
Definition pss_compact.hpp:220
constexpr std::span< const detail::PssText > classes() const noexcept
Definition pss_compact.hpp:235
constexpr std::string_view sourceName() const noexcept
Definition pss_compact.hpp:256
constexpr CompactSheet()=default
Construct a valid empty owning description.
constexpr std::span< const detail::PssCompactDeclaration > declarations() const noexcept
Definition pss_compact.hpp:240
constexpr std::size_t ownedTextBytes() const noexcept
Definition pss_compact.hpp:266
constexpr std::span< const detail::PssCompactRule > rules() const noexcept
Definition pss_compact.hpp:230
constexpr std::string_view text(detail::PssText range) const noexcept
Definition pss_compact.hpp:247
constexpr PssOriginKind originKind() const noexcept
Definition pss_compact.hpp:261
Allocation-free storing sink writing one bounded owning descriptor.
Definition pss_compact.hpp:292
constexpr void originKind(PssOriginKind kind)
Definition pss_compact.hpp:310
constexpr std::expected< void, PssError > idName(std::string_view bytes, PssLocation location)
Definition pss_compact.hpp:367
constexpr std::expected< void, PssError > beginRule(PssLocation location)
Definition pss_compact.hpp:317
constexpr std::expected< void, PssError > readOnly()
Definition pss_compact.hpp:393
constexpr std::expected< void, PssError > classBytes(std::string_view bytes, PssLocation location)
Definition pss_compact.hpp:375
constexpr std::expected< void, PssError > type(PssSpan span, PssLocation location)
Definition pss_compact.hpp:335
constexpr std::expected< void, PssError > className(PssSpan span, PssLocation location)
Definition pss_compact.hpp:351
constexpr std::expected< void, PssError > id(PssSpan span, PssLocation location)
Definition pss_compact.hpp:343
constexpr std::expected< void, PssError > declaration(PssProperty property, PssValue value, PssLocation location)
Definition pss_compact.hpp:412
constexpr std::expected< void, PssError > typeName(std::string_view bytes, PssLocation location)
Definition pss_compact.hpp:359
constexpr std::expected< void, PssError > sourceName(std::string_view name)
Definition pss_compact.hpp:305
constexpr std::expected< void, PssError > copyText(std::string_view bytes, PssLocation location, PssText &destination)
Definition pss_compact.hpp:445
constexpr std::expected< void, PssError > copyFrom(const CompactSheet< SourceR, SourceC, SourceD, SourceB > &source)
Definition pss_compact.hpp:468
constexpr std::expected< void, PssError > endRule()
Definition pss_compact.hpp:434
constexpr PssCompactSink(std::string_view source, CompactSheet< R, C, D, B > &sheet)
Definition pss_compact.hpp:297
constexpr std::expected< void, PssError > state(StyleState value)
Definition pss_compact.hpp:401
Owning compile-time PSS v0 snapshots using the existing runtime cascade.
Definition pss_compact.hpp:8
constexpr std::size_t MAX_CT_PSS_DESCRIPTOR_BYTES
Maximum complete compact descriptor object size.
Definition pss_compact.hpp:22
consteval auto sheet(P values, R... rules)
Definition style_static.hpp:1380
consteval auto rule(S target, D... declarations)
Definition style_static.hpp:1366
constexpr std::size_t MAX_CT_PSS_SOURCE_NAME_BYTES
Maximum caller-supplied compile-time UTF-8 source identity bytes.
Definition pss_compact.hpp:20
constexpr std::size_t MAX_CT_PSS_BYTES
Maximum compile-time source bytes, independently of the larger runtime budget.
Definition pss_compact.hpp:10
constexpr std::size_t MAX_CT_PSS_TEXT_BYTES
Maximum shared owning selector and source-identity text bytes.
Definition pss_compact.hpp:18
constexpr std::size_t MAX_CT_PSS_CLASSES
Maximum compile-time class predicates across the whole sheet.
Definition pss_compact.hpp:14
constexpr std::size_t MAX_CT_PSS_DECLARATIONS
Maximum compile-time declaration occurrences, including overwritten duplicates.
Definition pss_compact.hpp:16
constexpr std::size_t MAX_CT_PSS_RULES
Maximum compile-time source-order rules.
Definition pss_compact.hpp:12
PssProperty
PSS v0 declaration identities in metadata and compact descriptions.
Definition pss_data.hpp:13
constexpr std::size_t PSS_SCALAR_PROPERTY_COUNT
Scalar-only prefix retained by compile-time PSS descriptors.
Definition pss_data.hpp:136
StyleState
Presentation states; ANY matches every state without changing behavior.
Definition style.hpp:26
@ ANY
Match all presentation variants.
Definition style.hpp:27
PssOriginKind
Coordinates describe either original PSS bytes or explicit typed ordinals.
Definition pss_data.hpp:147
@ PSS_BYTES
Actual offsets, LF lines, and byte columns in original PSS input.
Definition pss_data.hpp:148
@ RULE_LIMIT
Source-order rule count exceeds the selected budget.
Definition pss_data.hpp:156
@ DOCUMENT_LIMIT
Runtime owning payload exceeds its logical budget.
Definition pss_data.hpp:160
@ CLASS_LIMIT
Compact class predicates exceed their budget.
Definition pss_data.hpp:157
@ DECLARATION_LIMIT
Compact declaration occurrences exceed their budget.
Definition pss_data.hpp:158
@ INVALID_VALUE
Value does not have the property's exact scalar syntax.
Definition pss_data.hpp:172
@ TEXT_LIMIT
Compact owning text exceeds its shared arena.
Definition pss_data.hpp:159
Position in original PSS bytes, including an accepted leading BOM.
Definition pss_data.hpp:178
std::size_t offset
Zero-based byte offset.
Definition pss_data.hpp:179
std::size_t line
One-based line, advanced only by LF.
Definition pss_data.hpp:180
std::size_t column
One-based byte column.
Definition pss_data.hpp:181
Allocation-free declaration scalar; its owning occurrence property identifies the active field.
Definition pss_data.hpp:190
Borrowed byte range used only within a synchronous parser invocation.
Definition pss_parser.hpp:16
std::size_t offset
Start in the original source.
Definition pss_parser.hpp:17
std::size_t size
Number of bytes.
Definition pss_parser.hpp:18
Small validated scalar payload; avoids constructing six optional fields per parsed occurrence.
Definition pss_parser.hpp:22
Compact declaration occurrence with source coordinates and containment.
Definition pss_compact.hpp:68
std::uint32_t ruleIndex
Source-order containing rule.
Definition pss_compact.hpp:69
PssPosition location
Original property start.
Definition pss_compact.hpp:71
PssScalarValue value
Original owning scalar, including overwritten duplicate values.
Definition pss_compact.hpp:72
Compact owning source-order rule data, without per-rule text arenas.
Definition pss_compact.hpp:49
std::uint32_t classCount
Number of conjunction classes.
Definition pss_compact.hpp:53
std::uint32_t declarationCount
All occurrences, including duplicates.
Definition pss_compact.hpp:58
PssText type
Optional type identity in the shared arena.
Definition pss_compact.hpp:50
PssText id
Optional target identity in the shared arena.
Definition pss_compact.hpp:51
PssPosition selector
Original selector start.
Definition pss_compact.hpp:56
StyleState state
Presentation-state predicate.
Definition pss_compact.hpp:54
bool readOnly
Orthogonal read-only predicate.
Definition pss_compact.hpp:55
std::uint32_t classBegin
First class-reference index.
Definition pss_compact.hpp:52
std::uint32_t declarationBegin
First declaration occurrence index.
Definition pss_compact.hpp:57
std::array< std::uint16_t, PSS_SCALAR_PROPERTY_COUNT > effectiveDeclaration
Last winning occurrence for each property.
Definition pss_compact.hpp:59
Allocation-free counting sink with the same limits as the storing sink.
Definition pss_compact.hpp:99
constexpr std::expected< void, PssError > state(StyleState state)
Definition pss_compact.hpp:153
constexpr std::expected< void, PssError > className(PssSpan span, PssLocation location)
Definition pss_compact.hpp:135
constexpr std::expected< void, PssError > type(PssSpan span, PssLocation location)
Definition pss_compact.hpp:119
constexpr std::expected< void, PssError > id(PssSpan span, PssLocation location)
Definition pss_compact.hpp:127
PssCounts counts
Current admitted counts.
Definition pss_compact.hpp:100
constexpr std::expected< void, PssError > endRule()
Definition pss_compact.hpp:183
constexpr std::expected< void, PssError > declaration(PssProperty property, PssValue value, PssLocation location)
Definition pss_compact.hpp:164
constexpr std::expected< void, PssError > readOnly()
Definition pss_compact.hpp:146
constexpr std::expected< void, PssError > beginRule(PssLocation location)
Definition pss_compact.hpp:105
constexpr std::expected< void, PssError > text(std::size_t bytes, PssLocation location)
Definition pss_compact.hpp:191
Shared admission counts computed before exact-sized CT construction.
Definition pss_compact.hpp:91
std::size_t declarations
Total declaration occurrences.
Definition pss_compact.hpp:94
std::size_t rules
Rules in source order.
Definition pss_compact.hpp:92
std::size_t bytes
All copied selector and source-name text.
Definition pss_compact.hpp:95
std::size_t classes
Total conjunction classes.
Definition pss_compact.hpp:93
Compact original-source coordinates within the named CT byte limit.
Definition pss_compact.hpp:38
std::uint32_t line
One-based LF line.
Definition pss_compact.hpp:40
std::uint32_t column
One-based byte column.
Definition pss_compact.hpp:41
std::uint32_t offset
Zero-based byte offset.
Definition pss_compact.hpp:39
Compact owning-arena reference; all admitted CT text fits uint32_t.
Definition pss_compact.hpp:32
std::uint32_t size
Byte count.
Definition pss_compact.hpp:34
std::uint32_t offset
Start within the descriptor's shared arena.
Definition pss_compact.hpp:33