accessibility_rs/engine/styles/
rules.rs1use crate::engine::styles::errors::RuleParseErrorKind;
2use accessibility_scraper::selector::Simple;
3use cssparser::{AtRuleParser, ParseError, QualifiedRuleParser};
4use std::sync::Arc;
5
6#[derive(Debug)]
7pub enum CssRule {
9 StyleRule {
11 selectors: selectors::SelectorList<Simple>,
13 block: Arc<String>,
15 },
16}
17
18pub struct Parser;
20
21impl<'i> selectors::parser::Parser<'i> for Parser {
22 type Impl = Simple;
23 type Error = RuleParseErrorKind<'i>;
24}
25
26pub type SelectorList = selectors::SelectorList<Simple>;
28pub struct RulesParser;
32
33impl<'i> QualifiedRuleParser<'i> for RulesParser {
34 type Prelude = SelectorList;
35 type QualifiedRule = CssRule;
36 type Error = RuleParseErrorKind<'i>;
37
38 fn parse_prelude<'t>(
39 &mut self,
40 parser: &mut cssparser::Parser<'i, 't>,
41 ) -> Result<Self::Prelude, ParseError<'i, Self::Error>> {
42 SelectorList::parse(&Parser, parser)
43 }
44
45 fn parse_block<'t>(
46 &mut self,
47 prelude: Self::Prelude,
48 _location: cssparser::SourceLocation,
49 _parser: &mut cssparser::Parser<'i, 't>,
50 ) -> Result<Self::QualifiedRule, ParseError<'i, Self::Error>> {
51 Ok(CssRule::StyleRule {
52 selectors: prelude,
53 block: Arc::new(String::new()),
54 })
55 }
56}
57
58impl<'i> AtRuleParser<'i> for RulesParser {
59 type PreludeBlock = ();
60 type PreludeNoBlock = ();
61 type AtRule = CssRule;
62 type Error = RuleParseErrorKind<'i>;
63}