macro_rules! ranged_feature {
(@parse_call $p:ident, $feature_name:path) => { ... };
(@parse_call $p:ident, $feature_name:path, $min_name:path, $max_name:path) => { ... };
($(#[$meta:meta])* $vis:vis enum $feature: ident{$feature_name: path $(| $min_name: path | $max_name: path)?, $value: ty}) => { ... };
}Expand description
This macro expands to define an enum which already implements Parse and RangedFeature, for a one-liner definition of a RangedFeature.
§Examples
§No Legacy syntax
use css_parse::*;
use bumpalo::Bump;
use csskit_derives::{ToCursors, ToSpan};
use derive_atom_set::AtomSet;
#[derive(Debug, Default, AtomSet, Copy, Clone, PartialEq)]
pub enum MyAtomSet {
#[default]
_None,
Thing,
MaxThing,
MinThing,
}
impl MyAtomSet {
const ATOMS: MyAtomSet = MyAtomSet::_None;
}
// Define the Ranged Feature.
ranged_feature! {
/// A ranged media feature: (thing: 1), or (1 <= thing < 10)
#[derive(ToCursors, ToSpan, Debug)]
pub enum TestFeature{MyAtomSet::Thing, T![Number]}
}
// Test!
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(thing:2)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(4<=thing>8)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(thing>=2)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(max-thing>2)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(4<=max-thing<=8)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(max-thing:2)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(min-thing:2)");§With legacy syntax
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,
Thing,
MaxThing,
MinThing,
}
impl MyAtomSet {
const ATOMS: MyAtomSet = MyAtomSet::_None;
}
// Define the Ranged Feature.
ranged_feature! {
/// A ranged media feature: (thing: 1), or (1 <= thing < 10)
#[derive(Debug, ToCursors, ToSpan)]
pub enum TestFeature{MyAtomSet::Thing | MyAtomSet::MinThing | MyAtomSet::MaxThing, T![Number]}
}
// Test!
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(thing:2)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(4<=thing>8)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(thing>=2)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(max-thing:2)");
assert_parse!(MyAtomSet::ATOMS, TestFeature, "(min-thing:2)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(max-thing>2)");
assert_parse_error!(MyAtomSet::ATOMS, TestFeature, "(4<=max-thing<=8)");