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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
use super::*;
use crate::parse_fraction;
impl TailwindAspect {
pub fn parse(kind: &[&str], arbitrary: &str) -> Result<Self> {
let out = match kind {
[] => {
let (a, b) = parse_fraction(arbitrary)?.1;
Self::Arbitrary(a, b)
}
["auto"] => Self::Auto,
["square"] => Self::Arbitrary(1, 1),
["video"] => Self::Arbitrary(16, 9),
["inherit"] => todo!(),
["w", _n] => todo!(),
["h", _n] => todo!(),
_ => return syntax_error!("unknown aspect-ratio elements"),
};
Ok(out)
}
}
impl TailwindColumns {
pub fn parse(input: &[&str]) -> Result<Self> {
let out = match input {
["auto"] => Self::Auto,
["3xs"] => Self::Rem(16),
["2xs"] => Self::Rem(18),
["xs"] => Self::Rem(20),
["sm"] => Self::Rem(24),
["md"] => Self::Rem(28),
["lg"] => Self::Rem(32),
["xl"] => Self::Rem(36),
["2xl"] => Self::Rem(42),
["3xl"] => Self::Rem(48),
["4xl"] => Self::Rem(56),
["5xl"] => Self::Rem(64),
["6xl"] => Self::Rem(72),
["7xl"] => Self::Rem(80),
[name] => Self::Columns(parse_integer(name)?.1),
_ => return syntax_error!("Unknown column instructions: {}", input.join("-")),
};
Ok(out)
}
}
impl TailwindLayoutBreak {
pub fn parse_before(input: &[&str]) -> Result<Self> {
let kind = LayoutBreakKind::Before;
let info = input.join("-");
match input {
["auto"] | ["avoid"] | ["all"] | ["avoid", "page"] | ["page"] | ["left"] | ["right"] | ["column"] => {
Ok(Self { kind, info })
}
_ => syntax_error!("Unknown break-before instructions: {}", info),
}
}
pub fn parse_after(input: &[&str]) -> Result<Self> {
let kind = LayoutBreakKind::After;
let info = input.join("-");
match input {
["auto"] | ["avoid"] | ["all"] | ["avoid", "page"] | ["page"] | ["left"] | ["right"] | ["column"] => {
Ok(Self { kind, info })
}
_ => syntax_error!("Unknown break-after instructions: {}", info),
}
}
pub fn parse_inside(input: &[&str]) -> Result<Self> {
let kind = LayoutBreakKind::Inside;
let info = input.join("-");
match input {
["auto"] | ["avoid"] | ["avoid", "page"] | ["avoid", "column"] => Ok(Self { kind, info }),
_ => syntax_error!("Unknown break-inside instructions: {}", info),
}
}
}
impl TailwindObjectPosition {
pub fn parse_arbitrary(arbitrary: &str) -> Result<Self> {
todo!("{}", arbitrary)
}
}
impl OverflowKind {
pub fn parse(input: &[&str]) -> Result<Self> {
match input {
["auto"] => Ok(Self::Auto),
["hidden"] => Ok(Self::Hidden),
["clip"] => Ok(Self::Clip),
["visible"] => Ok(Self::Visible),
["scroll"] => Ok(Self::Scroll),
_ => syntax_error!("Unknown overflow instructions: {}", input.join("-")),
}
}
}
impl TailwindOverflow {
#[inline]
pub fn parse_x(kind: &[&str]) -> Result<Self> {
let kind = OverflowKind::parse(kind)?;
Ok(Self { kind, axis: Some(true) })
}
#[inline]
pub fn parse_y(kind: &[&str]) -> Result<Self> {
let kind = OverflowKind::parse(kind)?;
Ok(Self { kind, axis: Some(false) })
}
#[inline]
pub fn parse_xy(kind: &[&str]) -> Result<Self> {
let kind = OverflowKind::parse(kind)?;
Ok(Self { kind, axis: None })
}
}
impl OverscrollKind {
pub fn parse(input: &[&str]) -> Result<Self> {
match input {
["auto"] => Ok(Self::Auto),
["contain"] => Ok(Self::Contain),
["none"] => Ok(Self::None),
_ => syntax_error!("Unknown overflow instructions: {}", input.join("-")),
}
}
}
impl TailwindOverscroll {
#[inline]
pub fn parse_x(kind: &[&str]) -> Result<Self> {
let kind = OverscrollKind::parse(kind)?;
Ok(Self { kind, axis: Some(true) })
}
#[inline]
pub fn parse_y(kind: &[&str]) -> Result<Self> {
let kind = OverscrollKind::parse(kind)?;
Ok(Self { kind, axis: Some(false) })
}
#[inline]
pub fn parse_xy(kind: &[&str]) -> Result<Self> {
let kind = OverscrollKind::parse(kind)?;
Ok(Self { kind, axis: None })
}
}
impl TailWindZIndex {
pub fn parse(kind: &[&str], neg: bool) -> Box<dyn TailwindInstance> {
match kind.len() {
1 => {}
r => panic!("break-inside expected 1 element but found {} elements", r),
}
let instance = match kind {
["auto"] => Self::Auto,
[r] => Self::parse_number(r, neg).expect("not number"),
_ => {
panic!("Unknown aspect-ratio pattern")
}
};
Box::new(instance)
}
#[inline]
fn parse_number(input: &str, neg: bool) -> Result<Self> {
let n = parse_integer(input)?.1;
match neg {
true => Ok(Self::Negative(n)),
false => Ok(Self::Positive(n)),
}
}
}
impl TailwindClear {
#[inline]
pub fn parse(kind: &[&str]) -> Result<Self> {
let out = match kind {
["left"] => Self::Left,
["right"] => Self::Right,
["both"] => Self::Both,
["none"] => Self::None,
_ => return syntax_error!("unknown clear elements"),
};
Ok(out)
}
}