/* * Copyright (c) 2020-2021, the SerenityOS developers. * Copyright (c) 2021-2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #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 const& block() const { return m_value.get>(); } bool is_function() const { return m_value.has>(); } Function const& 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(); } String to_string() const; String 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, component_value.to_string()); } };