protected function string(&$out)
{
$s = $this->seek();
if ($this->literal('"', false)) {
$delim = '"';
} elseif ($this->literal("'", false)) {
$delim = "'";
} else {
return false;
}
$content = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
$hasInterpolation = false;
while ($this->matchString($m, $delim)) {
if ($m[1] !== '') {
$content[] = $m[1];
}
if ($m[2] === '#{') {
$this->count -= strlen($m[2]);
if ($this->interpolation($inter, false)) {
$content[] = $inter;
$hasInterpolation = true;
} else {
$this->count += strlen($m[2]);
$content[] = '#{';
// ignore it
}
} elseif ($m[2] === '\\') {
if ($this->literal('"', false)) {
$content[] = $m[2] . '"';
} elseif ($this->literal("'", false)) {
$content[] = $m[2] . "'";
} else {
$content[] = $m[2];
}
} else {
$this->count -= strlen($delim);
break;
// delim
}
}
$this->eatWhiteDefault = $oldWhite;
if ($this->literal($delim)) {
if ($hasInterpolation) {
$delim = '"';
foreach ($content as &$string) {
if ($string === "\\'") {
$string = "'";
} elseif ($string === '\\"') {
$string = '"';
}
}
}
$out = [Type::T_STRING, $delim, $content];
return true;
}
$this->seek($s);
return false;
}