css_parse/syntax/
bang_important.rs1use crate::{
2 Cursor, CursorSink, Diagnostic, Kind, Parse, Parser, Peek, Result, SemanticEq, Span, T, ToCursors, ToSpan,
3};
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
25pub struct BangImportant {
26 pub bang: T![!],
27 pub important: T![Ident],
28}
29
30impl<'a> Peek<'a> for BangImportant {
31 fn peek<Iter>(p: &Parser<'a, Iter>, c: Cursor) -> bool
32 where
33 Iter: Iterator<Item = Cursor> + Clone,
34 {
35 if c == Kind::Delim && c == '!' {
36 let c = p.peek_n(2);
37 c == Kind::Ident && p.to_source_cursor(c).eq_ignore_ascii_case("important")
38 } else {
39 false
40 }
41 }
42}
43
44impl<'a> Parse<'a> for BangImportant {
45 fn parse<Iter>(p: &mut Parser<'a, Iter>) -> Result<Self>
46 where
47 Iter: Iterator<Item = Cursor> + Clone,
48 {
49 let bang = p.parse::<T![!]>()?;
50 let important = p.parse::<T![Ident]>()?;
51 if !p.to_source_cursor(important.into()).eq_ignore_ascii_case("important") {
52 Err(Diagnostic::new(important.into(), Diagnostic::unexpected_ident))?
53 }
54 Ok(Self { bang, important })
55 }
56}
57
58impl ToCursors for BangImportant {
59 fn to_cursors(&self, s: &mut impl CursorSink) {
60 s.append(self.bang.into());
61 s.append(self.important.into());
62 }
63}
64
65impl ToSpan for BangImportant {
66 fn to_span(&self) -> Span {
67 self.bang.to_span() + self.important.to_span()
68 }
69}
70
71impl SemanticEq for BangImportant {
72 fn semantic_eq(&self, _: &Self) -> bool {
73 true
75 }
76}