API / Minn\I18n / PluralExpression

PluralExpression final class

Minn\I18n\PluralExpression · public/minn/src/Minn/I18n/PluralExpression.php · 147 lines

The C subset a Plural-Forms header writes its rule in: the number n, integer literals, parentheses, ! and unary minus, * / %, + -, the four comparisons, == and !=, && and ||, and the ternary, with C's precedence and the ternary binding to the right. Parsed into a small tree once and evaluated per number; nothing is ever handed to PHP to run.

Used by 1

Constants and properties

privateTOKEN = '/\\G\\s*(\\d+|n|==|!=|<=|>=|&&|\\|\\||[<>!?:()+\\-*\\/%])/'
privateBINARY = array ( '||' => 1, '&&' => 2, '==' => 3, '!=' => 3, '<' => 4, '>' => 4, '<=' => 4, '>=' => 4, '+' => 5, '-' => 5, '*' => 6, '/' => 6, '%' => 6, )

Public

staticparse(string $expression): ?array#

The expression as a tree, or null when it is not a whole expression.

@return array<int, mixed>|null
staticevaluate(array $node, int $n): int#

The value of a parsed expression for one number; true is 1 and false 0.

$nodearray<int, mixed>

Internals 5

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatebinary(string $operator, int $left, int $right): int#
privatetokens(string $expression): ?array#
@return list<string>|null
privateternary(array $tokens, int $position): ?array#
$tokenslist<string>
@return array<int, mixed>|null
privatebinaryLevel(array $tokens, int $position, int $level): ?array#

One level of left-associative binary operators, and every tighter level under it.

$tokenslist<string>
@return array<int, mixed>|null
privateunary(array $tokens, int $position): ?array#
$tokenslist<string>
@return array<int, mixed>|null