public function enterInterpolatedStringChilds(InterpolatedString $node) { $n = 0; foreach ($node->getChilds() as $child) { if (0 !== $n) { $this->betweenInterpolatedStringChilds($node); } $child->accept($this); ++$n; } return false; }
public function leaveInterpolatedString(InterpolatedString $node) { if (!$this->isEchoMode() && 1 < count($node->getChilds())) { $this->raw(')'); } }
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; }
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; }