[][src]Function cldr_pluralrules_parser::parse_plural_rule

pub fn parse_plural_rule<S: AsRef<str>>(source: S) -> Result<Rule, String>

Given a string reference of a plural rule, will return the AST representation of that rule.

Examples

use cldr_pluralrules_parser::parse_plural_rule;
use cldr_pluralrules_parser::ast::*;

let condition = Condition(vec![
    AndCondition(vec![Relation {
        expression: Expression {
            operand: Operand::I,
            modulus: None,
        },
        operator: Operator::Is,
        range_list: RangeList(vec![RangeListItem::Value(Value(5))]),
    }]),
    AndCondition(vec![Relation {
        expression: Expression {
            operand: Operand::V,
            modulus: None,
        },
        operator: Operator::Within,
        range_list: RangeList(vec![RangeListItem::Value(Value(2))]),
    }]),
]);

assert_eq!(
    condition,
    parse_plural_rule("i is 5 or v within 2")
        .expect("Parsing succeeded")
        .condition
)