def firstpos(sub: str, pos: int):
    """On the assumption that *sub* is a substring contained in a longer
    string, and *pos* is the index in that longer string of the final
    character in sub, returns the position of the first character of
    sub in that longer string.

    This is useful in the PVL library when we know the position of the
    final character of a token, but want the position of the first
    character.
    """
    return pos - len(sub) + 1