def parse_while(state, pred):
    """
    pred: a boolean-valued function (i.e. a predicate) on a character
    postcondition: `state.pos` is at the first character *not* satisfying `pred`,
        after the original `state.pos` at call-time, or `len(self.text)` if there is
        no such character
    returns: the text satisfying `pred` starting from the original `state.pos`
    """
    start = state.pos
    while not state.finished() and pred(state.text[state.pos]):
        state.pos += 1
    return state.text[start : state.pos]