Skip to main content

validate

Function validate 

Source
pub fn validate(file: &str, strict: bool, lenient: bool) -> Result<(), CliError>
Expand description

Validate a HEDL file for syntax and structural correctness.

Parses a HEDL file and reports whether it is syntactically valid. In strict mode, all entity references must resolve to defined entities. In lenient mode, constraint violations become null values with diagnostics emitted separately.

§Arguments

  • file - Path to the HEDL file to validate
  • strict - If true, enables strict reference validation (all references must resolve)
  • lenient - If true, uses lenient parsing mode (constraint violations become null)

§Returns

Returns Ok(()) if the file is valid, Err with a descriptive error message otherwise.

§Errors

Returns Err if:

  • The file cannot be read
  • The file contains syntax errors
  • In strict mode, if any entity references cannot be resolved
  • In non-lenient mode, if constraints are violated

§Examples

use hedl_cli::commands::validate;

// Validate a well-formed HEDL file
validate("valid.hedl", false, false)?;

// Strict validation requires all references to resolve
validate("references.hedl", true, false)?;

// Lenient mode allows constraint violations
validate("data.hedl", false, true)?;

// Invalid syntax will fail
let result = validate("invalid.hedl", false, false);
assert!(result.is_err());

§Output

Prints a summary to stdout including:

  • File validation status (✓ or ✗)
  • HEDL version
  • Count of structs, aliases, and nests
  • Parse mode (strict/lenient)
  • Reference mode indicator if strict enabled