macro_rules! pseudo_element {
($(#[$meta:meta])* $vis:vis enum $name: ident { $first_variant: ident: $atoms: ident::$first:ident, $( $variant: ident: $variant_pat: pat$(,)?)* }) => { ... };
}Expand description
A macro for defining pseudo elements.
This makes it much easier to define a pseudo element. Parsing is also a little bit delicate, as the two Cursors must appear next to each other - no whitespace nor comments can be present betwixt the colon and ident.
ยงExample
use css_parse::*;
use csskit_derives::*;
use derive_atom_set::*;
use bumpalo::Bump;
#[derive(Debug, Default, AtomSet, Copy, Clone, PartialEq)]
pub enum MyAtomSet {
#[default]
_None,
Foo,
Bar,
Baz,
}
impl MyAtomSet {
const ATOMS: MyAtomSet = MyAtomSet::_None;
}
pseudo_element!(
/// Some docs on this type...
#[derive(Debug, ToCursors, ToSpan)]
pub enum MyPseudoElement {
Foo: MyAtomSet::Foo,
Bar: MyAtomSet::Bar,
Baz: MyAtomSet::Baz,
}
);
// Matches are case insensitive
assert_parse!(MyAtomSet::ATOMS, MyPseudoElement, "::FoO");
// The result will be one of the variants in the enum, matching the keyword.
assert_parse!(MyAtomSet::ATOMS, MyPseudoElement, "::bar");
// Words that do not match will fail to parse.
assert_parse_error!(MyAtomSet::ATOMS, MyPseudoElement, "::bing");