Beispiel #1
0
 /**
  * Verificação da Precedência
  * @param Token $tokenA Token para Verificação
  * @param Token $tokenB Token para Verificação
  * @throws Exception Token de Tipo Não Operador
  * @return int Comparação de Precedências dos Tokens
  */
 public function precedence($tokenA, $tokenB)
 {
     /* @todo Checar Precedência */
     $precedenceA = $this->_mapper[$tokenA->getContent()];
     $precedenceB = $this->_mapper[$tokenB->getContent()];
     return $precedenceA - $precedenceB;
 }
Beispiel #2
0
 protected function _getParseTokenFromToken(Token $token)
 {
     $code = $token->getCode();
     if ($code === "WHILE_START") {
         $code = "WHILE";
     }
     return new ParseToken($code, $token->getContent(), $token->getChar(), $token->getLine());
 }
Beispiel #3
0
 /**
  * Given the set of matches, nest them according to their types
  *
  * @param \ArrayIterator $result Iterator of match results
  * @param  \SalesforceEng\Breakout\Token $latest Token instance
  * @return array Set of nested token instances (arrays)
  */
 public function nest(&$result, $latest = null)
 {
     $container = [];
     if (!$result instanceof \ArrayIterator) {
         $result = new \ArrayIterator($result);
     }
     while ($result->valid()) {
         $current = new Token($result->current());
         $result->next();
         if ($current->getType() == 'block') {
             // see if we're closing it out
             $content = trim($current->getContent());
             if ($content !== 'endif' && $content !== 'endfor' && $content !== 'else' && $content !== 'endraw') {
                 $group = [$current];
                 $found = $this->nest($result, $current);
                 $current = array_merge($group, $found);
             } else {
                 if ($latest !== null) {
                     $latestType = explode(' ', trim($latest->getContent()))[0];
                     if ($latestType == 'if' && trim($current->getContent()) == 'endif') {
                         $container[] = $current;
                         return $container;
                     } elseif ($latestType == 'for' && trim($current->getContent()) == 'endfor') {
                         $container[] = $current;
                         return $container;
                     } elseif ($latestType == 'raw' && trim($current->getContent()) == 'endraw') {
                         $container[] = $current;
                         return $container;
                     }
                 }
             }
         }
         $container[] = $current;
     }
     return $container;
 }