import re


def parse_time(time_string: str) -> int:
    """ Parse a time stamp in h/m/s(default)/ms or any combination of these units.

    Args:
        time_string (str): timestamp, e.g., "0.23s", "5.234" (implied s), "1234 ms",
            "1h 10m 12.345s", "00h00m00.000". Supported units: h, m, s (default), ms
            and any combination thereof.

    Returns:
        int: time represented by time_string in milliseconds

    Raises:
        ValueError: if time_string cannot be parsed
    """
    try:
        if not time_string.strip():
            raise ValueError("empty time string")
        prev_end = 0
        time_in_ms = 0
        for unit_match in re.finditer(r"ms|h|m|s", time_string):
            # float() raises ValueError if text before the unit is not a valid number
            numerical_part = float(time_string[prev_end : unit_match.start()])
            unit_part = unit_match.group()
            if unit_part == "h":
                time_in_ms += int(numerical_part * 3600000)
            elif unit_part == "m":
                time_in_ms += int(numerical_part * 60000)
            elif unit_part == "s":
                time_in_ms += int(numerical_part * 1000)
            else:  # unit_part == "ms":
                time_in_ms += int(numerical_part)
            prev_end = unit_match.end()
        last_part = time_string[prev_end:].strip()
        if last_part:
            time_in_ms += int(float(last_part) * 1000)
        return time_in_ms
    except ValueError as e:
        # e might have been raised by any of the float() constructor
        raise ValueError(
            f'cannot parse "{time_string}" as a valid time in h/m/s/ms'
        ) from e