*/ final class FloatRangeParameter extends Parameter{ public function __construct( string $codeName, Translatable|string $printableName, private float $min, private float $max ){ parent::__construct($codeName, $printableName, new NamedType(BuiltInType::FLOAT)); } public function parse(string $buffer, int &$offset) : float{ if(preg_match('/\G(-?\d+\.?\d*)/', $buffer, $matches, offset: $offset) > 0){ $offset += strlen($matches[0]); $value = (float) $matches[0]; if($value < $this->min || $value > $this->max){ //TODO: we should probably use localised messages for this, but they probably won't be seen by the user //anyway since we'll try all the overloads before giving up throw new ParameterParseException("Value must be in the range $this->min ... $this->max"); } return $value; } throw new ParameterParseException("Expected a float in the range $this->min ... $this->max"); } }