public static function normalize(array $context)
    {
        $diff = array_diff_key($context, self::$defaults);
        if (!empty($diff)) {
            $errorMessage = 'unknown index '.implode(', ', array_keys($diff));
            throw new InvalidContext($errorMessage);
        }
        if (!empty($context['namespace'])) {
            if (preg_match('/^\\\\?(.*?)\\\\?$/s', $context['namespace'], $ns)) {
                $context['namespace'] = $ns[1] ? $ns[1].'\\' : null;
            }
        } else {
            $context['namespace'] = null;
        }
        return array_replace(self::$defaults, $context);
    }