cloudformation-plus-plus: cfn template preprocessor
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.
 
 

87 lines
1.3 KiB

<?php
declare(strict_types=1);
namespace App\Cfnpp\Expression\Token;
use App\Cfnpp\Expression\Token;
use App\Cfnpp\Expression\TokenLiteral;
/**
* A number literal.
*
* @author Adam Pippin <hello@adampippin.ca>
*/
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();
}
}