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(p: &Parser<'a>, c: Cursor) -> bool {
30 if c == Kind::Delim && c == '!' {
31 let c = p.peek_n(2);
32 c == Kind::Ident && p.to_source_cursor(c).eq_ignore_ascii_case("important")
33 } else {
34 false
35 }
36 }
37}
38
39impl<'a> Parse<'a> for BangImportant {
40 fn parse(p: &mut Parser<'a>) -> Result<Self> {
41 let bang = p.parse::<T![!]>()?;
42 let important = p.parse::<T![Ident]>()?;
43 if !p.to_source_cursor(important.into()).eq_ignore_ascii_case("important") {
44 Err(Diagnostic::new(important.into(), Diagnostic::unexpected_ident))?
45 }
46 Ok(Self { bang, important })
47 }
48}
49
50impl ToCursors for BangImportant {
51 fn to_cursors(&self, s: &mut impl CursorSink) {
52 s.append(self.bang.into());
53 s.append(self.important.into());
54 }
55}
56
57impl ToSpan for BangImportant {
58 fn to_span(&self) -> Span {
59 self.bang.to_span() + self.important.to_span()
60 }
61}