Find Options combinators containing keyword (Ident) children that need helper structs. Searches: direct Alternatives children, and NoneOr/AutoOr/NormalOr/AutoNoneOr wrappers.
(def: &Def)
| 330 | /// Find Options combinators containing keyword (Ident) children that need helper structs. |
| 331 | /// Searches: direct Alternatives children, and NoneOr/AutoOr/NormalOr/AutoNoneOr wrappers. |
| 332 | fn 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 |
no test coverage detected