MCPcopy Create free account
hub / github.com/csskit/csskit / parse

Method parse

crates/css_ast/src/rules/charset.rs:21–40  ·  view source on GitHub ↗
(p: &mut Parser<'a, I>)

Source from the content-addressed store, hash-verified

19// https://drafts.csswg.org/css-syntax-3/#determine-the-fallback-encoding
20impl<'a> Parse<'a> for CharsetRule {
21 fn parse<I>(p: &mut Parser<'a, I>) -> ParserResult<Self>
22 where
23 I: Iterator<Item = Cursor> + Clone,
24 {
25 let at_keyword = p.parse::<T![AtKeyword]>()?;
26 let c: Cursor = at_keyword.into();
27 // CharsetRule MUST be all lowercase, alt cases such as CHARSET or charSet aren't
28 // valid here, compares to other at-rules which are case insensitive.
29 if !p.equals_atom(c, &CssAtomSet::Charset) {
30 Err(Diagnostic::new(c, Diagnostic::unexpected))?;
31 }
32 // Charsets MUST have a space between the at keyword and the string. This
33 // isn't necessary in other at rules where an at keyword can align with other
34 // delims (e.g. `(`) or unambinguous tokens like strings.
35 let space = p.parse::<T![' ']>()?;
36 let string = p.parse::<T![String]>()?;
37 // TODO: check quote style as it should be "
38 let semicolon = p.parse::<T![;]>().ok();
39 Ok(Self { at_keyword, space, string, semicolon })
40 }
41}
42
43#[cfg(test)]

Callers

nothing calls this directly

Calls 3

ErrClass · 0.85
okMethod · 0.80
equals_atomMethod · 0.45

Tested by

no test coverage detected