css_parse/syntax/
unknown_rule_block.rs1use crate::{
2 ComponentValues, Cursor, CursorSink, DeclarationValue, NodeMetadata, NodeWithMetadata, Parse, Parser, Peek, Result,
3 SemanticEq, Span, ToCursors, ToSpan,
4};
5
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent))]
11pub struct UnknownRuleBlock<'a, D = ComponentValues<'a>, M = ()> {
12 pub values: ComponentValues<'a>,
13 #[cfg_attr(feature = "serde", serde(skip))]
14 _phantom: std::marker::PhantomData<(D, M)>,
15}
16
17impl<'a, D, M> Parse<'a> for UnknownRuleBlock<'a, D, M> {
18 fn parse<Iter>(p: &mut Parser<'a, Iter>) -> Result<Self>
19 where
20 Iter: Iterator<Item = Cursor> + Clone,
21 {
22 ComponentValues::parse(p).map(|values| Self { values, _phantom: std::marker::PhantomData })
23 }
24}
25
26impl<'a, D, M> Peek<'a> for UnknownRuleBlock<'a, D, M> {
27 fn peek<Iter>(p: &Parser<'a, Iter>, c: Cursor) -> bool
28 where
29 Iter: Iterator<Item = Cursor> + Clone,
30 {
31 ComponentValues::peek(p, c)
32 }
33}
34
35impl<'a, D, M> ToCursors for UnknownRuleBlock<'a, D, M> {
36 fn to_cursors(&self, s: &mut impl CursorSink) {
37 self.values.to_cursors(s)
38 }
39}
40
41impl<'a, D, M> ToSpan for UnknownRuleBlock<'a, D, M> {
42 fn to_span(&self) -> Span {
43 self.values.to_span()
44 }
45}
46
47impl<'a, D, M> SemanticEq for UnknownRuleBlock<'a, D, M> {
48 fn semantic_eq(&self, other: &Self) -> bool {
49 self.values.semantic_eq(&other.values)
50 }
51}
52
53impl<'a, D, M: NodeMetadata> NodeWithMetadata<M> for UnknownRuleBlock<'a, D, M> {
54 fn metadata(&self) -> M {
55 self.values.metadata()
56 }
57}
58
59impl<'a, D, M> crate::RuleVariants<'a> for UnknownRuleBlock<'a, D, M>
60where
61 D: DeclarationValue<'a, M>,
62 M: NodeMetadata,
63{
64 type DeclarationValue = D;
65 type Metadata = M;
66
67 fn is_unknown(&self) -> bool {
68 true
71 }
72}