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

Method parse

crates/css_parse/src/syntax/bad_declaration.rs:13–52  ·  view source on GitHub ↗
(p: &mut Parser<'a, Iter>)

Source from the content-addressed store, hash-verified

11// https://drafts.csswg.org/css-syntax-3/#consume-the-remnants-of-a-bad-declaration
12impl<'a> Parse<'a> for BadDeclaration<'a> {
13 fn parse<Iter>(p: &mut Parser<'a, Iter>) -> ParserResult<Self>
14 where
15 Iter: Iterator<Item = crate::Cursor> + Clone,
16 {
17 let mut values = Vec::new_in(p.bump());
18 // To consume the remnants of a bad declaration from a token stream input, given a bool nested:
19 //
20 // Process input:
21 loop {
22 // <eof-token>
23 // <semicolon-token>
24 //
25 // Discard a token from input, and return nothing.
26 if p.at_end() {
27 return Ok(Self(values));
28 }
29 let c = p.peek_n(1);
30 if <T![;]>::peek(p, c) {
31 values.push(p.parse::<ComponentValue>()?);
32 return Ok(Self(values));
33 }
34
35 // <}-token>
36 //
37 // If nested is true, return nothing. Otherwise, discard a token.
38 if <T!['}']>::peek(p, c) {
39 if p.is(State::Nested) {
40 return Ok(Self(values));
41 } else {
42 p.parse::<T!['}']>()?;
43 }
44 }
45
46 // anything else
47 //
48 // Consume a component value from input, and do nothing.
49 //
50 values.push(p.parse::<ComponentValue>()?);
51 }
52 }
53}
54
55impl<'a> ToSpan for BadDeclaration<'a> {

Callers

nothing calls this directly

Calls 4

peek_nMethod · 0.80
isMethod · 0.80
bumpMethod · 0.45
at_endMethod · 0.45

Tested by

no test coverage detected