core/src/main/java/io/parsingdata/metal/token/IterableToken.java
/**
     * Iteratively parse iterations of the token, given a stop condition and the logic how to handle a failed parse.
     *
     * @param environment the environment to apply the parse to
     * @param stopCondition a function to determine when to stop the iteration
     * @param ifIterationFails a function to determine how to handle a failed parse
     * @return a trampolined {@code Optional<ParseState>}
     */
Iteratively parse iterations of the token, given a stop condition and the logic how to handle a failed parse.
@param environment the environment to apply the parse to
@param stopCondition a function to determine when to stop the iteration
@param ifIterationFails a function to determine how to handle a failed parse
@return a trampolined  Optional
Iteratively parse iterations of the token given a stop condition and the logic how to handle a failed parse . @param environment the environment to apply the parse to @param stopCondition a function to determine when to stop the iteration @param ifIterationFails a function to determine how to handle a failed parse @return a trampolined Optional
private Trampoline<Optional<ParseState>> iterate(final Environment environment, final Predicate<Environment> stopCondition, final Function<Environment, Optional<ParseState>> ifIterationFails) {
        if (stopCondition.test(environment)) {
            return complete(() -> success(environment.parseState.closeBranch(this)));
        }
        return token
                .parse(environment)
                .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState.iterate()), stopCondition, ifIterationFails)))
                .orElseGet(() -> complete(() -> ifIterationFails.apply(environment)));
    }
private Trampoline < Optional < ParseState > > iterate ( final Environment environment , final Predicate < Environment > stopCondition , final Function < Environment , Optional < ParseState > > ifIterationFails ) { if ( stopCondition . test ( environment ) ) { return complete ( ( ) -> success ( environment . parseState . closeBranch ( this ) ) ) ; } return token . parse ( environment ) . map ( nextParseState -> intermediate ( ( ) -> iterate ( environment . withParseState ( nextParseState . iterate ( ) ) , stopCondition , ifIterationFails ) ) ) . orElseGet ( ( ) -> complete ( ( ) -> ifIterationFails . apply ( environment ) ) ) ; }
Iteratively parse iterations of the token, given a stop condition and the logic how to handle a failed parse.
Iteratively parse iterations of the token given a stop condition and the logic how to handle a failed parse .