css_ast/selector/
class.rs1use css_parse::{Cursor, Kind, Parse, Parser, Peek, Result as ParserResult, T};
2use csskit_derives::{ToCursors, ToSpan, Visitable};
3
4#[derive(ToSpan, ToCursors, Visitable, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))]
6#[visit(self)]
7pub struct Class {
8 pub dot: T![.],
9 pub name: T![Ident],
10}
11
12impl<'a> Peek<'a> for Class {
13 fn peek(p: &Parser<'a>, c: Cursor) -> bool {
14 c == Kind::Delim && c == '.' && p.peek_n(2) == Kind::Ident
15 }
16}
17
18impl<'a> Parse<'a> for Class {
19 fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
20 let dot = p.parse::<T![.]>()?;
21 let name = p.parse::<T![Ident]>()?;
22 Ok(Self { dot, name })
23 }
24}