From d68d4495395cabc10407e088b6781bf7ee5035e1 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Apr 2026 03:28:01 +0800 Subject: style: apply consistent code formatting and bracing style across the codebase --- src/parser/tree_builder.cc | 87 +++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) (limited to 'src/parser/tree_builder.cc') diff --git a/src/parser/tree_builder.cc b/src/parser/tree_builder.cc index 51a8a51..4f7f87e 100644 --- a/src/parser/tree_builder.cc +++ b/src/parser/tree_builder.cc @@ -24,67 +24,58 @@ namespace ricochet::parser { namespace { -struct TokenVisitor { - std::vector* stack; +struct TokenVisitor +{ + std::vector* stack; - void operator()(const TextToken& token) const { - stack->back().children.emplace_back( - DomNode{ - .tag_name = "", - .text_content = token.content, - .children = {} - } - ); - } + void operator()( const TextToken& token ) const + { + stack->back().children.emplace_back( + DomNode { .tag_name = "", .text_content = token.content, .children = {} } ); + } + + void operator()( const TagOpenToken& token ) const + { + DomNode new_node { .tag_name = token.name, .text_content = "", .children = {} }; - void operator()(const TagOpenToken& token) const { - DomNode new_node{ - .tag_name = token.name, - .text_content = "", - .children = {} - }; + if ( token.name == "meta" || token.name == "link" || token.name == "img" || token.name == "br" + || token.name == "hr" || token.name == "input" || token.name == "base" || token.name == "col" ) { - if (token.name == "meta" || token.name == "link" || token.name == "img" || - token.name == "br" || token.name == "hr" || token.name == "input" || - token.name == "base" || token.name == "col") { - - stack->back().children.push_back(std::move(new_node)); - } else { - stack->push_back(std::move(new_node)); - } + stack->back().children.push_back( std::move( new_node ) ); + } else { + stack->push_back( std::move( new_node ) ); } + } - void operator()(const TagCloseToken& /*token*/) const { - if (stack->size() > 1) { - DomNode completed_node = std::move(stack->back()); - stack->pop_back(); - stack->back().children.push_back(std::move(completed_node)); - } + void operator()( const TagCloseToken& /*token*/ ) const + { + if ( stack->size() > 1 ) { + DomNode completed_node = std::move( stack->back() ); + stack->pop_back(); + stack->back().children.push_back( std::move( completed_node ) ); } + } }; } // namespace -DomNode TreeBuilder::build(const std::vector& tokens) const // NOLINT(readability-convert-member-functions-to-static) +DomNode TreeBuilder::build( // NOLINT(readability-convert-member-functions-to-static) + const std::vector& tokens ) const { - std::vector stack; - stack.emplace_back(DomNode{ - .tag_name = "Document", - .text_content = "", - .children = {} - }); + std::vector stack; + stack.emplace_back( DomNode { .tag_name = "Document", .text_content = "", .children = {} } ); - TokenVisitor visitor{&stack}; - for (const auto& token : tokens) { - std::visit(visitor, token); - } + TokenVisitor visitor { &stack }; + for ( const auto& token : tokens ) { + std::visit( visitor, token ); + } - while (stack.size() > 1) { - DomNode completed_node = std::move(stack.back()); - stack.pop_back(); - stack.back().children.push_back(std::move(completed_node)); - } + while ( stack.size() > 1 ) { + DomNode completed_node = std::move( stack.back() ); + stack.pop_back(); + stack.back().children.push_back( std::move( completed_node ) ); + } - return std::move(stack.front()); + return std::move( stack.front() ); } } // namespace ricochet::parser \ No newline at end of file -- cgit v1.2.3