*/ class NumericLiteral extends TokenLiteral { /** * Value of this literal. * @var int|float */ protected $value; /** * New number literal. * * @param int|float $value */ public function __construct($value) { $this->value = $value; } /** * Get the value of this literal. * * @return int|float */ public function getValue() { return $this->value; } public static function isToken(string $stream): bool { return is_numeric($stream[0]); } public static function getToken(string &$stream): Token { $buffer = ''; for ($i = 0; $i < strlen($stream); $i++) { if (preg_match('/^[0-9]$/', $stream[$i])) { $buffer .= $stream[$i]; } else { break; } } $stream = substr($stream, strlen($buffer)); if (stristr($buffer, '.')) { $buffer = (float)$buffer; } else { $buffer = (int)$buffer; } return new NumericLiteral($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(); } }