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.
 
 

62 lines
954 B

<?php
declare(strict_types=1);
namespace App\Cfnpp\Expression\Token;
use App\Cfnpp\Expression\Token;
use App\Cfnpp\Expression\TokenLiteral;
class NumericLiteral 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 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);
}
public function execute(?array $arguments = null)
{
return $this->getValue();
}
}