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

Method parse_and_extract_file

crates/csskit/src/commands/extract.rs:145–178  ·  view source on GitHub ↗

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>),
	)

Source from the content-addressed store, hash-verified

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 {

Callers 1

runMethod · 0.45

Implementers 3

specificity.rscrates/csskit/src/commands/specificity
colors.rscrates/csskit/src/commands/colors.rs
find.rscrates/csskit/src/commands/find.rs

Calls 4

ErrClass · 0.85
messageMethod · 0.80
try_contentMethod · 0.45
extractMethod · 0.45

Tested by

no test coverage detected