// Path: advance/src/java/com/dwarfartisan/parsec/Combinator.java
// public static <T, E, Status, Tran> Parsec<T, E, Status, Tran> attempt(Parsec<T, E, Status, Tran> parser) {
//     return new Try<>(parser);
// }


import java.io.EOFException;
import java.util.ArrayList;
import java.util.List;
import static com.dwarfartisan.parsec.Combinator.attempt;
package com.dwarfartisan.parsec;


/**
 * Created by Mars Liu on 2016-01-03.
 * ManyTil 尝试匹配 parser 0 到多次,直到终结算子成功,它是饥饿模式.
 */
public class ManyTill<T, L, E, Status, Tran> implements Parsec<List<T>, E, Status, Tran> {
    private Parsec<T, E, Status, Tran> parser;
    private Parsec<L, E, Status, Tran> end;
    @Override
    public List<T> parse(State<E, Status, Tran> s) throws EOFException, ParsecException {
        ArrayList<T> re = new ArrayList<>();
        while (true) {
            try {
// Path: advance/src/java/com/dwarfartisan/parsec/Combinator.java
// public static <T, E, Status, Tran> Parsec<T, E, Status, Tran> attempt(Parsec<T, E, Status, Tran> parser) {
//     return new Try<>(parser);
// }


// Path: advance/src/java/com/dwarfartisan/parsec/ManyTill.java
import java.io.EOFException;
import java.util.ArrayList;
import java.util.List;
import static com.dwarfartisan.parsec.Combinator.attempt;

package com.dwarfartisan.parsec;


/**
 * Created by Mars Liu on 2016-01-03.
 * ManyTil 尝试匹配 parser 0 到多次,直到终结算子成功,它是饥饿模式.
 */
public class ManyTill<T, L, E, Status, Tran> implements Parsec<List<T>, E, Status, Tran> {
    private Parsec<T, E, Status, Tran> parser;
    private Parsec<L, E, Status, Tran> end;
    @Override
    public List<T> parse(State<E, Status, Tran> s) throws EOFException, ParsecException {
        ArrayList<T> re = new ArrayList<>();
        while (true) {
            try {
                attempt(end).parse(s);