MediaWiki  1.23.12
CLDRPluralRuleConverter Class Reference

Helper class for converting rules to reverse polish notation (RPN). More...

Collaboration diagram for CLDRPluralRuleConverter:

Static Public Member Functions

static convert ( $rule)
 Convert a rule to RPN. More...
 

Public Attributes

int $end
 The past-the-end position. More...
 
array $operands = array()
 The operand stack. More...
 
array $operators = array()
 The operator stack. More...
 
int $pos
 The current position. More...
 
string $rule
 The input string. More...
 
const NUMBER_CLASS = '0123456789'
 Same for digits. More...
 
const OPERAND_SYMBOLS = 'nivwft'
 A character list of symbolic operands. More...
 
const WHITESPACE_CLASS = " \t\r\n"
 A character list defining whitespace, for use in strspn() etc. More...
 
const WORD_REGEX = '/[a-zA-Z@]+/A'
 An anchored regular expression which matches a word at the current offset. More...
 

Static Public Attributes

static $precedence
 Precedence levels. More...
 

Protected Member Functions

 __construct ( $rule)
 Private constructor. More...
 
 doConvert ()
 Do the operation. More...
 
 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. More...
 
 error ( $message)
 Throw an error. More...
 
 newNumber ( $text, $pos)
 Create a numerical expression object. More...
 
 newOperator ( $type, $pos, $length)
 Create a binary operator. More...
 
 nextToken ()
 Fetch the next token from the input string. More...
 

Detailed Description

Helper class for converting rules to reverse polish notation (RPN).

Definition at line 16 of file CLDRPluralRuleConverter.php.

Constructor & Destructor Documentation

◆ __construct()

CLDRPluralRuleConverter::__construct (   $rule)
protected

Private constructor.

Definition at line 101 of file CLDRPluralRuleConverter.php.

References $rule.

Member Function Documentation

◆ convert()

static CLDRPluralRuleConverter::convert (   $rule)
static

Convert a rule to RPN.

This is the only public entry point.

Parameters
string$ruleThe rule to convert
Returns
string The RPN representation of the rule

Definition at line 93 of file CLDRPluralRuleConverter.php.

References $parser, and $rule.

Referenced by CLDRPluralRuleEvaluator\compile().

◆ doConvert()

CLDRPluralRuleConverter::doConvert ( )
protected

Do the operation.

Returns
string The RPN representation of the rule (e.g. "5 3 mod n is")

Definition at line 112 of file CLDRPluralRuleConverter.php.

References $value, doOperation(), error(), nextToken(), and operators.

◆ doOperation()

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.

Parameters
CLDRPluralRuleConverter_Operator$op

Definition at line 269 of file CLDRPluralRuleConverter.php.

References $right.

Referenced by doConvert().

◆ error()

CLDRPluralRuleConverter::error (   $message)
protected

Throw an error.

Definition at line 305 of file CLDRPluralRuleConverter.php.

Referenced by doConvert(), and nextToken().

◆ newNumber()

CLDRPluralRuleConverter::newNumber (   $text,
  $pos 
)
protected

Create a numerical expression object.

Parameters
string$text
int$pos
Returns
CLDRPluralRuleConverter_Expression The numerical expression

Definition at line 286 of file CLDRPluralRuleConverter.php.

References $pos.

Referenced by nextToken().

◆ newOperator()

CLDRPluralRuleConverter::newOperator (   $type,
  $pos,
  $length 
)
protected

Create a binary operator.

Parameters
string$type
int$pos
int$length
Returns
CLDRPluralRuleConverter_Operator The operator

Definition at line 298 of file CLDRPluralRuleConverter.php.

References $pos, and $type.

Referenced by nextToken().

◆ nextToken()

CLDRPluralRuleConverter::nextToken ( )
protected

Fetch the next token from the input string.

Returns
CLDRPluralRuleConverter_Fragment The next token

Definition at line 172 of file CLDRPluralRuleConverter.php.

References $end, $pos, error(), newNumber(), and newOperator().

Referenced by doConvert().

Member Data Documentation

◆ $end

int CLDRPluralRuleConverter::$end

The past-the-end position.

Definition at line 33 of file CLDRPluralRuleConverter.php.

Referenced by nextToken().

◆ $operands

array CLDRPluralRuleConverter::$operands = array()

The operand stack.

Definition at line 45 of file CLDRPluralRuleConverter.php.

◆ $operators

array CLDRPluralRuleConverter::$operators = array()

The operator stack.

Definition at line 39 of file CLDRPluralRuleConverter.php.

◆ $pos

int CLDRPluralRuleConverter::$pos

The current position.

Definition at line 27 of file CLDRPluralRuleConverter.php.

Referenced by newNumber(), newOperator(), and nextToken().

◆ $precedence

CLDRPluralRuleConverter::$precedence
static
Initial value:
'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 52 of file CLDRPluralRuleConverter.php.

◆ $rule

string CLDRPluralRuleConverter::$rule

The input string.

Definition at line 21 of file CLDRPluralRuleConverter.php.

Referenced by __construct(), and convert().

◆ NUMBER_CLASS

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 75 of file CLDRPluralRuleConverter.php.

◆ OPERAND_SYMBOLS

const CLDRPluralRuleConverter::OPERAND_SYMBOLS = 'nivwft'

A character list of symbolic operands.

Definition at line 80 of file CLDRPluralRuleConverter.php.

◆ WHITESPACE_CLASS

const CLDRPluralRuleConverter::WHITESPACE_CLASS = " \t\r\n"

A character list defining whitespace, for use in strspn() etc.

Definition at line 69 of file CLDRPluralRuleConverter.php.

◆ WORD_REGEX

const CLDRPluralRuleConverter::WORD_REGEX = '/[a-zA-Z@]+/A'

An anchored regular expression which matches a word at the current offset.

Definition at line 85 of file CLDRPluralRuleConverter.php.


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.