Macro ranged_feature

Source
macro_rules! ranged_feature {
    ($(#[$meta:meta])* $vis:vis enum $feature: ident<$feature_name: ty, $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.

ยงExample

use css_parse::*;
use bumpalo::Bump;

// Defined the "FeatureName"
keyword_set!(pub enum TestKeyword { Thing: "thing", MaxThing: "max-thing", MinThing: "min-thing" });
impl RangedFeatureKeyword for TestKeyword {
  fn is_legacy(&self) -> bool {
    matches!(self, Self::MaxThing(_) | Self::MinThing(_))
  }
}

// Define the Ranged Feature.
ranged_feature! {
  /// A ranged media feature: (thing: 1), or (1 <= thing < 10)
  pub enum TestFeature<TestKeyword, T![Number]>
}

// Test!
assert_parse!(TestFeature, "(thing:2)");
assert_parse!(TestFeature, "(max-thing:2)");
assert_parse!(TestFeature, "(min-thing:2)");
assert_parse!(TestFeature, "(4<=thing>8)");
assert_parse!(TestFeature, "(thing>=2)");

assert_parse_error!(TestFeature, "(max-thing>2)");
assert_parse_error!(TestFeature, "(4<=max-thing<=8)");