MediaWiki
REL1_24
|
Helper class for converting rules to reverse polish notation (RPN). More...
Static Public Member Functions | |
static | convert ($rule) |
Convert a rule to RPN. | |
Public Attributes | |
int | $end |
The past-the-end position. | |
array | $operands = array() |
The operand stack. | |
array | $operators = array() |
The operator stack. | |
int | $pos |
The current position. | |
string | $rule |
The input string. | |
const | NUMBER_CLASS = '0123456789' |
Same for digits. | |
const | OPERAND_SYMBOLS = 'nivwft' |
A character list of symbolic operands. | |
const | WHITESPACE_CLASS = " \t\r\n" |
A character list defining whitespace, for use in strspn() etc. | |
const | WORD_REGEX = '/[a-zA-Z@]+/A' |
An anchored regular expression which matches a word at the current offset. | |
Protected Member Functions | |
__construct ($rule) | |
Private constructor. | |
doConvert () | |
Do the operation. | |
doOperation ($op) | |
For the binary operator $op, pop its operands off the stack and push a fragment with rpn and type members describing the result of that operation. | |
error ($message) | |
Throw an error. | |
newNumber ($text, $pos) | |
Create a numerical expression object. | |
newOperator ($type, $pos, $length) | |
Create a binary operator. | |
nextToken () | |
Fetch the next token from the input string. | |
Static Private Attributes | |
static | $precedence |
Precedence levels. |
Helper class for converting rules to reverse polish notation (RPN).
Definition at line 15 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::__construct | ( | $ | rule | ) | [protected] |
Private constructor.
string | $rule |
Definition at line 102 of file CLDRPluralRuleConverter.php.
References $rule.
static CLDRPluralRuleConverter::convert | ( | $ | rule | ) | [static] |
Convert a rule to RPN.
This is the only public entry point.
string | $rule | The rule to convert |
Definition at line 92 of file CLDRPluralRuleConverter.php.
Referenced by CLDRPluralRuleEvaluator\compile().
CLDRPluralRuleConverter::doConvert | ( | ) | [protected] |
Do the operation.
Definition at line 113 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::doOperation | ( | $ | op | ) | [protected] |
For the binary operator $op, pop its operands off the stack and push a fragment with rpn and type members describing the result of that operation.
CLDRPluralRuleConverterOperator | $op |
Definition at line 277 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::error | ( | $ | message | ) | [protected] |
Throw an error.
string | $message |
Definition at line 314 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::newNumber | ( | $ | text, |
$ | pos | ||
) | [protected] |
Create a numerical expression object.
string | $text | |
int | $pos |
Definition at line 294 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::newOperator | ( | $ | type, |
$ | pos, | ||
$ | length | ||
) | [protected] |
Create a binary operator.
string | $type | |
int | $pos | |
int | $length |
Definition at line 306 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::nextToken | ( | ) | [protected] |
Fetch the next token from the input string.
Definition at line 173 of file CLDRPluralRuleConverter.php.
int CLDRPluralRuleConverter::$end |
The past-the-end position.
Definition at line 32 of file CLDRPluralRuleConverter.php.
The operand stack.
Definition at line 44 of file CLDRPluralRuleConverter.php.
The operator stack.
Definition at line 38 of file CLDRPluralRuleConverter.php.
int CLDRPluralRuleConverter::$pos |
The current position.
Definition at line 26 of file CLDRPluralRuleConverter.php.
CLDRPluralRuleConverter::$precedence [static, private] |
array( 'or' => 2, 'and' => 3, 'is' => 4, 'is-not' => 4, 'in' => 4, 'not-in' => 4, 'within' => 4, 'not-within' => 4, 'mod' => 5, ',' => 6, '..' => 7, )
Precedence levels.
Note that there's no need to worry about associativity for the level 4 operators, since they return boolean and don't accept boolean inputs.
Definition at line 51 of file CLDRPluralRuleConverter.php.
string CLDRPluralRuleConverter::$rule |
The input string.
Definition at line 20 of file CLDRPluralRuleConverter.php.
Referenced by __construct().
const CLDRPluralRuleConverter::NUMBER_CLASS = '0123456789' |
Same for digits.
Note that the grammar given in UTS #35 doesn't allow negative numbers or decimal separators.
Definition at line 74 of file CLDRPluralRuleConverter.php.
const CLDRPluralRuleConverter::OPERAND_SYMBOLS = 'nivwft' |
A character list of symbolic operands.
Definition at line 79 of file CLDRPluralRuleConverter.php.
const CLDRPluralRuleConverter::WHITESPACE_CLASS = " \t\r\n" |
A character list defining whitespace, for use in strspn() etc.
Definition at line 68 of file CLDRPluralRuleConverter.php.
const CLDRPluralRuleConverter::WORD_REGEX = '/[a-zA-Z@]+/A' |
An anchored regular expression which matches a word at the current offset.
Definition at line 84 of file CLDRPluralRuleConverter.php.