pub fn parse_text_magic_file(input: &str) -> Result<ParsedMagic, 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<ParsedMagic, ParseError> - A ParsedMagic value containing
the top-level rules (with name-declared subroutines hoisted out) and
the resulting name table.
§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 parsed = parse_text_magic_file(magic)?;
assert_eq!(parsed.rules.len(), 1);
assert_eq!(parsed.rules[0].message, "ELF file");