| 1 | // Copyright 2016 the SimpleCSS Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | |
| 4 | /*! |
| 5 | A simple [CSS 2.1](https://www.w3.org/TR/CSS21/) parser and selector. |
| 6 | |
| 7 | This is not a browser-grade CSS parser. If you need one, |
| 8 | use [cssparser](https://crates.io/crates/cssparser) + |
| 9 | [selectors](https://crates.io/crates/selectors). |
| 10 | |
| 11 | Since it's very simple we will start with limitations: |
| 12 | |
| 13 | ## Limitations |
| 14 | |
| 15 | - [At-rules](https://www.w3.org/TR/CSS21/syndata.html#at-rules) are not supported. |
| 16 | They will be skipped during parsing. |
| 17 | - Property values are not parsed. |
| 18 | In CSS like `* { width: 5px }` you will get a `width` property with a `5px` value as a string. |
| 19 | - CDO/CDC comments are not supported. |
| 20 | - Parser is case sensitive. All keywords must be lowercase. |
| 21 | - Unicode escape, like `\26`, is not supported. |
| 22 | |
| 23 | ## Features |
| 24 | |
| 25 | - Selector matching support. |
| 26 | - The rules are sorted by specificity. |
| 27 | - `!important` parsing support. |
| 28 | - Has a high-level parsers and low-level, zero-allocation tokenizers. |
| 29 | - No unsafe. |
| 30 | */ |
| 31 | |
| 32 | // LINEBENDER LINT SET - lib.rs - v2 |
| 33 | // See https://linebender.org/wiki/canonical-lints/ |
| 34 | // These lints aren't included in Cargo.toml because they |
| 35 | // shouldn't apply to examples and tests |
| 36 | #![warn(unused_crate_dependencies)] |
| 37 | #![warn(clippy::print_stdout, clippy::print_stderr)] |
| 38 | // Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit. |
| 39 | #![cfg_attr(target_pointer_width = "64", warn(clippy::trivially_copy_pass_by_ref))] |
| 40 | // END LINEBENDER LINT SET |
| 41 | #![cfg_attr(docsrs, feature(doc_auto_cfg))] |
| 42 | #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] |
| 43 | // The following lints are part of the Linebender standard set, |
| 44 | // but resolving them has been deferred for now. |
| 45 | // Feel free to send a PR that solves one or more of these. |
| 46 | #![allow( |
| 47 | missing_debug_implementations, |
| 48 | unreachable_pub, |
| 49 | clippy::use_self, |
| 50 | clippy::missing_assert_message, |
| 51 | clippy::missing_panics_doc, |
| 52 | clippy::exhaustive_enums, |
| 53 | clippy::unseparated_literal_suffix |
| 54 | )] |
| 55 | #![cfg_attr(test, allow(unused_crate_dependencies))] // Some dev dependencies are only used in tests |
| 56 | |
| 57 | extern crate allocrust-analyzer cargo simplecss 0.2.2 alloc/; |
| 58 | |
| 59 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 60 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 61 | |
| 62 | use logrust-analyzer cargo log 0.4.22 crate/::warnrust-analyzer cargo log 0.4.22 macros/warn!; |
| 63 | |
| 64 | mod selectorrust-analyzer cargo simplecss 0.2.2 selector/; |
| 65 | mod streamrust-analyzer cargo simplecss 0.2.2 stream/; |
| 66 | |
| 67 | pub use selectorrust-analyzer cargo simplecss 0.2.2 selector/::*; |
| 68 | use streamrust-analyzer cargo simplecss 0.2.2 stream/::Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#; |
| 69 | |
| 70 | /// A list of possible errors. |
| 71 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 72 | pub enum Errorrust-analyzer cargo simplecss 0.2.2 Error# { |
| 73 | /// The steam ended earlier than we expected. |
| 74 | /// |
| 75 | /// Should only appear on invalid input data. |
| 76 | UnexpectedEndOfStreamrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedEndOfStream#, |
| 77 | |
| 78 | /// An invalid ident. |
| 79 | InvalidIdentrust-analyzer cargo simplecss 0.2.2 Error#InvalidIdent#(TextPosrust-analyzer cargo simplecss 0.2.2 TextPos#), |
| 80 | |
| 81 | /// An unclosed comment. |
| 82 | InvalidCommentrust-analyzer cargo simplecss 0.2.2 Error#InvalidComment#(TextPosrust-analyzer cargo simplecss 0.2.2 TextPos#), |
| 83 | |
| 84 | /// An invalid declaration value. |
| 85 | InvalidValuerust-analyzer cargo simplecss 0.2.2 Error#InvalidValue#(TextPosrust-analyzer cargo simplecss 0.2.2 TextPos#), |
| 86 | |
| 87 | /// An invalid byte. |
| 88 | #[allow(missing_docs)] |
| 89 | InvalidByterust-analyzer cargo simplecss 0.2.2 Error#InvalidByte# { |
| 90 | expectedrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#expected.: u8, |
| 91 | actualrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#actual.: u8, |
| 92 | posrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#pos.: TextPosrust-analyzer cargo simplecss 0.2.2 TextPos#, |
| 93 | }, |
| 94 | |
| 95 | /// A missing selector. |
| 96 | SelectorMissingrust-analyzer cargo simplecss 0.2.2 Error#SelectorMissing#, |
| 97 | |
| 98 | /// An unexpected selector. |
| 99 | UnexpectedSelectorrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedSelector#, |
| 100 | |
| 101 | /// An unexpected combinator. |
| 102 | UnexpectedCombinatorrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedCombinator#, |
| 103 | |
| 104 | /// An invalid or unsupported attribute selector. |
| 105 | InvalidAttributeSelectorrust-analyzer cargo simplecss 0.2.2 Error#InvalidAttributeSelector#, |
| 106 | |
| 107 | /// An invalid language pseudo-class. |
| 108 | InvalidLanguagePseudoClassrust-analyzer cargo simplecss 0.2.2 Error#InvalidLanguagePseudoClass#, |
| 109 | } |
| 110 | |
| 111 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo simplecss 0.2.2 Error# { |
| 112 | fn fmtrust-analyzer cargo simplecss 0.2.2 impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 113 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 114 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::UnexpectedEndOfStreamrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedEndOfStream# => { |
| 115 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "unexpected end of stream") |
| 116 | } |
| 117 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidIdentrust-analyzer cargo simplecss 0.2.2 Error#InvalidIdent#(pos) => { |
| 118 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid ident at {}", pos) |
| 119 | } |
| 120 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidCommentrust-analyzer cargo simplecss 0.2.2 Error#InvalidComment#(pos) => { |
| 121 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid comment at {}", pos) |
| 122 | } |
| 123 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidValuerust-analyzer cargo simplecss 0.2.2 Error#InvalidValue#(pos) => { |
| 124 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid value at {}", pos) |
| 125 | } |
| 126 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidByterust-analyzer cargo simplecss 0.2.2 Error#InvalidByte# { |
| 127 | expectedrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#expected., |
| 128 | actualrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#actual., |
| 129 | posrust-analyzer cargo simplecss 0.2.2 Error#InvalidByte#pos., |
| 130 | } => { |
| 131 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 132 | f, |
| 133 | "expected '{}' not '{}' at {}", |
| 134 | expected as char, actual as char, pos |
| 135 | ) |
| 136 | } |
| 137 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::SelectorMissingrust-analyzer cargo simplecss 0.2.2 Error#SelectorMissing# => { |
| 138 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "selector missing") |
| 139 | } |
| 140 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::UnexpectedSelectorrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedSelector# => { |
| 141 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "unexpected selector") |
| 142 | } |
| 143 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::UnexpectedCombinatorrust-analyzer cargo simplecss 0.2.2 Error#UnexpectedCombinator# => { |
| 144 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "unexpected combinator") |
| 145 | } |
| 146 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidAttributeSelectorrust-analyzer cargo simplecss 0.2.2 Error#InvalidAttributeSelector# => { |
| 147 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid or unsupported attribute selector") |
| 148 | } |
| 149 | Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidLanguagePseudoClassrust-analyzer cargo simplecss 0.2.2 Error#InvalidLanguagePseudoClass# => { |
| 150 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid language pseudo-class") |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #[cfg(feature = "std")] |
| 157 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo simplecss 0.2.2 Error# {} |
| 158 | |
| 159 | /// A position in text. |
| 160 | /// |
| 161 | /// Position indicates a row/line and a column in the original text. Starting from 1:1. |
| 162 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 163 | #[allow(missing_docs)] |
| 164 | pub struct TextPosrust-analyzer cargo simplecss 0.2.2 TextPos# { |
| 165 | pub rowrust-analyzer cargo simplecss 0.2.2 TextPos#row.: u32, |
| 166 | pub colrust-analyzer cargo simplecss 0.2.2 TextPos#col.: u32, |
| 167 | } |
| 168 | |
| 169 | impl TextPosrust-analyzer cargo simplecss 0.2.2 TextPos# { |
| 170 | /// Constructs a new `TextPos`. |
| 171 | /// |
| 172 | /// Should not be invoked manually, but rather via `Stream::gen_text_pos`. |
| 173 | pub fn newrust-analyzer cargo simplecss 0.2.2 impl#[TextPos]new().(row: u32, col: u32) -> TextPosrust-analyzer cargo simplecss 0.2.2 TextPos# { |
| 174 | TextPosrust-analyzer cargo simplecss 0.2.2 TextPos# { rowrust-analyzer cargo simplecss 0.2.2 TextPos#row., colrust-analyzer cargo simplecss 0.2.2 TextPos#col. } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for TextPosrust-analyzer cargo simplecss 0.2.2 TextPos# { |
| 179 | fn fmtrust-analyzer cargo simplecss 0.2.2 impl#[TextPos][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 180 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}:{}", self.rowrust-analyzer cargo simplecss 0.2.2 TextPos#row., self.colrust-analyzer cargo simplecss 0.2.2 TextPos#col.) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /// A declaration. |
| 185 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 186 | #[allow(missing_docs)] |
| 187 | pub struct Declarationrust-analyzer cargo simplecss 0.2.2 Declaration#<'a> { |
| 188 | pub namerust-analyzer cargo simplecss 0.2.2 Declaration#name.: &'a str, |
| 189 | pub valuerust-analyzer cargo simplecss 0.2.2 Declaration#value.: &'a str, |
| 190 | pub importantrust-analyzer cargo simplecss 0.2.2 Declaration#important.: bool, |
| 191 | } |
| 192 | |
| 193 | /// A rule. |
| 194 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 195 | pub struct Rulerust-analyzer cargo simplecss 0.2.2 Rule#<'a> { |
| 196 | /// A rule selector. |
| 197 | pub selectorrust-analyzer cargo simplecss 0.2.2 Rule#selector.: Selectorrust-analyzer cargo simplecss 0.2.2 selector/Selector#<'a>, |
| 198 | /// A rule declarations. |
| 199 | pub declarationsrust-analyzer cargo simplecss 0.2.2 Rule#declarations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Declarationrust-analyzer cargo simplecss 0.2.2 Declaration#<'a>>, |
| 200 | } |
| 201 | |
| 202 | /// A style sheet. |
| 203 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 204 | pub struct StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet#<'a> { |
| 205 | /// A list of rules. |
| 206 | pub rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rulerust-analyzer cargo simplecss 0.2.2 Rule#<'a>>, |
| 207 | } |
| 208 | |
| 209 | impl<'a> StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet#<'a> { |
| 210 | /// Creates an empty style sheet. |
| 211 | pub fn newrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]new().() -> Selfrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`] { |
| 212 | StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet# { rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().() } |
| 213 | } |
| 214 | |
| 215 | /// Parses a style sheet from text. |
| 216 | /// |
| 217 | /// At-rules are not supported and will be skipped. |
| 218 | /// |
| 219 | /// # Errors |
| 220 | /// |
| 221 | /// Doesn't produce any errors. In worst case scenario will return an empty stylesheet. |
| 222 | /// |
| 223 | /// All warnings will be logged. |
| 224 | pub fn parserust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]parse().(text: &'a str) -> Selfrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`] { |
| 225 | let mut sheet = StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet#::newrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]new().(); |
| 226 | sheet.parse_morerust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]parse_more().(text); |
| 227 | sheet |
| 228 | } |
| 229 | |
| 230 | /// Parses a style sheet from a text to the current style sheet. |
| 231 | pub fn parse_morerust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]parse_more().(&mut self, text: &'a str) { |
| 232 | let mut s = Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#::fromrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`][`From<&'a str>`]from().(text); |
| 233 | |
| 234 | if s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.at_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]at_end().() { |
| 239 | if s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | let _ = consume_statementrust-analyzer cargo simplecss 0.2.2 consume_statement().(&mut s, &mut self.rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules.); |
| 244 | } |
| 245 | |
| 246 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.at_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]at_end().() { |
| 247 | warnrust-analyzer cargo log 0.4.22 macros/warn!!("{} bytes were left.", s.slice_tailrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]slice_tail().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()); |
| 248 | } |
| 249 | |
| 250 | // Remove empty rules. |
| 251 | self.rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules..retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]retain().(|rule| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rule.declarationsrust-analyzer cargo simplecss 0.2.2 Rule#declarations..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 252 | |
| 253 | // Sort the rules by specificity. |
| 254 | self.rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules. |
| 255 | .sort_by_cached_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_cached_key().(|rule| rule.selectorrust-analyzer cargo simplecss 0.2.2 Rule#selector..specificityrust-analyzer cargo simplecss 0.2.2 selector/impl#[`Selector<'a>`]specificity().()); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet#<'_> { |
| 260 | fn fmtrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'_>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 261 | for (i, rule) in self.rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 262 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{} {{ ", rule.selectorrust-analyzer cargo simplecss 0.2.2 Rule#selector.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 263 | for dec in &rule.declarationsrust-analyzer cargo simplecss 0.2.2 Rule#declarations. { |
| 264 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}:{}", dec.namerust-analyzer cargo simplecss 0.2.2 Declaration#name., dec.valuerust-analyzer cargo simplecss 0.2.2 Declaration#value.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 265 | if dec.importantrust-analyzer cargo simplecss 0.2.2 Declaration#important. { |
| 266 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, " !important")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 267 | } |
| 268 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ";")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 269 | } |
| 270 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, " }}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 271 | |
| 272 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().self.rulesrust-analyzer cargo simplecss 0.2.2 StyleSheet#rules..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 { |
| 273 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for StyleSheetrust-analyzer cargo simplecss 0.2.2 StyleSheet#<'_> { |
| 282 | fn defaultrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'_>`][Default]default().() -> Selfrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'_>`][Default] { |
| 283 | Selfrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'_>`][Default]::newrust-analyzer cargo simplecss 0.2.2 impl#[`StyleSheet<'a>`]new().() |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | fn consume_statementrust-analyzer cargo simplecss 0.2.2 consume_statement().<'a>(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'a>, rules: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rulerust-analyzer cargo simplecss 0.2.2 Rule#<'a>>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 288 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'@') { |
| 289 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 290 | consume_at_rulerust-analyzer cargo simplecss 0.2.2 consume_at_rule().(s) |
| 291 | } else { |
| 292 | consume_rule_setrust-analyzer cargo simplecss 0.2.2 consume_rule_set().(s, rules) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | fn consume_at_rulerust-analyzer cargo simplecss 0.2.2 consume_at_rule().(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 297 | let ident = s.consume_identrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_ident().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 298 | warnrust-analyzer cargo log 0.4.22 macros/warn!!("The @{} rule is not supported. Skipped.", ident); |
| 299 | |
| 300 | s.skip_bytesrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_bytes().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b';' && c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b'{'); |
| 301 | |
| 302 | match s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 303 | b';' => s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1), |
| 304 | b'{' => consume_blockrust-analyzer cargo simplecss 0.2.2 consume_block().(s), |
| 305 | _ => {} |
| 306 | } |
| 307 | |
| 308 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 309 | } |
| 310 | |
| 311 | fn consume_rule_setrust-analyzer cargo simplecss 0.2.2 consume_rule_set().<'a>(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'a>, rules: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rulerust-analyzer cargo simplecss 0.2.2 Rule#<'a>>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 312 | let start_rule_idx = rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 313 | |
| 314 | while s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b',' || start_rule_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 315 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b',' { |
| 316 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 317 | } |
| 318 | |
| 319 | let (selector, offset) = parserust-analyzer cargo simplecss 0.2.2 selector/parse().(s.slice_tailrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]slice_tail().()); |
| 320 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(offset); |
| 321 | s.skip_spacesrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces().(); |
| 322 | |
| 323 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selector) = selector { |
| 324 | rules.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Rulerust-analyzer cargo simplecss 0.2.2 Rule# { |
| 325 | selectorrust-analyzer cargo simplecss 0.2.2 Rule#selector., |
| 326 | declarationsrust-analyzer cargo simplecss 0.2.2 Rule#declarations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 327 | }); |
| 328 | } |
| 329 | |
| 330 | match s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 331 | b'{' => break, |
| 332 | b',' => {} |
| 333 | _ => { |
| 334 | s.skip_bytesrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_bytes().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b'{'); |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | s.try_consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]try_consume_byte().(b'{'); |
| 341 | |
| 342 | let declarations = consume_declarationsrust-analyzer cargo simplecss 0.2.2 consume_declarations().(s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 343 | for rule in rules.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(start_rule_idx) { |
| 344 | rule.declarationsrust-analyzer cargo simplecss 0.2.2 Rule#declarations. = declarations.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 345 | } |
| 346 | |
| 347 | s.try_consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]try_consume_byte().(b'}'); |
| 348 | |
| 349 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 350 | } |
| 351 | |
| 352 | fn consume_blockrust-analyzer cargo simplecss 0.2.2 consume_block().(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'_>) { |
| 353 | s.try_consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]try_consume_byte().(b'{'); |
| 354 | consume_until_block_endrust-analyzer cargo simplecss 0.2.2 consume_until_block_end().(s); |
| 355 | } |
| 356 | |
| 357 | fn consume_until_block_endrust-analyzer cargo simplecss 0.2.2 consume_until_block_end().(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'_>) { |
| 358 | // Block can have nested blocks, so we have to check for matching braces. |
| 359 | // We simply counting the number of opening braces, which is incorrect, |
| 360 | // since `{` can be inside a string, but it's fine for majority of the cases. |
| 361 | |
| 362 | let mut braces = 0; |
| 363 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.at_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]at_end().() { |
| 364 | match s.curr_byte_uncheckedrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte_unchecked().() { |
| 365 | b'{' => { |
| 366 | braces rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 367 | } |
| 368 | b'}' => { |
| 369 | if braces rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 370 | break; |
| 371 | } else { |
| 372 | braces rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1; |
| 373 | } |
| 374 | } |
| 375 | _ => {} |
| 376 | } |
| 377 | |
| 378 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 379 | } |
| 380 | |
| 381 | s.try_consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]try_consume_byte().(b'}'); |
| 382 | } |
| 383 | |
| 384 | fn consume_declarationsrust-analyzer cargo simplecss 0.2.2 consume_declarations().<'a>(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'a>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Declarationrust-analyzer cargo simplecss 0.2.2 Declaration#<'a>>, Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 385 | let mut declarations = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 386 | |
| 387 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.at_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]at_end().() && s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'}') { |
| 388 | match consume_declarationrust-analyzer cargo simplecss 0.2.2 consume_declaration().(s) { |
| 389 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(declaration) => declarations.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(declaration), |
| 390 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 391 | consume_until_block_endrust-analyzer cargo simplecss 0.2.2 consume_until_block_end().(s); |
| 392 | break; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(declarations) |
| 398 | } |
| 399 | |
| 400 | /// A declaration tokenizer. |
| 401 | /// |
| 402 | /// Tokenizer will stop at the first invalid token. |
| 403 | /// |
| 404 | /// # Example |
| 405 | /// |
| 406 | /// ``` |
| 407 | /// use simplecss::{DeclarationTokenizer, Declaration}; |
| 408 | /// |
| 409 | /// let mut t = DeclarationTokenizer::from("background: url(\"img.png\"); color:red !important"); |
| 410 | /// assert_eq!(t.next().unwrap(), Declaration { name: "background", value: "url(\"img.png\")", important: false }); |
| 411 | /// assert_eq!(t.next().unwrap(), Declaration { name: "color", value: "red", important: true }); |
| 412 | /// ``` |
| 413 | pub struct DeclarationTokenizerrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#<'a> { |
| 414 | streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream.: Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'a>, |
| 415 | } |
| 416 | |
| 417 | impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a str> for DeclarationTokenizerrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#<'a> { |
| 418 | fn fromrust-analyzer cargo simplecss 0.2.2 impl#[`DeclarationTokenizer<'a>`][`From<&'a str>`]from().(text: &'a str) -> Selfrust-analyzer cargo simplecss 0.2.2 impl#[`DeclarationTokenizer<'a>`][`From<&'a str>`] { |
| 419 | DeclarationTokenizerrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer# { |
| 420 | streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream.: Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#::fromrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`][`From<&'a str>`]from().(text), |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for DeclarationTokenizerrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#<'a> { |
| 426 | type Itemrust-analyzer cargo simplecss 0.2.2 impl#[`DeclarationTokenizer<'a>`][Iterator]Item# = Declarationrust-analyzer cargo simplecss 0.2.2 Declaration#<'a>; |
| 427 | |
| 428 | fn nextrust-analyzer cargo simplecss 0.2.2 impl#[`DeclarationTokenizer<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo simplecss 0.2.2 impl#[`DeclarationTokenizer<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 429 | let _ = self.streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream..skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().(); |
| 430 | |
| 431 | if self.streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream..at_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]at_end().() { |
| 432 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 433 | } |
| 434 | |
| 435 | match consume_declarationrust-analyzer cargo simplecss 0.2.2 consume_declaration().(&mut self.streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream.) { |
| 436 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v), |
| 437 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 438 | self.streamrust-analyzer cargo simplecss 0.2.2 DeclarationTokenizer#stream..jump_to_endrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]jump_to_end().(); |
| 439 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | fn consume_declarationrust-analyzer cargo simplecss 0.2.2 consume_declaration().<'a>(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'a>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Declarationrust-analyzer cargo simplecss 0.2.2 Declaration#<'a>, Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 446 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 447 | |
| 448 | // Parse name. |
| 449 | |
| 450 | // https://snook.ca/archives/html_and_css/targetting_ie7 |
| 451 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'*') { |
| 452 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 453 | } |
| 454 | |
| 455 | let name = s.consume_identrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_ident().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 456 | |
| 457 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 458 | s.consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_byte().(b':')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 459 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 460 | |
| 461 | // Parse value. |
| 462 | let start = s.posrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]pos().(); |
| 463 | let mut end = s.posrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]pos().(); |
| 464 | while consume_termrust-analyzer cargo simplecss 0.2.2 consume_term().(s).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() { |
| 465 | end = s.posrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]pos().(); |
| 466 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 467 | } |
| 468 | let value = s.slice_rangerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]slice_range().(start, end).trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(); |
| 469 | |
| 470 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 471 | |
| 472 | // Check for `important`. |
| 473 | let mut important = false; |
| 474 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'!') { |
| 475 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 476 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 477 | if s.slice_tailrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]slice_tail().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("important") { |
| 478 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(9); |
| 479 | important = true; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 484 | |
| 485 | while s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b';') { |
| 486 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 487 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 488 | } |
| 489 | |
| 490 | s.skip_spaces_and_commentsrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_spaces_and_comments().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 491 | |
| 492 | if value.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 493 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo simplecss 0.2.2 Error#::InvalidValuerust-analyzer cargo simplecss 0.2.2 Error#InvalidValue#(s.gen_text_pos_fromrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]gen_text_pos_from().(start))); |
| 494 | } |
| 495 | |
| 496 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Declarationrust-analyzer cargo simplecss 0.2.2 Declaration# { |
| 497 | namerust-analyzer cargo simplecss 0.2.2 Declaration#name., |
| 498 | valuerust-analyzer cargo simplecss 0.2.2 Declaration#value., |
| 499 | importantrust-analyzer cargo simplecss 0.2.2 Declaration#important., |
| 500 | }) |
| 501 | } |
| 502 | |
| 503 | fn consume_termrust-analyzer cargo simplecss 0.2.2 consume_term().(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo simplecss 0.2.2 Error#> { |
| 504 | fn consume_digitsrust-analyzer cargo simplecss 0.2.2 consume_digits().(s: &mut Streamrust-analyzer cargo simplecss 0.2.2 stream/Stream#<'_>) { |
| 505 | while let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9') = s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() { |
| 506 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | match s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 511 | b'#' => { |
| 512 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 513 | match s.consume_identrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_ident().() { |
| 514 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {} |
| 515 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 516 | // Try consume as a hex color. |
| 517 | while let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) = s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() { |
| 518 | match c { |
| 519 | b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9' | b'a'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'f' | b'A'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'F' => s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1), |
| 520 | _ => break, |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | b'+' | b'-' | b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9' | b'.' => { |
| 527 | // Consume number. |
| 528 | |
| 529 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 530 | consume_digitsrust-analyzer cargo simplecss 0.2.2 consume_digits().(s); |
| 531 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'.') { |
| 532 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 533 | consume_digitsrust-analyzer cargo simplecss 0.2.2 consume_digits().(s); |
| 534 | } |
| 535 | |
| 536 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'%') { |
| 537 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 538 | } else { |
| 539 | // Consume suffix if any. |
| 540 | let _ = s.consume_identrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_ident().(); |
| 541 | } |
| 542 | } |
| 543 | b'\'' | b'"' => { |
| 544 | s.consume_stringrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_string().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 545 | } |
| 546 | b',' => { |
| 547 | s.advancerust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]advance().(1); |
| 548 | } |
| 549 | _ => { |
| 550 | let _ = s.consume_identrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_ident().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 551 | |
| 552 | // Consume function. |
| 553 | if s.curr_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]curr_byte().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][`PartialEq<Self>`]eq().Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b'(') { |
| 554 | s.skip_bytesrust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]skip_bytes().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b')'); |
| 555 | s.consume_byterust-analyzer cargo simplecss 0.2.2 stream/impl#[`Stream<'a>`]consume_byte().(b')')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 561 | } |