Beispiel #1
0
 /**
  * To determine the type of the token (opening/unit) on the basis of the following tokens
  * @param fx_template_token $token the token with an unknown type
  * @param array $tokens following tokens
  * @return null
  */
 protected function solveUnclosed($token, $tokens)
 {
     if (!$token || $token->type != 'unknown') {
         return;
     }
     $token_info = Token::getTokenInfo($token->name);
     $stack = array();
     while ($next_token = array_shift($tokens)) {
         if ($next_token->type == 'unknown') {
             $this->solveUnclosed($next_token, $tokens);
         }
         switch ($next_token->type) {
             case 'open':
                 if (count($stack) == 0) {
                     if (!in_array($next_token->name, $token_info['contains'])) {
                         $token->type = 'single';
                         return;
                     }
                 }
                 $stack[] = $token;
                 break;
             case 'close':
                 if (count($stack) == 0) {
                     if ($next_token->name == $token->name) {
                         $token->type = 'open';
                         return;
                     } else {
                         $token->type = 'single';
                         return;
                     }
                 }
                 array_pop($stack);
                 break;
         }
     }
 }