Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
syntactic-decomposition.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors: RafaƂ Siejakowski <rs@rs-math.net>
7 *
8 * Copyright (C) 2025 Authors
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef INKSCAPE_CSS_SYNTACTIC_DECOMPOSITION_H
13#define INKSCAPE_CSS_SYNTACTIC_DECOMPOSITION_H
14
15#include <algorithm>
16#include <memory>
17#include <string>
18#include <variant>
19#include <vector>
20
21using CRSelector = struct _CRSelector;
22
23namespace Inkscape::CSS {
24
25class SyntacticDecomposition;
26
37{
38 std::string selectors;
39 std::string rules;
40};
41
54{
55 std::string at_statement;
56 std::unique_ptr<SyntacticDecomposition> block_content;
57};
58
62using OtherStatement = std::string;
63
66using SyntacticElement = std::variant<RuleStatement, BlockAtStatement, OtherStatement>;
67
70template <class F>
72 requires(RuleStatement const &rule, BlockAtStatement const &block, OtherStatement const &other, F f) {
73 f(rule);
74 f(block);
75 f(other);
76 };
77
82{
83public:
85 explicit SyntacticDecomposition(std::string const &css);
86
88 explicit SyntacticDecomposition(std::vector<SyntacticElement> elements)
89 : _elements{std::move(elements)}
90 {}
91
93 [[nodiscard]] bool empty() const { return _elements.empty(); }
94
96 void for_each(SyntacticElementHandler auto &&handler) const
97 {
98 std::for_each(_elements.begin(), _elements.end(),
99 [&handler, this](auto const &element) { std::visit(handler, element); });
100 }
101
102private:
103 std::vector<SyntacticElement> _elements;
104};
105
113std::string selector_to_validated_string(CRSelector const &croco_selector);
114
115} // namespace Inkscape::CSS
116
117#endif // INKSCAPE_CSS_SYNTACTIC_DECOMPOSITION_H
118/*
119 Local Variables:
120 mode:c++
121 c-file-style:"stroustrup"
122 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123 indent-tabs-mode:nil
124 fill-column:99
125 End:
126*/
127// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
A partial syntactic decomposition of a CSS stylesheet into syntactic elements.
void for_each(SyntacticElementHandler auto &&handler) const
Execute an operation for each syntactic element, in the order of their occurrence.
std::vector< SyntacticElement > _elements
SyntacticDecomposition(std::vector< SyntacticElement > elements)
Construct from a collection of syntactic elements.
bool empty() const
Returns true when there are no elements.
A SyntacticElementHandler is a callable which can accept all possible variant types of a syntactic el...
typedefG_BEGIN_DECLS struct _CRSelector CRSelector
Definition cr-selector.h:40
std::shared_ptr< Css const > css
std::string OtherStatement
Another CSS statement, currently not handled in a special way; for example @charset.
std::string selector_to_validated_string(CRSelector const &croco_selector)
Convert a CSS selector to a string, performing a fix-up if needed.
std::variant< RuleStatement, BlockAtStatement, OtherStatement > SyntacticElement
A syntactic element of a CSS stylesheet is either a rule set statement, a block -statement,...
STL namespace.
A decomposed block -statement, consisting of the statement and the contents of the associated block.
std::unique_ptr< SyntacticDecomposition > block_content
A decomposed CSS rule statement, consisting of a selector (which can be complex), and the associated ...
std::string selectors
Selectors for a rule set statement.
std::string rules
Semicolon-separated rules.
Abstracts a CSS2 selector as defined in the right part of the 'ruleset' production in the appendix D....
Definition cr-selector.h:54