macro_rules! pseudo_class {
($(#[$meta:meta])* $vis:vis enum $name: ident { $( $variant: ident: $variant_str: tt$(,)?)+ }) => { ... };
}
Expand description
A macro for defining pseudo classes.
This makes it much easier to define a pseudo class, which would otherwise need to define a keyword_set or similar, in order to build up the two Cursors required to parse. 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 bumpalo::Bump;
pseudo_class!(
/// Some docs on this type...
pub enum MyPseudoClass {
Foo: "foo",
Bar: "bar",
Baz: "baz"
}
);
// The result will be one of the variants in the enum, matching the keyword.
assert_parse!(MyPseudoClass, ":foo");
// Matches are case insensitive
assert_parse!(MyPseudoClass, ":BaR");
// Words that do not match will fail to parse.
assert_parse_error!(MyPseudoClass, ":bing");
// The `:` is also required
assert_parse_error!(MyPseudoClass, "baz");
// Any tokens between the `:` and ident result in a parse error:
assert_parse_error!(MyPseudoClass, ": foo");