Example #1
0
 public static function preprocessorFilterCb($matches)
 {
     if (!isset($matches[0]) || !isset($matches[0][0])) {
         return '';
         // shouldn't ever happen
     }
     if ($matches[0][0] === '"') {
         return Utils::tagBlock('STRING', $matches[0]);
     } elseif ($matches[0][0] === '&') {
         return '<' . Utils::tagBlock('STRING', $matches[1]) . '>';
     } else {
         return Utils::tagBlock('COMMENT', $matches[0]);
     }
 }
Example #2
0
 /**
  * @brief Returns the XML representation of the token stream
  *
  * This function triggers the generation of the XML output.
  * @return An XML-string which represents the tokens recorded by the scanner.
  */
 public function tagged()
 {
     $out = '';
     // call stream filters.
     foreach ($this->streamFilters as $f) {
         $this->tokens = call_user_func($f[1], $this->tokens);
     }
     foreach ($this->tokens as $t) {
         $type = $t[0];
         // speed is roughly 10% faster if we process the filters inside this
         // loop instead of separately.
         if (isset($this->filters[$type])) {
             foreach ($this->filters[$type] as $filter) {
                 $t = call_user_func($filter[1], $t);
             }
         }
         list($type, $string, $esc) = $t;
         if (!$esc) {
             $string = Utils::escapeString($string);
         }
         if ($type !== null) {
             $out .= Utils::tagBlock($type, $string);
         } else {
             $out .= $string;
         }
     }
     return $out;
 }
Example #3
0
 /**
  * Recursive function to collapse the token tree into XML
  * @internal
  */
 protected function collapseTokenTree($node)
 {
     $text = '';
     foreach ($node['children'] as $c) {
         if (is_string($c)) {
             $text .= Utils::escapeString($c);
         } else {
             $text .= $this->collapseTokenTree($c);
         }
     }
     $tokenName = $node['token_name'];
     $token = array($node['token_name'], $text, true);
     $token_ = $this->ruleMapperFilter(array($token));
     $token = $token_[0];
     if (isset($this->filters[$tokenName])) {
         foreach ($this->filters[$tokenName] as $filter) {
             $token = call_user_func($filter[1], $token);
         }
     }
     list($tokenName, $text, ) = $token;
     return $tokenName === null ? $text : Utils::tagBlock($tokenName, $text);
 }