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

Method parse_stylesheet

crates/css_parse/src/traits/style_sheet.rs:26–48  ·  view source on GitHub ↗
(p: &mut Parser<'a, I>)

Source from the content-addressed store, hash-verified

24 type Rule: Parse<'a> + NodeWithMetadata<M>;
25
26 fn parse_stylesheet<I>(p: &mut Parser<'a, I>) -> Result<(Vec<'a, Self::Rule>, M)>
27 where
28 I: Iterator<Item = Cursor> + Clone,
29 {
30 let mut rules: Vec<'a, Self::Rule> = Vec::new_in(p.bump());
31 let mut meta: M = Default::default();
32 loop {
33 // While by default the parser will skip whitespace, the Rule type may be a whitespace sensitive
34 // node, for example `ComponentValues`. As such whitespace needs to be consumed here, before Declarations and
35 // Rules are parsed.
36 if p.parse_if_peek::<T![' ']>()?.is_some() || p.parse_if_peek::<T![CdcOrCdo]>()?.is_some() {
37 continue;
38 }
39
40 // need to peek as last tokens may be whitespace.
41 if p.at_end() || p.peek_n(1) == Kind::Eof {
42 return Ok((rules, meta));
43 }
44 let rule = p.parse::<Self::Rule>()?;
45 meta = meta.merge(rule.metadata());
46 rules.push(rule);
47 }
48 }
49}

Callers

nothing calls this directly

Calls 5

peek_nMethod · 0.80
bumpMethod · 0.45
at_endMethod · 0.45
mergeMethod · 0.45
metadataMethod · 0.45

Tested by

no test coverage detected