forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros.rs
More file actions
88 lines (81 loc) · 2.1 KB
/
macros.rs
File metadata and controls
88 lines (81 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
macro_rules! enum_property {
($name: ident, $( $x: ident ),+) => {
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum $name {
$(
$x,
)+
}
impl Parse for $name {
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ()>> {
let ident = input.expect_ident()?;
match &ident[..] {
$(
s if s.eq_ignore_ascii_case(stringify!($x)) => Ok($name::$x),
)+
_ => return Err(input.new_error(BasicParseErrorKind::QualifiedRuleInvalid))
}
}
}
impl ToCss for $name {
fn to_css<W>(&self, dest: &mut Printer<W>) -> std::fmt::Result where W: std::fmt::Write {
use $name::*;
match self {
$(
$x => dest.write_str(&stringify!($x).to_lowercase()),
)+
}
}
}
impl $name {
pub fn from_str(s: &str) -> Option<Self> {
match s {
$(
s if s.eq_ignore_ascii_case(stringify!($x)) => Some($name::$x),
)+
_ => None
}
}
}
};
($name: ident, $( ($str: expr, $id: ident) ),+) => {
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum $name {
$(
$id,
)+
}
impl Parse for $name {
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ()>> {
let ident = input.expect_ident()?;
match &ident[..] {
$(
s if s.eq_ignore_ascii_case($str) => Ok($name::$id),
)+
_ => return Err(input.new_error(BasicParseErrorKind::QualifiedRuleInvalid))
}
}
}
impl ToCss for $name {
fn to_css<W>(&self, dest: &mut Printer<W>) -> std::fmt::Result where W: std::fmt::Write {
use $name::*;
match self {
$(
$id => dest.write_str($str),
)+
}
}
}
impl $name {
pub fn from_str(s: &str) -> Option<Self> {
match s {
$(
s if s.eq_ignore_ascii_case($str) => Some($name::$id),
)+
_ => None
}
}
}
};
}
pub(crate) use enum_property;