css_parse/syntax/
no_block_allowed.rs1use super::prelude::*;
2
3#[node]
13#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
15pub struct NoBlockAllowed<D = (), M = ()> {
16 semicolon: Option<crate::token_macros::Semicolon>,
17 _phantom: std::marker::PhantomData<(D, M)>,
18}
19
20impl<'a, D, M> Parse<'a> for NoBlockAllowed<D, M> {
21 fn parse<Iter>(p: &mut Parser<'a, Iter>) -> Result<Self>
22 where
23 Iter: Iterator<Item = crate::Cursor> + Clone,
24 {
25 if p.at_end() {
26 Ok(Self { semicolon: None, _phantom: std::marker::PhantomData })
27 } else if let Some(semicolon) = p.parse_if_peek::<T![;]>()? {
28 Ok(Self { semicolon: Some(semicolon), _phantom: std::marker::PhantomData })
29 } else {
30 Err(Diagnostic::new(p.next(), Diagnostic::unexpected))?
31 }
32 }
33}
34
35impl<'a, D, M> Peek<'a> for NoBlockAllowed<D, M> {
36 const PEEK_KINDSET: KindSet = KindSet::NONE;
37}
38
39impl<D, M> ToCursors for NoBlockAllowed<D, M> {
40 fn to_cursors(&self, s: &mut impl CursorSink) {
41 if let Some(semicolon) = self.semicolon {
42 s.append(semicolon.into());
43 }
44 }
45}
46
47impl<D, M> ToSpan for NoBlockAllowed<D, M> {
48 fn to_span(&self) -> Span {
49 self.semicolon.to_span()
50 }
51}
52
53impl<D, M> SemanticEq for NoBlockAllowed<D, M> {
54 fn semantic_eq(&self, other: &Self, source_text: &str) -> bool {
55 self.semicolon.semantic_eq(&other.semicolon, source_text)
56 }
57}
58
59impl<D, M: crate::NodeMetadata> crate::NodeWithMetadata<M> for NoBlockAllowed<D, M> {
60 fn metadata(&self) -> M {
61 M::default()
62 }
63}
64
65impl<'a, D, M> crate::RuleVariants<'a> for NoBlockAllowed<D, M>
66where
67 D: crate::DeclarationValue<'a, M>,
68 M: crate::NodeMetadata,
69{
70 type DeclarationValue = D;
71 type Metadata = M;
72}