css_ast/types/
position_area.rs

1use super::prelude::*;
2
3// https://drafts.csswg.org/css-anchor-position-1/#typedef-position-area
4// <position-area> = [
5//   [ left | center | right | span-left | span-right
6//   | x-start | x-end | span-x-start | span-x-end
7//   | x-self-start | x-self-end | span-x-self-start | span-x-self-end
8//   | span-all ]
9//   ||
10//   [ top | center | bottom | span-top | span-bottom
11//   | y-start | y-end | span-y-start | span-y-end
12//   | y-self-start | y-self-end | span-y-self-start | span-y-self-end
13//   | span-all ]
14// |
15//   [ block-start | center | block-end | span-block-start | span-block-end | span-all ]
16//   ||
17//   [ inline-start | center | inline-end | span-inline-start | span-inline-end
18//   | span-all ]
19// |
20//   [ self-block-start | center | self-block-end | span-self-block-start
21//   | span-self-block-end | span-all ]
22//   ||
23//   [ self-inline-start | center | self-inline-end | span-self-inline-start
24//   | span-self-inline-end | span-all ]
25// |
26//   [ start | center | end | span-start | span-end | span-all ]{1,2}
27// |
28//   [ self-start | center | self-end | span-self-start | span-self-end | span-all ]{1,2}
29// ]
30#[derive(ToCursors, ToSpan, SemanticEq, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
31#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
32#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
33pub enum PositionArea {
34	Physical(Option<PositionAreaPhsyicalHorizontal>, Option<PositionAreaPhsyicalVertical>),
35	Logical(Option<PositionAreaBlock>, Option<PositionAreaInline>),
36	SelfLogical(Option<PositionAreaSelfBlock>, Option<PositionAreaSelfInline>),
37	Position(PositionAreaPosition, Option<PositionAreaPosition>),
38	SelfPosition(PositionAreaSelfPosition, Option<PositionAreaSelfPosition>),
39}
40
41impl<'a> Peek<'a> for PositionArea {
42	fn peek<I>(p: &Parser<'a, I>, c: Cursor) -> bool
43	where
44		I: Iterator<Item = Cursor> + Clone,
45	{
46		PositionAreaPhsyicalVertical::peek(p, c)
47			|| PositionAreaPhsyicalHorizontal::peek(p, c)
48			|| PositionAreaBlock::peek(p, c)
49			|| PositionAreaInline::peek(p, c)
50			|| PositionAreaSelfBlock::peek(p, c)
51			|| PositionAreaSelfInline::peek(p, c)
52			|| PositionAreaPosition::peek(p, c)
53			|| PositionAreaSelfPosition::peek(p, c)
54	}
55}
56
57impl<'a> Parse<'a> for PositionArea {
58	fn parse<I>(p: &mut Parser<'a, I>) -> ParserResult<Self>
59	where
60		I: Iterator<Item = Cursor> + Clone,
61	{
62		if let Some(first) = p.parse_if_peek::<PositionAreaPosition>()? {
63			Ok(Self::Position(first, p.parse_if_peek::<PositionAreaPosition>()?))
64		} else if let Some(first) = p.parse_if_peek::<PositionAreaSelfPosition>()? {
65			Ok(Self::SelfPosition(first, p.parse_if_peek::<PositionAreaSelfPosition>()?))
66		} else if let Some(block) = p.parse_if_peek::<PositionAreaBlock>()? {
67			Ok(Self::Logical(Some(block), p.parse_if_peek::<PositionAreaInline>()?))
68		} else if let Some(inline) = p.parse_if_peek::<PositionAreaInline>()? {
69			Ok(Self::Logical(p.parse_if_peek::<PositionAreaBlock>()?, Some(inline)))
70		} else if let Some(block) = p.parse_if_peek::<PositionAreaSelfBlock>()? {
71			Ok(Self::SelfLogical(Some(block), p.parse_if_peek::<PositionAreaSelfInline>()?))
72		} else if let Some(inline) = p.parse_if_peek::<PositionAreaSelfInline>()? {
73			Ok(Self::SelfLogical(p.parse_if_peek::<PositionAreaSelfBlock>()?, Some(inline)))
74		} else if let Some(horizontal) = p.parse_if_peek::<PositionAreaPhsyicalHorizontal>()? {
75			Ok(Self::Physical(Some(horizontal), p.parse_if_peek::<PositionAreaPhsyicalVertical>()?))
76		} else if let Some(vertical) = p.parse_if_peek::<PositionAreaPhsyicalVertical>()? {
77			Ok(Self::Physical(p.parse_if_peek::<PositionAreaPhsyicalHorizontal>()?, Some(vertical)))
78		} else {
79			Err(Diagnostic::new(p.next(), Diagnostic::unexpected))?
80		}
81	}
82}
83
84#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
86pub enum PositionAreaPhsyicalHorizontal {
87	#[atom(CssAtomSet::Left)]
88	Left(T![Ident]),
89	#[atom(CssAtomSet::Center)]
90	Center(T![Ident]),
91	#[atom(CssAtomSet::Right)]
92	Right(T![Ident]),
93	#[atom(CssAtomSet::SpanLeft)]
94	SpanLeft(T![Ident]),
95	#[atom(CssAtomSet::SpanRight)]
96	SpanRight(T![Ident]),
97	#[atom(CssAtomSet::XStart)]
98	XStart(T![Ident]),
99	#[atom(CssAtomSet::XEnd)]
100	XEnd(T![Ident]),
101	#[atom(CssAtomSet::SpanXStart)]
102	SpanXStart(T![Ident]),
103	#[atom(CssAtomSet::SpanXEnd)]
104	SpanXEnd(T![Ident]),
105	#[atom(CssAtomSet::XSelfStart)]
106	XSelfStart(T![Ident]),
107	#[atom(CssAtomSet::XSelfEnd)]
108	XSelfEnd(T![Ident]),
109	#[atom(CssAtomSet::SpanXSelfStart)]
110	SpanXSelfStart(T![Ident]),
111	#[atom(CssAtomSet::SpanXSelfEnd)]
112	SpanXSelfEnd(T![Ident]),
113	#[atom(CssAtomSet::SpanAll)]
114	SpanAll(T![Ident]),
115}
116
117#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
118#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
119pub enum PositionAreaPhsyicalVertical {
120	#[atom(CssAtomSet::Top)]
121	Top(T![Ident]),
122	#[atom(CssAtomSet::Center)]
123	Center(T![Ident]),
124	#[atom(CssAtomSet::Bottom)]
125	Bottom(T![Ident]),
126	#[atom(CssAtomSet::SpanTop)]
127	SpanTop(T![Ident]),
128	#[atom(CssAtomSet::SpanBottom)]
129	SpanBottom(T![Ident]),
130	#[atom(CssAtomSet::YStart)]
131	YStart(T![Ident]),
132	#[atom(CssAtomSet::YEnd)]
133	YEnd(T![Ident]),
134	#[atom(CssAtomSet::SpanYStart)]
135	SpanYStart(T![Ident]),
136	#[atom(CssAtomSet::SpanYEnd)]
137	SpanYEnd(T![Ident]),
138	#[atom(CssAtomSet::YSelfStart)]
139	YSelfStart(T![Ident]),
140	#[atom(CssAtomSet::YSelfEnd)]
141	YSelfEnd(T![Ident]),
142	#[atom(CssAtomSet::SpanYSelfStart)]
143	SpanYSelfStart(T![Ident]),
144	#[atom(CssAtomSet::SpanYSelfEnd)]
145	SpanYSelfEnd(T![Ident]),
146	#[atom(CssAtomSet::SpanAll)]
147	SpanAll(T![Ident]),
148}
149
150#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
151#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
152pub enum PositionAreaBlock {
153	#[atom(CssAtomSet::BlockStart)]
154	BlockStart(T![Ident]),
155	#[atom(CssAtomSet::Center)]
156	Center(T![Ident]),
157	#[atom(CssAtomSet::BlockEnd)]
158	BlockEnd(T![Ident]),
159	#[atom(CssAtomSet::SpanBlockStart)]
160	SpanBlockStart(T![Ident]),
161	#[atom(CssAtomSet::SpanBlockEnd)]
162	SpanBlockEnd(T![Ident]),
163	#[atom(CssAtomSet::SpanAll)]
164	SpanAll(T![Ident]),
165}
166
167#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
168#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
169pub enum PositionAreaInline {
170	#[atom(CssAtomSet::InlineStart)]
171	InlineStart(T![Ident]),
172	#[atom(CssAtomSet::Center)]
173	Center(T![Ident]),
174	#[atom(CssAtomSet::InlineEnd)]
175	InlineEnd(T![Ident]),
176	#[atom(CssAtomSet::SpanInlineStart)]
177	SpanInlineStart(T![Ident]),
178	#[atom(CssAtomSet::SpanInlineEnd)]
179	SpanInlineEnd(T![Ident]),
180	#[atom(CssAtomSet::SpanAll)]
181	SpanAll(T![Ident]),
182}
183
184#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
185#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
186pub enum PositionAreaSelfBlock {
187	#[atom(CssAtomSet::SelfBlockStart)]
188	SelfBlockStart(T![Ident]),
189	#[atom(CssAtomSet::Center)]
190	Center(T![Ident]),
191	#[atom(CssAtomSet::SelfBlockEnd)]
192	SelfBlockEnd(T![Ident]),
193	#[atom(CssAtomSet::SpanSelfBlockStart)]
194	SpanSelfBlockStart(T![Ident]),
195	#[atom(CssAtomSet::SpanSelfBlockEnd)]
196	SpanSelfBlockEnd(T![Ident]),
197	#[atom(CssAtomSet::SpanAll)]
198	SpanAll(T![Ident]),
199}
200
201#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
202#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
203pub enum PositionAreaSelfInline {
204	#[atom(CssAtomSet::SelfInlineStart)]
205	SelfInlineStart(T![Ident]),
206	#[atom(CssAtomSet::Center)]
207	Center(T![Ident]),
208	#[atom(CssAtomSet::SelfInlineEnd)]
209	SelfInlineEnd(T![Ident]),
210	#[atom(CssAtomSet::SpanSelfInlineStart)]
211	SpanSelfInlineStart(T![Ident]),
212	#[atom(CssAtomSet::SpanSelfInlineEnd)]
213	SpanSelfInlineEnd(T![Ident]),
214	#[atom(CssAtomSet::SpanAll)]
215	SpanAll(T![Ident]),
216}
217
218#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
219#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
220pub enum PositionAreaPosition {
221	#[atom(CssAtomSet::Start)]
222	Start(T![Ident]),
223	#[atom(CssAtomSet::Center)]
224	Center(T![Ident]),
225	#[atom(CssAtomSet::End)]
226	End(T![Ident]),
227	#[atom(CssAtomSet::SpanStart)]
228	SpanStart(T![Ident]),
229	#[atom(CssAtomSet::SpanEnd)]
230	SpanEnd(T![Ident]),
231	#[atom(CssAtomSet::SpanAll)]
232	SpanAll(T![Ident]),
233}
234
235#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
236#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
237pub enum PositionAreaSelfPosition {
238	#[atom(CssAtomSet::SelfStart)]
239	SelfStart(T![Ident]),
240	#[atom(CssAtomSet::Center)]
241	Center(T![Ident]),
242	#[atom(CssAtomSet::SelfEnd)]
243	SelfEnd(T![Ident]),
244	#[atom(CssAtomSet::SpanSelfStart)]
245	SpanSelfStart(T![Ident]),
246	#[atom(CssAtomSet::SpanSelfEnd)]
247	SpanSelfEnd(T![Ident]),
248	#[atom(CssAtomSet::SpanAll)]
249	SpanAll(T![Ident]),
250}