diff --git a/src/rules/rule.rs b/src/rules/rule.rs index 63c8208..37fd05d 100644 --- a/src/rules/rule.rs +++ b/src/rules/rule.rs @@ -599,11 +599,28 @@ impl RuleSyntax { let path = path.as_ref(); let contents = std::fs::read_to_string(path) .with_context(|| format!("Failed to read file: {}", path.display()))?; - serde_yaml::from_str(&contents).map_err(|e| { + #[derive(Deserialize)] + #[serde(untagged)] + enum RuleSyntaxDocument { + Sequence(Vec), + Mapped { rules: Vec }, + } + + let parsed: RuleSyntaxDocument = serde_yaml::from_str(&contents).map_err(|e| { let context = e.location().map_or(String::new(), |loc| { format!(" at line {} column {}", loc.line(), loc.column()) }); - anyhow!("Failed to parse YAML from {}{}: {}", path.display(), context, e) + anyhow!( + "Failed to parse YAML from {}{}: {}", + path.display(), + context, + e + ) + })?; + + Ok(match parsed { + RuleSyntaxDocument::Sequence(rules) => rules, + RuleSyntaxDocument::Mapped { rules } => rules, }) } }