Parse and extract from one file. Returns Ok(rows) or Err(error_record). `on_stylesheet` is called with the stylesheet while still in scope.
( &self, file: &str, src: &str, bump: &Bump, on_stylesheet: &mut dyn for<'a> FnMut(&StyleSheet<'a>), )
| 143 | /// Parse and extract from one file. Returns Ok(rows) or Err(error_record). |
| 144 | /// `on_stylesheet` is called with the stylesheet while still in scope. |
| 145 | fn parse_and_extract_file( |
| 146 | &self, |
| 147 | file: &str, |
| 148 | src: &str, |
| 149 | bump: &Bump, |
| 150 | on_stylesheet: &mut dyn for<'a> FnMut(&StyleSheet<'a>), |
| 151 | ) -> Result<Vec<(Span, Self::Row)>, ErrorRecord> { |
| 152 | let mut rows = Vec::new(); |
| 153 | if self.try_content(src, bump, &mut rows) { |
| 154 | return Ok(rows); |
| 155 | } |
| 156 | |
| 157 | let lexer = Lexer::new(&CssAtomSet::ATOMS, src); |
| 158 | let mut parser = Parser::new(bump, src, lexer); |
| 159 | let result = parser.parse_entirely::<StyleSheet>(); |
| 160 | |
| 161 | if let Some(stylesheet) = result.output { |
| 162 | on_stylesheet(&stylesheet); |
| 163 | self.extract(&stylesheet, src, &mut rows); |
| 164 | Ok(rows) |
| 165 | } else { |
| 166 | let message = result |
| 167 | .errors |
| 168 | .first() |
| 169 | .map(|e| { |
| 170 | if matches!(self.format(), OutputFormat::Text) { |
| 171 | eprintln!("{}", crate::commands::format_diagnostic_error(e, src, file)); |
| 172 | } |
| 173 | e.message(src).to_string() |
| 174 | }) |
| 175 | .unwrap_or_else(|| "parse failed".to_string()); |
| 176 | Err(ErrorRecord { kind: ErrorKind::ParseError, message }) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /// Run the command: loop files, parse, extract, render. |
| 181 | fn run(&self, config: GlobalConfig) -> CliResult { |
no test coverage detected