pub fn parse_strength_directive(input: &str) -> IResult<&str, StrengthModifier>Expand description
Parse a strength directive (!:strength line)
Parses the !:strength directive that modifies rule strength.
Format: !:strength [+|-|*|/|=]N or !:strength N
§Examples
use libmagic_rs::parser::grammar::parse_strength_directive;
use libmagic_rs::parser::ast::StrengthModifier;
assert_eq!(parse_strength_directive("!:strength +10"), Ok(("", StrengthModifier::Add(10))));
assert_eq!(parse_strength_directive("!:strength -5"), Ok(("", StrengthModifier::Subtract(5))));
assert_eq!(parse_strength_directive("!:strength *2"), Ok(("", StrengthModifier::Multiply(2))));
assert_eq!(parse_strength_directive("!:strength /2"), Ok(("", StrengthModifier::Divide(2))));
assert_eq!(parse_strength_directive("!:strength =50"), Ok(("", StrengthModifier::Set(50))));
assert_eq!(parse_strength_directive("!:strength 50"), Ok(("", StrengthModifier::Set(50))));§Errors
Returns a nom parsing error if:
- Input doesn’t start with
!:strength - The modifier value cannot be parsed as a valid integer
- The operator is invalid