3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\I18n\Translator\Plural
;
13 use Zend\I18n\Exception
;
18 * All properties in the symbol are defined as public for easier and faster
19 * access from the applied closures. An exception are the closure properties
20 * themselves, as they have to be accessed via the appropriate getter and
33 * Node or token type name.
40 * Left binding power (precedence).
44 public $leftBindingPower;
47 * Getter for null denotation.
51 protected $nullDenotationGetter;
54 * Getter for left denotation.
58 protected $leftDenotationGetter;
61 * Value used by literals.
89 * Create a new symbol.
91 * @param Parser $parser
93 * @param int $leftBindingPower
95 public function __construct(Parser
$parser, $id, $leftBindingPower)
97 $this->parser
= $parser;
99 $this->leftBindingPower
= $leftBindingPower;
103 * Set the null denotation getter.
105 * @param Closure $getter
108 public function setNullDenotationGetter(Closure
$getter)
110 $this->nullDenotationGetter
= $getter;
115 * Set the left denotation getter.
117 * @param Closure $getter
120 public function setLeftDenotationGetter(Closure
$getter)
122 $this->leftDenotationGetter
= $getter;
127 * Get null denotation.
129 * @throws Exception\ParseException
132 public function getNullDenotation()
134 if ($this->nullDenotationGetter
=== null) {
135 throw new Exception\
ParseException(sprintf(
136 'Syntax error: %s', $this->id
140 /** @var callable $function */
141 $function = $this->nullDenotationGetter
;
142 return $function($this);
146 * Get left denotation.
148 * @param Symbol $left
149 * @throws Exception\ParseException
152 public function getLeftDenotation($left)
154 if ($this->leftDenotationGetter
=== null) {
155 throw new Exception\
ParseException(sprintf(
156 'Unknown operator: %s', $this->id
160 /** @var callable $function */
161 $function = $this->leftDenotationGetter
;
162 return $function($this, $left);