Expand description

A crate for parsing CLDR plural rules.

This crate parses plural rules and returns an AST representation of the rule. Plural rules must be written according to the specifications outlined at Unicode’s website.

Plural rules, compatible with this crate, can be found at this GitHub repository.

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"))

Modules

A public AST module for plural rule representations.

Functions

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