Beispiel #1
0
 public function optimize(Renderer $renderer, Filter $node, $options)
 {
     $inserts = array();
     $content = '';
     foreach ($node->getChilds() as $child) {
         foreach ($child->getContent()->getChilds() as $item) {
             if ($item instanceof Text) {
                 $content .= $item->getContent();
             } else {
                 $hash = md5(mt_rand());
                 $inserts[$hash] = $item;
                 $content .= $hash;
             }
         }
         $content .= "\n";
     }
     $string = new InterpolatedString(array());
     $result = $this->filter($content, array(), array());
     foreach ($inserts as $hash => $insert) {
         $parts = explode($hash, $result, 2);
         $string->addChild(new Text(array(), $parts[0]));
         $string->addChild($insert);
         $result = $parts[1];
     }
     $string->addChild(new Text(array(), $result));
     $string->accept($renderer);
 }
Beispiel #2
0
 protected function mergeInto(InterpolatedString $dest, $src)
 {
     if ($src instanceof InterpolatedString) {
         foreach ($src->getChilds() as $child) {
             $dest->addChild($child);
         }
     } elseif ($src instanceof Text || $src instanceof Insert) {
         $dest->addChild($src);
     } else {
         return false;
     }
 }
 public function enterInterpolatedStringChilds(InterpolatedString $node)
 {
     $n = 0;
     foreach ($node->getChilds() as $child) {
         if (0 !== $n) {
             $this->betweenInterpolatedStringChilds($node);
         }
         $child->accept($this);
         ++$n;
     }
     return false;
 }
 protected function parseInterpolatedString($buf, $quoted = true)
 {
     if ($quoted && !$buf->match('/"/A', $match)) {
         $this->syntaxErrorExpected($buf, 'double quoted string');
     }
     $node = new InterpolatedString($buf->getPosition());
     if ($quoted) {
         $stringRegex = '/(
                 [^\\#"\\\\]+     # anything without hash or " or \\
                 |\\\\["\\\\]    # or escaped quote slash
                 |\\#(?!\\{)       # or hash, but not followed by {
             )+/Ax';
     } else {
         $stringRegex = '/(
                 [^\\#]+      # anything without hash
                 |\\#(?!\\{)   # or hash, but not followed by {
             )+/Ax';
     }
     do {
         if ($buf->match($stringRegex, $match)) {
             $text = $match[0];
             if ($quoted) {
                 // strip slashes
                 $text = preg_replace('/\\\\(["\\\\])/', '\\1', $match[0]);
             }
             $text = new Text($match['pos'][0], $text);
             $node->addChild($text);
         } else {
             if ($expr = $this->parseInterpolation($buf)) {
                 $node->addChild($expr);
             } else {
                 if ($quoted && $buf->match('/"/A')) {
                     break;
                 } else {
                     if (!$quoted && $buf->match('/$/A')) {
                         break;
                     } else {
                         $this->syntaxErrorExpected($buf, 'string or #{...}');
                     }
                 }
             }
         }
     } while (true);
     // ensure that the InterpolatedString has at least one child
     if (0 === count($node->getChilds())) {
         $text = new Text($buf->getPosition(), '');
         $node->addChild($text);
     }
     return $node;
 }
 public function leaveInterpolatedString(InterpolatedString $node)
 {
     if (!$this->isEchoMode() && 1 < count($node->getChilds())) {
         $this->raw(')');
     }
 }
Beispiel #6
0
 protected function parseInterpolatedString(InterpolatedString $node)
 {
     $content = '';
     foreach ($node->getChilds() as $child) {
         if ($child instanceof Text) {
             $content .= $child->getContent();
         } else {
             throw new SnipCallerAttriSyntaxException(sprintf('attri InterpolatedString type value should be made of  Text (InlineSnipCaller is subclass of Text), %s given ', get_class($child)));
         }
     }
     return $content;
 }