pub fn parse_text_magic_file(input: &str) -> Result<Vec<MagicRule>, ParseError>Expand description
Parses a complete magic file from raw text input.
This is the main public-facing parser function that orchestrates the complete parsing pipeline: preprocessing, parsing individual rules, and building the hierarchical structure.
§Arguments
input- The raw magic file content as a string
§Returns
Result<Vec<MagicRule>, ParseError> - A vector of root rules with nested children
§Errors
Returns an error if any stage of parsing fails:
- Preprocessing errors
- Rule parsing errors
- Hierarchy building errors
§Example
ⓘ
use libmagic_rs::parser::parse_text_magic_file;
let magic = r#"0 string \x7fELF ELF file
>4 byte 1 32-bit
>4 byte 2 64-bit"#;
let rules = parse_text_magic_file(magic)?;
assert_eq!(rules.len(), 1);
assert_eq!(rules[0].message, "ELF file");