tag == parser_tag_type::css_qualified_rule ||
tag == parser_tag_type::css_simple_block) {
/* Pre-allocate content for known vector blocks */
- content = std::vector<consumed_block_ptr>(4);
+ std::vector<consumed_block_ptr> vec;
+ vec.reserve(4);
+ content = std::move(vec);
}
}
/* Construct a block from a single lexer token (for trivial blocks) */
auto attach_block(consumed_block_ptr &&block) -> bool {
if (content.index() == 0) {
/* Switch from monostate */
- content = std::vector<consumed_block_ptr>(1);
+ content = std::vector<consumed_block_ptr>();
}
else if (content.index() == 2) {
/* A single component, cannot attach a block ! */
return ret;
}
+
+ auto debug_str(void) -> std::string {
+ std::string ret = token_type_str();
+
+ ret += "; value: ";
+
+ std::visit([&](auto& arg) {
+ using T = std::decay_t<decltype(arg)>;
+
+ if constexpr (std::is_same_v<T, std::vector<consumed_block_ptr>>) {
+ /* Array of blocks */
+ ret += "nodes: [";
+ for (const auto &block : arg) {
+ ret += "{";
+ ret += block->debug_str();
+ ret += "}, ";
+ }
+
+ if (*(--ret.end()) == ' ') {
+ ret.pop_back();
+ ret.pop_back(); /* Last ',' */
+ }
+ ret += "]";
+ }
+ else if constexpr (std::is_same_v<T, std::monostate>) {
+ /* Empty block */
+ ret += "empty";
+ }
+ else {
+ /* Single element block */
+ ret += arg.debug_token_str();
+ }
+ },
+ content);
+
+ return ret;
+ }
};
class css_parser {
}
}
+ if (ret) {
+ msg_debug_css("attached node 'simple block' rule %s; length=%d",
+ block->token_type_str(), (int)block->size());
+ top->attach_block(std::move(block));
+ }
+
--rec_level;
return ret;
if (ret) {
if (top->tag == css_consumed_block::parser_tag_type::css_top_block) {
- msg_debug_css("attached block qualified rule %s; length=%d",
+ msg_debug_css("attached node qualified rule %s; length=%d",
block->token_type_str(), (int)block->size());
top->attach_block(std::move(block));
}
ret = function_consumer(fblock);
if (ret) {
- msg_debug_css("attached block function rule %s; length=%d",
+ msg_debug_css("attached node function rule %s; length=%d",
fblock->token_type_str(), (int)fblock->size());
block->attach_block(std::move(fblock));
}
}
if (ret) {
- msg_debug_css("attached block component rule %s; length=%d",
+ msg_debug_css("attached node component rule %s; length=%d",
block->token_type_str(), (int)block->size());
top->attach_block(std::move(block));
}
}
}
+ auto debug_str = consumed_blocks->debug_str();
+ msg_debug_css("consumed css: %*s", (int)debug_str.size(), debug_str.data());
+
tokeniser.reset(nullptr); /* No longer needed */
return ret;