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