draxl_validate/lib.rs
1#![forbid(unsafe_code)]
2//! Structural validation for Draxl source files.
3//!
4//! Validation runs after parsing and checks the stronger invariants that make
5//! canonical printing, lowering, and patch application predictable:
6//!
7//! - ids must be unique
8//! - ranked slots must provide ranks
9//! - anchors must refer to valid targets
10//! - detached comments and docs must resolve deterministically
11
12mod error;
13mod validator;
14
15use draxl_ast::File;
16
17pub use error::ValidationError;
18
19/// Runs structural validation for a parsed Draxl file.
20pub fn validate_file(file: &File) -> Result<(), Vec<ValidationError>> {
21 let mut validator = validator::Validator::default();
22 validator.collect_file_ids(file);
23 validator.validate_file(file);
24 if validator.errors.is_empty() {
25 Ok(())
26 } else {
27 Err(validator.errors)
28 }
29}