(p: &mut Parser<'a, Iter>)
| 57 | // https://drafts.csswg.org/css-syntax-3/#consume-component-value |
| 58 | impl<'a> Parse<'a> for ComponentValue<'a> { |
| 59 | fn parse<Iter>(p: &mut Parser<'a, Iter>) -> ParserResult<Self> |
| 60 | where |
| 61 | Iter: Iterator<Item = Cursor> + Clone, |
| 62 | { |
| 63 | let c = p.peek_n(1); |
| 64 | Ok(if <T![' ']>::peek(p, c) { |
| 65 | Self::Whitespace(p.parse::<T![' ']>()?) |
| 66 | } else if <T![PairWiseStart]>::peek(p, c) { |
| 67 | let old_state = p.set_state(State::Nested); |
| 68 | let block = p.parse::<SimpleBlock>(); |
| 69 | p.set_state(old_state); |
| 70 | Self::SimpleBlock(block?) |
| 71 | } else if <T![Function]>::peek(p, c) { |
| 72 | Self::Function(p.parse::<FunctionBlock>()?) |
| 73 | } else if <T![Number]>::peek(p, c) { |
| 74 | Self::Number(p.parse::<T![Number]>()?) |
| 75 | } else if <T![Dimension]>::peek(p, c) { |
| 76 | Self::Dimension(p.parse::<T![Dimension]>()?) |
| 77 | } else if <T![Ident]>::peek(p, c) { |
| 78 | Self::Ident(p.parse::<T![Ident]>()?) |
| 79 | } else if <T![AtKeyword]>::peek(p, c) { |
| 80 | Self::AtKeyword(p.parse::<T![AtKeyword]>()?) |
| 81 | } else if <T![Hash]>::peek(p, c) { |
| 82 | Self::Hash(p.parse::<T![Hash]>()?) |
| 83 | } else if <T![String]>::peek(p, c) { |
| 84 | Self::String(p.parse::<T![String]>()?) |
| 85 | } else if <T![Url]>::peek(p, c) { |
| 86 | Self::Url(p.parse::<T![Url]>()?) |
| 87 | } else if <T![Delim]>::peek(p, c) { |
| 88 | p.parse::<T![Delim]>().map(|delim| { |
| 89 | // Carefully handle Whitespace rules to ensure whitespace isn't lost when re-serializing |
| 90 | let mut rules = AssociatedWhitespaceRules::none(); |
| 91 | if p.peek_n_with_skip(1, KindSet::COMMENTS) == Kind::Whitespace { |
| 92 | rules |= AssociatedWhitespaceRules::EnforceAfter; |
| 93 | } else { |
| 94 | rules |= AssociatedWhitespaceRules::BanAfter; |
| 95 | } |
| 96 | Self::Delim(delim.with_associated_whitespace(rules)) |
| 97 | })? |
| 98 | } else if <T![:]>::peek(p, c) { |
| 99 | Self::Colon(p.parse::<T![:]>()?) |
| 100 | } else if <T![;]>::peek(p, c) { |
| 101 | Self::Semicolon(p.parse::<T![;]>()?) |
| 102 | } else if <T![,]>::peek(p, c) { |
| 103 | Self::Comma(p.parse::<T![,]>()?) |
| 104 | } else { |
| 105 | Err(Diagnostic::new(p.next(), Diagnostic::unexpected))? |
| 106 | }) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | impl<'a> ToCursors for ComponentValue<'a> { |
nothing calls this directly
no test coverage detected