Skip to main content

css_parse/syntax/
unknown_rule_block.rs

1use super::prelude::*;
2use crate::ComponentValues;
3
4/// Wrapper type for using ComponentValues as a rule type parameter in unknown rules.
5/// This implements RuleVariants to allow ComponentValues to be used as the block type
6/// for unknown qualified rules, where the rule structure is not recognized.
7#[node]
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent))]
10pub struct UnknownRuleBlock<'a, D = ComponentValues<'a>, M = ()> {
11	pub values: ComponentValues<'a>,
12	#[cfg_attr(feature = "serde", serde(skip))]
13	_phantom: std::marker::PhantomData<(D, M)>,
14}
15
16impl<'a, D, M> Parse<'a> for UnknownRuleBlock<'a, D, M> {
17	fn parse<Iter>(p: &mut Parser<'a, Iter>) -> Result<Self>
18	where
19		Iter: Iterator<Item = Cursor> + Clone,
20	{
21		ComponentValues::parse(p).map(|values| Self { values, _phantom: std::marker::PhantomData })
22	}
23}
24
25impl<'a, D, M> Peek<'a> for UnknownRuleBlock<'a, D, M> {
26	const PEEK_KINDSET: KindSet = ComponentValues::PEEK_KINDSET;
27}
28
29impl<'a, D, M> ToCursors for UnknownRuleBlock<'a, D, M> {
30	fn to_cursors(&self, s: &mut impl CursorSink) {
31		self.values.to_cursors(s)
32	}
33}
34
35impl<'a, D, M> ToSpan for UnknownRuleBlock<'a, D, M> {
36	fn to_span(&self) -> Span {
37		self.values.to_span()
38	}
39}
40
41impl<'a, D, M> SemanticEq for UnknownRuleBlock<'a, D, M> {
42	fn semantic_eq(&self, other: &Self) -> bool {
43		self.values.semantic_eq(&other.values)
44	}
45}
46
47impl<'a, D, M: NodeMetadata> NodeWithMetadata<M> for UnknownRuleBlock<'a, D, M> {
48	fn metadata(&self) -> M {
49		self.values.metadata()
50	}
51}
52
53impl<'a, D, M> crate::RuleVariants<'a> for UnknownRuleBlock<'a, D, M>
54where
55	D: DeclarationValue<'a, M>,
56	M: NodeMetadata,
57{
58	type DeclarationValue = D;
59	type Metadata = M;
60
61	fn is_unknown(&self) -> bool {
62		// ComponentValues is a generic fallback container, not a specific rule type.
63		// It should be treated as unknown so it doesn't override actual declarations.
64		true
65	}
66}