Exemple #1
0
 /**
  * @param string $name
  * @return BaseToken
  * @throws Exceptions\ParserException
  */
 public function getVariable($name)
 {
     if (!array_key_exists($name, $this->variables)) {
         $token = $this->stack->current();
         throw new Exceptions\ParserException(sprintf('Undefined variable "%s" at position %d on line %d', $name, $token->getPosition(), $token->getLine()));
     }
     return TokenFactory::createFromPHPType($this->variables[$name]);
 }
 /**
  * {@inheritdoc}
  */
 public function tokenize($string)
 {
     $stack = new Stack();
     $regex = $this->getRegex();
     $baseNameSpace = __NAMESPACE__ . '\\Tokens\\Token';
     $offset = 0;
     while (preg_match($regex, $string, $matches, 0, $offset)) {
         $token = $this->getMatchedToken($matches);
         $className = $baseNameSpace . $token;
         $stack->attach(new $className($matches[$token], $offset, $stack));
         $offset += strlen($matches[0]);
     }
     return $stack;
 }