*/ class StringLiteral extends TokenLiteral { /** * Value of the string literal. * @var string */ protected $value; /** * New string literal. * * @param string $value */ public function __construct(string $value) { $this->value = $value; } /** * Get the value of this literal. * * @return string */ public function getValue(): string { 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); } /** * Get the value of this token. * * @param ?\App\Util\GraphNode[] $arguments * @return \App\Util\GraphNode|Token|scalar|null */ public function execute(?array $arguments = null) { return $this->getValue(); } }