(p: &Parser<'a, Iter>, c: Cursor)
| 77 | |
| 78 | #[inline(always)] |
| 79 | fn peek<Iter>(p: &Parser<'a, Iter>, c: Cursor) -> bool |
| 80 | where |
| 81 | Iter: Iterator<Item = crate::Cursor> + Clone, |
| 82 | { |
| 83 | // A declaration must be an Ident followed by a Colon (with any number of whitespace inbetween). If that is not the |
| 84 | // case then it definitely cannot be parsed as a Declaration. |
| 85 | // |
| 86 | // https://drafts.csswg.org/css-syntax-3/#consume-a-blocks-contents |
| 87 | // ... "If the next non-whitespace token isn’t a <colon-token>, you can similarly immediately stop parsing as a |
| 88 | // declaration." ... "(That is, font+ ... is guaranteed to not be a property"... |
| 89 | if c != Kind::Ident || p.peek_n(2) != Kind::Colon { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | // https://drafts.csswg.org/css-syntax-3/#consume-a-blocks-contents |
| 94 | // ... "If the first two non-whitespace tokens are a custom property name and a colon, it’s definitely a custom |
| 95 | // property and won’t ever produce a valid rule" ... "(That is, --foo:hover {...} is guaranteed to be a custom |
| 96 | // property, not a rule.)". |
| 97 | if c.token().is_dashed_ident() { |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | // If the third token is a `Colon` then it's likely a Pseudo Element selector. Colons are not valid value tokens |
| 102 | // inside of a declaration at current, however this is _technically_ a non-standard affordance that may be removed |
| 103 | // in future. |
| 104 | if p.peek_n(3) == Kind::Colon { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | // https://drafts.csswg.org/css-syntax-3/#consume-a-blocks-contents |
| 109 | // ... "If the first three non-whitespace tokens are a valid property name, a colon, and anything other than a |
| 110 | // <{-token>, and then while parsing the declaration's value you encounter a <{-token>, you can immediately stop |
| 111 | // parsing as a declaration and reparse as a rule instead. |
| 112 | // (That is, font:bar {... is guaranteed to be an invalid property.)" |
| 113 | if p.peek_n(4) == Kind::LeftCurly || p.peek_n(5) == Kind::LeftCurly { |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | // All early checks have been exhausted, so the next step is to parse the Declaration to see if it is valid. |
| 118 | true |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | impl<'a, V, M> Parse<'a> for Declaration<'a, V, M> |
nothing calls this directly
no test coverage detected