Struct cldr_pluralrules_parser::ast::Condition
source · pub struct Condition(pub Vec<AndCondition>);
Expand description
A complete (and the only complete) AST representation of a plural rule. Comprises a vector of AndConditions.
Examples
All AST nodes can be built explicitly, as seen in the example. However, due to its complexity, it is preferred to build the AST using the parse_plural_rule function.
"i = 5"
Can be represented by the AST:
use cldr_pluralrules_parser::ast::*;
Condition(vec![AndCondition(vec![Relation {
expression: Expression {
operand: Operand('i'),
modulus: None,
},
operator: Operator::EQ,
range_list: RangeList(vec![RangeListItem::Value(Value(5))]),
}])]);
Because they care complete representations, hand-written Conditions can be verified with the assert macro. No other AST nodes can be verified.
use cldr_pluralrules_parser::ast::*;
use cldr_pluralrules_parser::parse_plural_rule;
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"))
Tuple Fields
0: Vec<AndCondition>
Trait Implementations
impl StructuralPartialEq for Condition
Auto Trait Implementations
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnwindSafe for Condition
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more