/* * Copyright (c) 2020-2021, the SerenityOS developers. * Copyright (c) 2021-2023, Sam Atkins * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::CSS::Parser { // https://www.w3.org/TR/css-syntax-3/#component-value class ComponentValue { public: ComponentValue(Token); explicit ComponentValue(NonnullRefPtr); explicit ComponentValue(NonnullRefPtr); ~ComponentValue(); bool is_block() const { return m_value.has>(); } Block& block() const { return m_value.get>(); } bool is_function() const { return m_value.has>(); } Function& function() const { return m_value.get>(); } bool is_token() const { return m_value.has(); } bool is(Token::Type type) const { return is_token() && token().is(type); } Token const& token() const { return m_value.get(); } operator Token() const { return m_value.get(); } ErrorOr to_string() const; ErrorOr to_debug_string() const; private: Variant, NonnullRefPtr> m_value; }; } template<> struct AK::Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::Parser::ComponentValue const& component_value) { return Formatter::format(builder, TRY(component_value.to_string())); } };