Hoa central
Token.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Compiler\Llk\Rule;
38 
39 use Hoa\Compiler;
40 use Hoa\File;
41 
50 class Token extends Rule
51 {
57  protected static $_regexCompiler = null;
58 
64  protected $_tokenName = null;
65 
71  protected $_namespace = null;
72 
78  protected $_regex = null;
79 
85  protected $_ast = null;
86 
92  protected $_value = null;
93 
99  protected $_kept = false;
100 
106  protected $_unification = -1;
107 
108 
109 
119  public function __construct($name, $tokenName, $nodeId, $unification)
120  {
121  parent::__construct($name, null, $nodeId);
122  $this->_tokenName = $tokenName;
123  $this->_unification = $unification;
124 
125  return;
126  }
127 
133  public function getTokenName()
134  {
135  return $this->_tokenName;
136  }
137 
144  public function setNamespace($namespace)
145  {
146  $old = $this->_namespace;
147  $this->_namespace = $namespace;
148 
149  return $old;
150  }
151 
157  public function getNamespace()
158  {
159  return $this->_namespace;
160  }
161 
168  public function setRepresentation($regex)
169  {
170  $old = $this->_regex;
171  $this->_regex = $regex;
172 
173  return $old;
174  }
175 
181  public function getRepresentation()
182  {
183  return $this->_regex;
184  }
185 
191  public function getAST()
192  {
193  if (null === static::$_regexCompiler) {
194  $stream = new File\Read('hoa://Library/Regex/Grammar.pp');
195  $stream->rewind();
196 
197  static::$_regexCompiler = Compiler\Llk::load($stream);
198  }
199 
200  if (null === $this->_ast) {
201  $this->_ast = static::$_regexCompiler->parse(
202  $this->getRepresentation()
203  );
204  }
205 
206  return $this->_ast;
207  }
208 
215  public function setValue($value)
216  {
217  $old = $this->_value;
218  $this->_value = $value;
219 
220  return $old;
221  }
222 
228  public function getValue()
229  {
230  return $this->_value;
231  }
232 
239  public function setKept($kept)
240  {
241  $old = $this->_kept;
242  $this->_kept = $kept;
243 
244  return $old;
245  }
246 
252  public function isKept()
253  {
254  return $this->_kept;
255  }
256 
262  public function getUnificationIndex()
263  {
264  return $this->_unification;
265  }
266 }
__construct($name, $tokenName, $nodeId, $unification)
Definition: Token.php:119
setNamespace($namespace)
Definition: Token.php:144