Skip to main content

css_ast/functions/
tree_counting_functions.rs

1use super::prelude::*;
2
3/// <https://drafts.csswg.org/css-values-5/#tree-counting>
4///
5/// ```text,ignore
6/// <sibling-count()> = sibling-count()
7/// <sibling-index()> = sibling-index()
8/// ```
9///
10/// Both notations represent an `<integer>` that can only be resolved against a live tree, so they
11/// are valid wherever an `<integer>` is, and as a `<calc-value>` inside any math function.
12#[node]
13#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
15#[cfg_attr(feature = "visitable", derive(Visitable), visit)]
16#[derive(csskit_derives::NodeWithMetadata)]
17#[metadata(declaration_kinds = Computed)]
18pub enum TreeCountingFunction {
19	SiblingCount(#[atom(CssAtomSet::SiblingCount)] Function, #[semantic_eq(skip)] RightParen),
20	SiblingIndex(#[atom(CssAtomSet::SiblingIndex)] Function, #[semantic_eq(skip)] RightParen),
21}
22
23#[cfg(test)]
24mod tests {
25	use super::*;
26	use css_parse::assert_parse;
27
28	#[test]
29	fn test_tree_counting_function() {
30		assert_parse!(CssAtomSet::ATOMS, TreeCountingFunction, "sibling-count()");
31		assert_parse!(CssAtomSet::ATOMS, TreeCountingFunction, "sibling-index()");
32	}
33}