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

Function find_options_with_keywords

crates/csskit_proc_macro/src/generate.rs:332–356  ·  view source on GitHub ↗

Find Options combinators containing keyword (Ident) children that need helper structs. Searches: direct Alternatives children, and NoneOr/AutoOr/NormalOr/AutoNoneOr wrappers.

(def: &Def)

Source from the content-addressed store, hash-verified

330/// Find Options combinators containing keyword (Ident) children that need helper structs.
331/// Searches: direct Alternatives children, and NoneOr/AutoOr/NormalOr/AutoNoneOr wrappers.
332fn find_options_with_keywords(def: &Def) -> Vec<&Def> {
333 fn is_options_with_keywords(def: &Def) -> bool {
334 if let Def::Combinator(defs, DefCombinatorStyle::Options) = def {
335 defs.iter().any(|d| !matches!(d, Def::Type(_) | Def::StyleValue(_)))
336 } else {
337 false
338 }
339 }
340 fn unwrap_to_options(def: &Def) -> Option<&Def> {
341 match def {
342 Def::Group(inner, _) => unwrap_to_options(inner),
343 d if is_options_with_keywords(d) => Some(d),
344 _ => None,
345 }
346 }
347 match def {
348 Def::Combinator(children, DefCombinatorStyle::Alternatives) => {
349 children.iter().filter_map(unwrap_to_options).collect()
350 }
351 Def::NoneOr(inner) | Def::AutoOr(inner) | Def::NormalOr(inner) | Def::AutoNoneOr(inner) => {
352 unwrap_to_options(inner).into_iter().collect()
353 }
354 _ => vec![],
355 }
356}
357
358/// For a list of sibling `Combinator(Options, ...)` children, compute each child's
359/// distinguishing keyword set: the keywords that appear in this child but NOT in some other

Callers 2

generate_definitionMethod · 0.85

Calls 4

unwrap_to_optionsFunction · 0.85
collectMethod · 0.80
iterMethod · 0.80
into_iterMethod · 0.80

Tested by

no test coverage detected