macro_rules! discrete_feature {
($(#[$meta:meta])* $vis:vis enum $feature: ident<$feature_name: path, $value: ty>) => { ... };
}
Expand description
This macro expands to define an enum which already implements Parse and DiscreteFeature, for a one-liner definition of a DiscreteFeature.
ยงExample
use css_parse::*;
use bumpalo::Bump;
use csskit_derives::{ToCursors, ToSpan};
use derive_atom_set::AtomSet;
// Your language atoms:
#[derive(Debug, Default, Copy, Clone, AtomSet, PartialEq)]
pub enum MyLangAtoms {
#[default]
_None,
TestFeature,
}
impl MyLangAtoms {
pub const ATOMS: MyLangAtoms = MyLangAtoms::_None;
}
// Define the Discrete Feature.
discrete_feature! {
/// A discrete media feature: `(test-feature: big)`, `(test-feature: small)`
#[derive(ToCursors, ToSpan, Debug)]
pub enum TestFeature<MyLangAtoms::TestFeature, T![Ident]>
}
// Test!
assert_parse!(MyLangAtoms::ATOMS, TestFeature, "(test-feature)", TestFeature::Bare(_open, _ident, _close));
assert_parse!(MyLangAtoms::ATOMS, TestFeature, "(test-feature:big)", TestFeature::WithValue(_open, _ident, _colon, _feature, _close));