I am trying to parse multiple CSS selectors with Boost Spirit X3. If I have the following CSS rule that apply to multiple IDs (selectors) for example:
#ID1, #ID2, #ID3 { color:#000000; }
Where #ID1, #ID2, #ID3
are the selectors, color:#000000;
is the declaration-block, and the same declaration-block applies to all 3 selectors. And assuming that the structs for rule
, selector
, and declaration_block
are the following:
struct Rule {
Selector selector;
DeclationBlock declarationBlock;
}
struct Selector {
std::string target;
}
struct DeclarationBlock {
std::vector<Declaration> declarations;
}
And I already have Spirit rules for selectors and declaration-blocks:
auto selector = x3::rule<struct SelectorId, css::Selector>{"selector"};
auto declaration_block = x3::rule<struct DeclarationBlockId, css::DeclarationBlock>{"declaration-block"};
Parsing rules for single selectors would be straight forward:
auto rule = x3::rule<struct RuleId, css::Rule>{"rule"} = selector >> declaration_block;
auto rules = x3::rule<struct RulesId, std::vector<css::Rule>>{"rules"} = *rule;
But, my question is, how do I parse the same declaration block for multiple selectors? I am trying to use semantic actions to basically copy the declaration-block for all selectors, but I don't know if this would be the best approach.