You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.0 KiB
70 lines
1.0 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cfnpp\Expression\Token;
|
|
|
|
use App\Cfnpp\Expression\Token;
|
|
use App\Cfnpp\Expression\TokenLiteral;
|
|
|
|
class StringLiteral extends TokenLiteral
|
|
{
|
|
protected $value;
|
|
|
|
public function __construct($value)
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
|
|
public function getValue()
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public static function isToken(string $stream): bool
|
|
{
|
|
return $stream[0] == '"';
|
|
}
|
|
|
|
public static function getToken(string &$stream): Token
|
|
{
|
|
$buffer = '';
|
|
$in_string = false;
|
|
$escaped = false;
|
|
|
|
for ($i = 0; $i < strlen($stream); $i++)
|
|
{
|
|
if ($escaped)
|
|
{
|
|
$buffer .= $stream[$i];
|
|
$escaped = false;
|
|
}
|
|
elseif ($stream[$i] == '"')
|
|
{
|
|
if ($in_string)
|
|
{
|
|
break;
|
|
}
|
|
|
|
$in_string = true;
|
|
}
|
|
elseif ($stream[$i] == '\\')
|
|
{
|
|
$escaped = true;
|
|
}
|
|
else
|
|
{
|
|
$buffer .= $stream[$i];
|
|
}
|
|
}
|
|
|
|
$stream = substr($stream, $i + 1);
|
|
|
|
return new StringLiteral($buffer);
|
|
}
|
|
|
|
public function execute(?array $arguments = null)
|
|
{
|
|
return $this->getValue();
|
|
}
|
|
}
|
|
|